//
//  DayHeaderRow.swift
//  SportsTime
//
//  Header row for a day in the itinerary with day number, date, and add button.
//

import SwiftUI

struct DayHeaderRow: View {
    let dayNumber: Int
    let date: Date
    let isEmpty: Bool
    let onAddTapped: () -> Void

    @Environment(\.colorScheme) private var colorScheme

    private var formattedDate: String {
        date.formatted(.dateTime.weekday(.wide).month().day())
    }

    var body: some View {
        VStack(alignment: .leading, spacing: 4) {
            HStack {
                Text("Day \(dayNumber) - \(formattedDate)")
                    .font(.title3)
                    .fontWeight(.semibold)
                    .foregroundStyle(Theme.textPrimary(colorScheme))

                Spacer()

                Button(action: onAddTapped) {
                    Image(systemName: "plus.circle.fill")
                        .font(.title2)
                        .foregroundStyle(Theme.warmOrange)
                }
                .minimumHitTarget()
                .accessibilityLabel("Add item to this day")
            }

            if isEmpty {
                Text("No items yet, tap + to add")
                    .font(.subheadline)
                    .foregroundStyle(Theme.textSecondary(colorScheme))
            }
        }
        .padding(.vertical, Theme.Spacing.sm)
        .padding(.horizontal, Theme.Spacing.md)
    }
}

#Preview {
    VStack(spacing: 16) {
        // Day with items (not empty)
        DayHeaderRow(dayNumber: 1, date: Date(), isEmpty: false, onAddTapped: {})

        Divider()

        // Empty day
        DayHeaderRow(dayNumber: 2, date: Date().addingTimeInterval(86400), isEmpty: true, onAddTapped: {})
    }
    .padding()
    .background(Color.gray.opacity(0.1))
}
