//
//  QuarterTimePickerView.swift
//  SodaLive
//
//  Created by klaus on 2024/01/10.
//

import SwiftUI

struct QuarterTimePickerView: View {
    
    @Binding var selectedTime: Date
    @Binding var isShowing: Bool
    
    var body: some View {
        GeometryReader { proxy in
            ZStack {
                Color
                    .black
                    .opacity(0.5)
                    .edgesIgnoringSafeArea(.all)
                
                VStack(spacing: 0) {
                    DatePicker(
                        "",
                        selection: $selectedTime,
                        displayedComponents: .hourAndMinute
                    )
                    .datePickerStyle(WheelDatePickerStyle())
                    .labelsHidden()
                    .environment(\.locale, Locale.init(identifier: "ko"))
                    .frame(width: proxy.size.width - 53.4)
                    .onAppear {
                        UIDatePicker.appearance().minuteInterval = 15
                    }
                    .onDisappear {
                        UIDatePicker.appearance().minuteInterval = 1
                    }
                    
                    Button(action: { self.isShowing = false }) {
                        Text("확인")
                            .font(.system(size: 16))
                            .foregroundColor(Color(hex: "eeeeee"))
                            .padding(.vertical, 10)
                            .frame(width: proxy.size.width)
                    }
                }
                .background(Color(hex: "222222"))
                .cornerRadius(6.7)
            }
            .frame(width: proxy.size.width)
        }
    }
}

struct QuarterTimePickerView_Previews: PreviewProvider {
    static var previews: some View {
        QuarterTimePickerView(
            selectedTime: .constant(Date()),
            isShowing: .constant(true)
        )
    }
}
