import XCTest

@MainActor
final class ModifierBarUITests: XCTestCase {

    override func setUpWithError() throws {
        continueAfterFailure = false
    }

    func testModifierBarButtons() throws {
        let app = XCUIApplication()
        app.launchPaired()

        // List of buttons to verify
        // Wait until the terminal view is up and the modifier bar visible.
        XCTAssertTrue(app.buttons["Ctrl"].waitForExistence(timeout: 10),
                      "Modifier bar should appear after pairing")

        let buttons = [
            "Ctrl", "Esc", "Tab", "←", "↑", "↓", "→", "⇧↵", "📋"
        ]

        for title in buttons {
            let btn = app.buttons[title]
            XCTAssertTrue(btn.exists, "Modifier button '\(title)' should be present")
        }

        // Test Ctrl sticky state
        let ctrlBtn = app.buttons["Ctrl"]
        // In SwiftUI, the visual state (background color) isn't directly accessible via XCUITest
        // unless we add accessibilityValue or similar.
        // However, we can verify that tapping it doesn't crash and the app remains responsive.
        ctrlBtn.tap()

        // Tap a few other buttons
        app.buttons["Esc"].tap()
        app.buttons["↑"].tap()
        app.buttons["📋"].tap()

        // Verify PasteSheet appears (navigationTitle is "Paste")
        let pasteSheetTitle = app.staticTexts["Paste"]
        XCTAssertTrue(pasteSheetTitle.waitForExistence(timeout: 5), "Paste sheet should appear after tapping clipboard button")

        // Dismiss PasteSheet
        app.buttons["Cancel"].tap()
    }
}
