//
//  OnboardingTime.swift
//  Feels (iOS)
//
//  Created by Trey Tartt on 1/20/22.
//

import SwiftUI

struct OnboardingTime: View {
    @ObservedObject var onboardingData: OnboardingData
    
    var formatter: DateFormatter {
        let dateFormatter = DateFormatter()
        dateFormatter.timeStyle = .short
        return dateFormatter
    }
    
    var body: some View {
        ZStack {
            GeometryReader { geometry in
                VStack {
                    Spacer()
                    Image("great", bundle: .main)
                        .foregroundColor(Color(UIColor.darkText))
                        .opacity(0.04)
                        .scaleEffect(1.2, anchor: .trailing)
                    Spacer()
                }
                
                
                ScrollView {
                    VStack {
                        Text(String(localized: "onboarding_time_title"))
                            .font(.title)
                            .padding()
                            .fixedSize(horizontal: false, vertical: true)
                            .foregroundColor(Color(UIColor.white))
                        
                        DatePicker("", selection: $onboardingData.date,
                                   displayedComponents: .hourAndMinute)
                        .scaleEffect(2)
                        .labelsHidden()
                        .frame(minWidth: 0, maxWidth: .infinity)
                        .padding()
                        .padding([.top, .bottom], 25)
                        .colorScheme(.dark)
                        
                        Text(String(format: String(localized: "onboarding_time_body"),
                                    formatter.string(from: onboardingData.date)))
                        .font(.body)
                        .fixedSize(horizontal: false, vertical: true)
                        .padding()
                        .foregroundColor(Color(UIColor.white))
                        
                    }
                    .frame(maxWidth: geometry.size.width)
                }
            }
        }
        .background(.green)
    }
}

struct OnboardingTime_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            OnboardingTime(onboardingData: OnboardingData())
            
            OnboardingTime(onboardingData: OnboardingData())
                .preferredColorScheme(.dark)
        }
    }
}
