import Testing
import AppKit
@testable import Alas

@MainActor
struct TitlelessWindowTests {
    @Test func hidesStandardWindowButtons() {
        let window = NSWindow(
            contentRect: NSRect(x: 0, y: 0, width: 800, height: 600),
            styleMask: [.titled, .closable, .miniaturizable, .resizable],
            backing: .buffered,
            defer: false
        )

        TitlelessWindow.configure(window)

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

    @Test func fullSizeContentViewIsSet() {
        let window = NSWindow(
            contentRect: NSRect(x: 0, y: 0, width: 800, height: 600),
            styleMask: [.titled, .closable, .miniaturizable, .resizable],
            backing: .buffered,
            defer: false
        )

        TitlelessWindow.configure(window)

        #expect(window.styleMask.contains(.fullSizeContentView))
    }

    @Test func configurationViewConfiguresWindowWhenAttached() {
        let window = NSWindow(
            contentRect: NSRect(x: 0, y: 0, width: 800, height: 600),
            styleMask: [.titled, .closable, .miniaturizable, .resizable],
            backing: .buffered,
            defer: false
        )
        let configurationView = WindowConfigurationView(disablesSystemDrag: false)

        #expect(window.standardWindowButton(.closeButton)?.isHidden == false)

        window.contentView = configurationView

        #expect(window.standardWindowButton(.closeButton)?.isHidden == true)
        #expect(window.standardWindowButton(.miniaturizeButton)?.isHidden == true)
        #expect(window.standardWindowButton(.zoomButton)?.isHidden == true)
        #expect(window.styleMask.contains(.fullSizeContentView))
    }
}
