import AppKit

class PopoverPanel: NSPanel {
    override var canBecomeKey: Bool { true }

    init(viewController: NSViewController) {
        super.init(
            contentRect: CGRect(x: 0, y: 0, width: 100, height: 100),
            styleMask: [.titled, .nonactivatingPanel, .utilityWindow,
                        .fullSizeContentView],
            backing: .buffered,
            defer: false
        )
        super.contentViewController = viewController

        title = ""
        isMovable = false
        isMovableByWindowBackground = false
        isFloatingPanel = true
        isOpaque = false
        level = .statusBar
        titleVisibility = .hidden
        titlebarAppearsTransparent = true

        animationBehavior = .none
        collectionBehavior = [.moveToActiveSpace, .fullScreenAuxiliary,
                              .transient]
        isReleasedWhenClosed = false
        hidesOnDeactivate = false

        standardWindowButton(.closeButton)?.isHidden = true
        standardWindowButton(.miniaturizeButton)?.isHidden = true
        standardWindowButton(.zoomButton)?.isHidden = true
    }

    // HACK: ???
    // NOTE: All events should be managed by an NSViewController.
    //       Though, I am not sure how great of a solution this is.
    override func performKeyEquivalent(with event: NSEvent) -> Bool {
        // return super.performKeyEquivalent(with: event)
        return true
    }
}
