//
//  BoosterSubscriptionSelectionScreen.swift
//
//
//  Created by Victor on 12/06/2024.
//

import SwiftUI

let backgroundGradient = LinearGradient(
    colors: [Color.sqRoyal(), Color.sqPurple()],
    startPoint: .top, endPoint: .bottom)

struct ElipseShape: Shape {
    func path(in rect: CGRect) -> Path {
        var path = Path()
        let width = rect.width
        let height = rect.height

        path.move(to: CGPoint(x: 0, y: height))
        
        let midHeight = height * 0.1
        let controlPoint1 = CGPoint(x: width * 0.5, y: height + midHeight)
        let endPoint = CGPoint(x: width, y: height)
        
        path.addQuadCurve(to: endPoint, control: controlPoint1)
        
        path.addLine(to: CGPoint(x: width, y: 0))
        
        path.addLine(to: CGPoint(x: 0, y: 0))
        
        path.closeSubpath()
        
        return path
    }
}

struct BoosterSubscriptionSelectionScreen: View {
    var cancellation: Bool = true
    @State var mode: BoosterSubscriptionMode = .edit
    @State var isNotPremier = false

    var body: some View {
        NavigationView {
            ZStack(alignment: .top) {
                VStack {
                    Color.sqRoyal()
                        .frame(height: 100)
                }
                ScrollViewReader { _ in
                    ScrollView(showsIndicators: false) {
                        VStack(spacing: 48) {
                            ZStack {
                                ElipseShape()
                                    .fill(backgroundGradient)
                                
                                VStack(alignment: .trailing) {
                                    BoosterLockedToPremierView()
                                    VStack(spacing: 16) {
                                        Image("booster_logo")
                                            .resizable()
                                            .frame(width: 210, height: 180)
                                        
                                        BoosterFeaturesView()
                                            .padding(.horizontal)
                                    }
                                }
                                .padding([.top], 48)
                            }
                            ZStack {
                                Color.white
                                VStack(spacing: 32) {
                                    VStack(spacing: 16) {
                                        BoosterStatsView()
                                            .padding([.leading, .trailing], 8)
                                        BoosterSelectionView()
                                    }
                                    
                                    VStack {
                                        SQButton("C'est parti !") {}
                                        if cancellation {
                                            Button(action: /*@START_MENU_TOKEN@*/ {}/*@END_MENU_TOKEN@*/, label: {
                                                SQText("Non merci, je souhaite résilier", size: 13)
                                                    .foregroundColor(.black)
                                            })
                                            .padding()
                                        }
                                    }
                                    .padding([.top], 8)
                                }
                            }
                        }
                    }
                }
            }
            .edgesIgnoringSafeArea(.top)
        }
        .bottomSheet(isShowing: $isNotPremier, opacified: false, dismissable: false) {
            OnlyForPremierView()
        }
    }
}

#Preview {
    BoosterSubscriptionSelectionScreen()
}

enum BoosterSubscriptionMode {
    case subscribe
    case edit
    case cancel
}
