//
//  EntryDeleteTests.swift
//  Tests iOS
//
//  Entry deletion tests.
//

import XCTest

final class EntryDeleteTests: BaseUITestCase {
    override var seedFixture: String? { "single_mood" }

    /// TC-025: Delete a mood entry from the detail sheet.
    func testDeleteEntry_FromDetail() {
        // Wait for entry to appear
        let firstEntry = app.firstEntryRow

        guard firstEntry.waitForExistence(timeout: 8) else {
            XCTFail("No entry row found from seeded data")
            return
        }

        firstEntry.tap()

        let detailScreen = EntryDetailScreen(app: app)
        detailScreen.assertVisible()

        captureScreenshot(name: "entry_detail_before_delete")

        // Delete the entry
        detailScreen.deleteEntry()

        // Detail should dismiss after delete
        detailScreen.assertDismissed()

        // The entry should no longer be visible (or empty state should show)
        // Give UI time to update
        let moodHeader = app.element(UITestID.Day.moodHeader)
        let noDataText = app.element(UITestID.Day.emptyStateNoData)

        let headerReappeared = moodHeader.waitForExistence(timeout: 5)
        let noDataAppeared = noDataText.waitForExistence(timeout: 2)

        XCTAssertTrue(
            headerReappeared || noDataAppeared,
            "After deleting the only entry, mood header or empty state should appear"
        )

        captureScreenshot(name: "entry_deleted")
    }
}
