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

import SwiftUI

enum DayOptions: Int, CaseIterable, RawRepresentable, Codable {
    case Today
    case Previous
    
    var localizedValue: String {
        switch self {
            
        case .Today:
            return  String(localized: "onboarding_day_options_today")
        case .Previous:
            return  String(localized: "onboarding_day_options_yesterday")
        }
    }
}

struct OnboardingDay: View {
    @ObservedObject var onboardingData: OnboardingData
    
    var previewText: String {
        switch onboardingData.inputDay {
        case .Today:
            return String(localized: "onboarding_day_preview_text_today")
        case .Previous:
            return String(localized: "onboarding_day_preview_text_yesterday")
        }
    }
    
    var body: some View {
        ZStack {
            GeometryReader { geometry in
                VStack {
                    Spacer()
                    Image("average", bundle: .main)
                        .foregroundColor(Color(UIColor.darkText))
                        .opacity(0.04)
                        .scaleEffect(1.2, anchor: .trailing)
                    Spacer()
                }
                
                ScrollView {
                    VStack{
                        Text(String(localized: "onboarding_day_title"))
                            .font(.title)
                            .padding()
                            .fixedSize(horizontal: false, vertical: true)
                            .foregroundColor(Color(UIColor.white))

                        
                        Picker(selection: $onboardingData.inputDay,
                               label: Text("")) {
                            ForEach(DayOptions.allCases, id: \.self) { day in
                                Text(day.localizedValue)
                            }
                        }
                               .padding()
                               .colorScheme(.dark)
                               .padding([.trailing, .leading], 55)
                               .pickerStyle(SegmentedPickerStyle())
                        
                        Text(previewText)
                            .font(.body)
                            .padding()
                            .fixedSize(horizontal: false, vertical: true)
                            .foregroundColor(Color(UIColor.white))
                    }
                    .frame(maxWidth: geometry.size.width)
                }
            }
        }
        .background(.blue)
    }
}

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