import XCTest

/// UI Tests for Settings functionality
final class SettingsUITests: XCTestCase {

    var app: XCUIApplication!

    override func setUpWithError() throws {
        continueAfterFailure = false
        app = XCUIApplication()
        app.launchArguments = ["--uitesting"]
        app.launch()

        // Navigate to Settings tab
        let tabBar = app.tabBars.firstMatch
        _ = tabBar.waitForExistence(timeout: 5)
        let settingsTab = tabBar.buttons["Settings"]
        if settingsTab.exists {
            settingsTab.tap()
        }
    }

    override func tearDownWithError() throws {
        app = nil
    }

    // MARK: - Settings Screen Tests

    func testSettingsScreenLoads() throws {
        // Verify settings content is visible
        // Look for common settings elements
        let settingsView = app.scrollViews.firstMatch
        XCTAssertTrue(settingsView.exists || app.collectionViews.firstMatch.exists || app.tables.firstMatch.exists)
    }

    func testCurrencySettingExists() throws {
        // Look for currency-related UI elements
        let currencyLabel = app.staticTexts["Currency"]
        if currencyLabel.waitForExistence(timeout: 2) {
            XCTAssertTrue(currencyLabel.exists)
        }
    }

    func testAppVersionDisplayed() throws {
        // Scroll to bottom if needed and look for version info
        let scrollView = app.scrollViews.firstMatch
        if scrollView.exists {
            scrollView.swipeUp()
        }

        // Version text is usually at the bottom
        Thread.sleep(forTimeInterval: 0.5)

        // Just verify the settings screen is still visible after scrolling
        let tabBar = app.tabBars.firstMatch
        XCTAssertTrue(tabBar.exists)
    }
}
