//
//  YearShareTemplateTests.swift
//  Tests iOS
//
//  TC-111: All Time Moods - Gradient sharing template renders.
//  TC-112: All Time Moods - Color Block sharing template renders.
//

import XCTest

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

    /// TC-111: Tap Year share button → verify Gradient design renders in SharingStylePickerView.
    func testYearShare_GradientTemplate_Renders() {
        let tabBar = TabBarScreen(app: app)
        tabBar.tapYear()

        // Wait for year view to load and find the share button
        let shareButton = app.element(UITestID.Year.shareButton)
        XCTAssertTrue(
            shareButton.waitForExistence(timeout: 8),
            "Year 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"
        )

        // Verify the title "All Time Moods" appears (YearView sends "All Time Moods")
        // Note: YearView creates SharePickerData with title based on year number,
        // but the first design is "Gradient"
        let gradientLabel = app.staticTexts["Gradient"].firstMatch
        XCTAssertTrue(
            gradientLabel.waitForExistence(timeout: 5),
            "Gradient design label should be visible"
        )

        captureScreenshot(name: "year_share_gradient")

        // Close the picker
        exitButton.tap()
    }

    /// TC-112: Swipe to second design → verify Color Block design renders.
    func testYearShare_ColorBlockTemplate_Renders() {
        let tabBar = TabBarScreen(app: app)
        tabBar.tapYear()

        let shareButton = app.element(UITestID.Year.shareButton)
        XCTAssertTrue(
            shareButton.waitForExistence(timeout: 8),
            "Year 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 "Color Block" design (second page in TabView pager)
        app.swipeLeft()
        _ = app.waitForExistence(timeout: 1)

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

        captureScreenshot(name: "year_share_color_block")

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