//
//  ClockView.swift
//  TheNoiseClock
//
//  Created by Matt Bruce on 9/7/25.
//

import SwiftUI

/// Main clock display view with settings and display mode
struct ClockView: View {
    
    // MARK: - Properties
    @State private var viewModel = ClockViewModel()
    @State private var showSettings = false
    
    // MARK: - Body
    var body: some View {
        ZStack {
            viewModel.style.backgroundColor
                .ignoresSafeArea()
            
            GeometryReader { geometry in
                ZStack {
                    // Main clock display container
                    ClockDisplayContainer(
                        currentTime: viewModel.currentTime,
                        style: viewModel.style,
                        isDisplayMode: viewModel.isDisplayMode
                    )
                    
                    // Top overlay container
                    ClockOverlayContainer(style: viewModel.style)
                }
            }
        }
        .ignoresSafeArea(.all, edges: viewModel.isDisplayMode ? .bottom : [])
        .statusBarHidden(viewModel.isDisplayMode)
        .sheet(isPresented: $showSettings) {
            ClockSettingsView(style: viewModel.style) { newStyle in
                viewModel.updateStyle(newStyle)
            }
            .presentationDetents([.medium, .large])
        }
        .overlay {
            // Toolbar overlay
            ClockToolbar(
                isDisplayMode: viewModel.isDisplayMode,
                onSettingsTap: { showSettings = true }
            )
        }
        .overlay {
            // Tab bar management overlay
            ClockTabBarManager(isDisplayMode: viewModel.isDisplayMode, animated: true)
        }
        .overlay {
            // Gesture handling overlay
            ClockGestureHandler {
                viewModel.toggleDisplayMode()
            }
        }
    }
}

// MARK: - Preview
#Preview {
    NavigationStack {
        ClockView()
    }
}
