import SwiftUI

struct VictoryOverlayView: View {
    let onNewGame: () -> Void

    @State private var showContent = false
    @Environment(\.accessibilityReduceMotion) private var reduceMotion

    var body: some View {
        ZStack {
            Color.black.opacity(0.6)
                .ignoresSafeArea()

            VStack(spacing: 24) {
                Text("You Win!")
                    .font(.largeTitle.bold())
                    .foregroundStyle(.white)

                Button("New Game") {
                    onNewGame()
                }
                .buttonStyle(.borderedProminent)
                .controlSize(.large)
            }
            .scaleEffect(showContent ? 1.0 : 0.5)
            .opacity(showContent ? 1.0 : 0)
        }
        .onAppear {
            if reduceMotion {
                showContent = true
            } else {
                withAnimation(.spring(response: 0.5, dampingFraction: 0.7)) {
                    showContent = true
                }
            }
        }
        .accessibilityAddTraits(.isModal)
        .accessibilityLabel(Text("You win! Double tap New Game to start a new game."))
    }
}
