//
//  MonthShareTemplateTests.swift
//  Tests iOS
//
//  TC-116: This Month - Clean Calendar sharing template renders.
//  TC-117: This Month - Stacked Bars sharing template renders.
//

import XCTest

final class MonthShareTemplateTests: BaseUITestCase {
    override var seedFixture: String? { "week_of_moods" }
    override var bypassSubscription: Bool { true }

    /// TC-116: Tap Month share button → verify Clean Calendar design renders.
    func testMonthShare_CleanCalendarTemplate_Renders() {
        let tabBar = TabBarScreen(app: app)
        tabBar.tapMonth()

        // Wait for month view to load
        _ = app.waitForExistence(timeout: 3)

        // Find the month share button
        let shareButton = app.element(UITestID.Month.shareButton)
        XCTAssertTrue(
            shareButton.waitForExistence(timeout: 8),
            "Month share button should exist"
        )

        shareButton.tapWhenReady()

        // Verify the SharingStylePickerView sheet appears
        let exitButton = app.buttons["Exit"].firstMatch
        XCTAssertTrue(
            exitButton.waitForExistence(timeout: 5),
            "Sharing picker Exit button should appear"
        )

        // First design should be "Clean Calendar"
        let cleanCalendarLabel = app.staticTexts["Clean Calendar"].firstMatch
        XCTAssertTrue(
            cleanCalendarLabel.waitForExistence(timeout: 5),
            "Clean Calendar design label should be visible"
        )

        captureScreenshot(name: "month_share_clean_calendar")

        // Close the picker
        exitButton.tap()
    }

    /// TC-117: Swipe to second design → verify Stacked Bars design renders.
    func testMonthShare_StackedBarsTemplate_Renders() {
        let tabBar = TabBarScreen(app: app)
        tabBar.tapMonth()

        _ = app.waitForExistence(timeout: 3)

        let shareButton = app.element(UITestID.Month.shareButton)
        XCTAssertTrue(
            shareButton.waitForExistence(timeout: 8),
            "Month share button should exist"
        )

        shareButton.tapWhenReady()

        let exitButton = app.buttons["Exit"].firstMatch
        XCTAssertTrue(
            exitButton.waitForExistence(timeout: 5),
            "Sharing picker Exit button should appear"
        )

        // Swipe left to get to the "Stacked Bars" design
        app.swipeLeft()
        _ = app.waitForExistence(timeout: 1)

        let stackedBarsLabel = app.staticTexts["Stacked Bars"].firstMatch
        XCTAssertTrue(
            stackedBarsLabel.waitForExistence(timeout: 5),
            "Stacked Bars design label should be visible after swiping"
        )

        captureScreenshot(name: "month_share_stacked_bars")

        // Close the picker
        exitButton.tap()
    }
}
