//
// GameDaySection.swift
// IceGlass-iOS
//
// Copyright 2026 Rouslan Zenetl. All Rights Reserved.
//

import SwiftUI

struct GameDaySection: View {
    let gameDay: Scoreboard.GameDay

    var body: some View {
        VStack(alignment: .leading, spacing: 8) {
            HStack(alignment: .firstTextBaseline) {
                Text(headerText)
                    .font(.caption)
                    .fontWeight(.bold)
                    .foregroundStyle(.secondary)
                Spacer()
            }

            if gameDay.games.isEmpty {
                Text("No games scheduled")
                    .font(.subheadline)
                    .italic()
                    .foregroundStyle(.tertiary)
                    .padding(.horizontal, 14)
                    .padding(.vertical, 12)
                    .frame(maxWidth: .infinity, alignment: .leading)
                    .background(Color(uiColor: .secondarySystemGroupedBackground))
                    .clipShape(RoundedRectangle(cornerRadius: 12))
            } else {
                VStack(spacing: 0) {
                    ForEach(Array(gameDay.games.enumerated()), id: \.element.id) { idx, game in
                        GameRow(game: game)
                        if idx < gameDay.games.count - 1 {
                            Divider()
                        }
                    }
                }
                .background(Color(uiColor: .secondarySystemGroupedBackground))
                .clipShape(RoundedRectangle(cornerRadius: 12))
            }
        }
    }

    private var headerText: String {
        let label = Date.fullDateLabel(for: gameDay.date)
        return "\(label) (\(gameDay.games.count))"
    }
}
