import Cocoa
import FlutterMacOS

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

    // Center window with a sensible default size
    let screenSize = NSScreen.main?.frame.size ?? CGSize(width: 1440, height: 900)
    let windowWidth: CGFloat = min(1280, screenSize.width * 0.85)
    let windowHeight: CGFloat = min(820, screenSize.height * 0.85)
    let origin = CGPoint(
      x: (screenSize.width - windowWidth) / 2,
      y: (screenSize.height - windowHeight) / 2
    )
    let windowFrame = NSRect(origin: origin, size: CGSize(width: windowWidth, height: windowHeight))

    self.contentViewController = flutterViewController
    self.setFrame(windowFrame, display: true)

    // Keep sidebar always visible — desktop layout kicks in at 720px
    self.minSize = CGSize(width: 880, height: 560)
    self.titlebarAppearsTransparent = true

    RegisterGeneratedPlugins(registry: flutterViewController)

    super.awakeFromNib()
  }
}
