//
//  GenericResiliationScreen.swift
//  AlloVoisinsSwiftUI
//
//  Created by Victor on 14/10/2024.
//

import SwiftUI

protocol ResiliationContentView: View {
    var screenType: ResiliationScreenType { get }
}

enum ResiliationScreenType {
    case alloVoisinReputation
    case askIfWillComeBack
    case continueAsParticular
    case getMoreRatings
    case moreTime
    case onlyProRequests
    case personalizedSupport
    case profileCompletion
    case resizePerimeter
    case softwarePresentation
    case statusChange
    case webinaire

    var title: String {
        switch self {
        case .statusChange: return "Changer de statut"
        default: return "Ne partez pas !"
        }
    }

    var mainColor: Color {
        switch self {
        case .alloVoisinReputation, .moreTime: return Color.sqBlue(10)
        case .continueAsParticular, .resizePerimeter, .statusChange: return Color.sqOrange(10)
        case .getMoreRatings: return Color.sqGold(10)
        case .onlyProRequests, .personalizedSupport, .webinaire: return Color.sqGrape(10)
        case .profileCompletion: return Color.sqNeutral(10)
        case .softwarePresentation: return Color.white
        default: return Color.white
        }
    }

    var buttonColor: SQButtonColorScheme {
        switch self {
        case .alloVoisinReputation, .continueAsParticular, .profileCompletion, .softwarePresentation:
            return .neutral
        case .getMoreRatings: return .gold
        case .moreTime: return .blue
        case .onlyProRequests, .personalizedSupport, .webinaire: return .grape
        case .resizePerimeter, .statusChange: return .orange
        default: return .neutral
        }
    }

    var buttonTitle: String {
        switch self {
        case .alloVoisinReputation: return "Conserver mon abonnement"
        case .continueAsParticular: return "Changer de statut"
        case .getMoreRatings: return "Recueillir des avis"
        case .moreTime: return "Je prolonge ma période d'essai"
        case .onlyProRequests: return "Voir les demandes"
        case .personalizedSupport: return "Je souhaite être appelé"
        case .profileCompletion: return "Je complète mon profil"
        case .resizePerimeter: return "Modifier mon périmètre"
        case .softwarePresentation: return "Découvrir le logiciel"
        case .statusChange: return "Résilier et changer de statut"
        case .webinaire: return "Je m'inscris"
        default: return "Continuer"
        }
    }

    var cancelButtonTitle: String {
        switch self {
        case .moreTime, .personalizedSupport, .webinaire:
            return "Non merci, je souhaite résilier"
        default:
            return "J'ai compris, mais je souhaite résilier"
        }
    }
}

struct GenericResiliationScreen<Content: ResiliationContentView>: View {
    @ObservedObject var viewModel: PromotionalScreenViewModel
    @State private var navigateToNext = false
    let content: Content
    let buttonAction: () -> Void

    var body: some View {
        VStack(spacing: 16) {
            VStack(spacing: 32) {
                content
                    .padding(16)
                    .background(content.screenType.mainColor)
                    .cornerRadius(8)

                SQButton(content.screenType.buttonTitle, action: buttonAction)
                    .sqColorScheme(content.screenType.buttonColor)
            }

            if content.screenType != .statusChange {
                SQButton(content.screenType.cancelButtonTitle) {
                    navigateToNext = true
                }
                .sqButtonType(.glass)
                .sqTextSize(13)
            }
        }
        .navigationDestination(isPresented: $navigateToNext) {
            if let screen = viewModel.nextPromotionalScreen {
                viewModel.getPromotionalScreenNew(for: screen)
            } else {
                ResiliationConfirmationScreen()
            }
        }
        .sqNavigationBar(title: content.screenType.title)
        .padding()
    }
}

//#Preview {
//    GenericResiliationScreen(viewModel: ResiliationViewModel(resiliationType: .apProWithTrial), content: ResiliationContentView) {
//
//    }
//}
struct AlloVoisinReputationScreens: View {
    @ObservedObject var viewModel: PromotionalScreenViewModel

    var body: some View {
        GenericResiliationScreen(
            viewModel: viewModel,
            content: AlloVoisinReputationContent(),
            buttonAction: {
                // Handle button action
            }
        )
    }
}

#Preview {
    AlloVoisinReputationScreens(viewModel: PromotionalScreenViewModel())
}

struct AlloVoisinReputationContent: ResiliationContentView {
    let screenType: ResiliationScreenType = .alloVoisinReputation

    var body: some View {
        VStack(spacing: 32) {
            VStack {
                SQText("Le saviez-vous ?")
                    .sqSize(20)
                    .sqFont(.bold)
                SQText("AlloVoisins en France, c'est :")
                    .sqSize(20)
                    .sqFont(.bold)
            }
            VStack {
                SQText("4,5 millions")
                    .sqSize(32)
                    .sqFont(.bold)
                SQText("de membres, partout en France")
            }
            .padding(16)
            .background(Color.white)
            .cornerRadius(8)
            // ... Rest of the content
        }
    }
}
