//
//  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)
                    }
                    .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(.white)
                        .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()
    }
}
