import Cocoa
import FlutterMacOS

class MainFlutterWindow: NSWindow {
  override func awakeFromNib() {
    let flutterViewController = FlutterViewController()
    self.contentViewController = flutterViewController

    // Override the window title so the OS task switcher and
    // window chrome read "F∆I Studio" instead of the
    // pubspec-derived "fai_studio".
    self.title = "F∆I Studio"

    // Pick a comfortable default window size. 1440x900 is the
    // effective Retina resolution of a 13" MacBook (Stefan's
    // dev machine) and the smallest "modern desktop" footprint
    // that comfortably fits the sidebar, content area, and a
    // tooling panel side-by-side. Clamp to the active screen's
    // visibleFrame so we never open larger than the display —
    // important for external monitors at non-Retina scales.
    if let screen = NSScreen.main {
      let visible = screen.visibleFrame
      let targetWidth = min(CGFloat(1280), visible.width)
      let targetHeight = min(CGFloat(900), visible.height)
      self.setContentSize(NSSize(width: targetWidth, height: targetHeight))
      self.center()
    }

    RegisterGeneratedPlugins(registry: flutterViewController)

    super.awakeFromNib()
  }
}
