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

import SwiftUI
import Bedrock

/// Component for displaying top overlay with battery and date information
struct TopOverlayView: View {
    
    // MARK: - Properties
    let showBattery: Bool
    let showDate: Bool
    let color: Color
    let opacity: Double
    let dateFormat: String
    
    @State private var batteryService = BatteryService.shared
    
    // MARK: - Body
    var body: some View {
        HStack {
            if showDate {
                DateOverlayView(color: color, opacity: opacity, dateFormat: dateFormat)
            }
            
            Spacer()
            
            if showBattery {
                BatteryOverlayView(
                    color: color, 
                    opacity: opacity, 
                    batteryLevel: batteryService.batteryLevel,
                    isCharging: batteryService.isCharging
                )
            }
        }
        .padding(.horizontal, Design.Spacing.medium)
        .padding(.vertical, Design.Spacing.small)
        .transition(.opacity)
        .onAppear {
            batteryService.startMonitoring()
        }
        .onDisappear {
            batteryService.stopMonitoring()
        }
    }
}
