//
//  OnboardingView.swift
//  SodaLive
//
//  Created by klaus on 2023/08/09.
//

import SwiftUI

struct OnboardingView: View {
    
    @State private var selection = 0
    
    var body: some View {
        GeometryReader { proxy in
            ZStack {
                VStack(spacing: 0) {
                    TabView(selection: $selection) {
                        Image("img_guide_0")
                            .resizable()
                            .scaledToFit()
                            .tag(0)
                        
                        Image("img_guide_1")
                            .resizable()
                            .scaledToFit()
                            .tag(1)
                        
                        Image("img_guide_2")
                            .resizable()
                            .scaledToFit()
                            .tag(2)
                        
                        Image("img_guide_3")
                            .resizable()
                            .scaledToFit()
                            .tag(3)
                        
                        Image("img_guide_4")
                            .resizable()
                            .scaledToFit()
                            .tag(4)
                        
                        Image("img_guide_5")
                            .resizable()
                            .scaledToFit()
                            .tag(5)
                        
                        Image("img_guide_6")
                            .resizable()
                            .scaledToFit()
                            .tag(6)
                    }
                    .tabViewStyle(PageTabViewStyle())
                    .onAppear {
                        UIPageControl.appearance().pageIndicatorTintColor = UIColor(hex: "555555", alpha: 0.24)
                        UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(hex: "1313BC")
                    }
                    
                    Text("μ‹œμž‘ν•˜κΈ°")
                        .font(.custom(Font.bold.rawValue, size: 18.3))
                        .foregroundColor(Color(hex: "1313BC"))
                        .frame(width: screenSize().width, height: 60)
                        .background(Color(hex: "80D8FF"))
                        .onTapGesture {
                            UserDefaults.set(true, forKey: .isViewedOnboardingView)
                        }
                    
                    if proxy.safeAreaInsets.bottom > 0 {
                        Rectangle()
                            .foregroundColor(Color(hex: "80D8FF"))
                            .frame(width: proxy.size.width, height: 15.3)
                    }
                }
            }
        }
        .ignoresSafeArea()
    }
}

struct OnboardingView_Previews: PreviewProvider {
    static var previews: some View {
        OnboardingView()
    }
}