//
//  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 {
            
            Image("average", bundle: .main)
                .foregroundColor(Color(UIColor.darkText))
                .opacity(0.04)
                .scaleEffect(1.2)
                .padding(.bottom, 55)
            
            ScrollView {
                VStack{
                    Text(String(localized: "onboarding_day_title"))
                        .font(.title)
                        .foregroundColor(Color(UIColor.white))
                        .padding([.trailing, .leading], 55)
                        .padding([.top], 25)
                    
                    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(String(localized: "onboarding_day_body"))
                        .font(.body)
                        .foregroundColor(Color(UIColor.white))
                        .padding([.trailing, .leading], 75)
                        .padding([.top], 15)
                    
                    Text(previewText)
                        .font(.body)
                        .foregroundColor(Color(UIColor.white))
                        .padding([.trailing, .leading], 75)
                        .padding([.top], 15)
                    
                    Spacer()
                    
                    
                }
            }
        }
        .background(.blue)
    }
}

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