//
//  ResiliationReasonScreen.swift
//  Sequoia
//
//  Created by Victor on 10/10/2024.
//

import SwiftUI

struct ResiliationReasonScreen: View {
    @Environment(\.dismiss) var dismiss
    @ObservedObject var viewModel: ResiliationViewModel
    @State private var selectedIndex: Int? = nil
    @State private var resiliationOtherMotif: String = ""

    var body: some View {
        ScrollView {
            VStack(spacing: 16) {
                SQRadio(title: "Aidez-nous à nous améliorer : précisez le motif de votre résiliation",
                        options: viewModel.resiliationReasons.map { $0.text },
                        selectedIndex: $selectedIndex)
                if selectedIndex == viewModel.resiliationReasons.count - 1 {
                    SQTextField("", placeholder: "Précisez-nous le motif de votre résiliation", text: $resiliationOtherMotif)
                }

                HStack {
                    SQButton("Annuler", color: .sqNeutral(100), isFull: false) {
                        dismiss()
                    }
                    SQButton("Continuer", color: .sqNeutral(100), textColor: .white) {
                        // TODO: Aller au prochain promotional screen
                        if let index = selectedIndex {
                            let selectedReason = viewModel.resiliationReasons[index]
                            viewModel.setSelectedReason(selectedReason)
                        }
                    }
                    .disabled(selectedIndex == nil)
                }
                Spacer()
            }
        }
        .padding()
        .sqNavigationBar(title: "Demander la résiliation")
    }
}

 #Preview {
     ResiliationReasonScreen(viewModel: ResiliationViewModel(resiliationType: .apProWithTrial))
 }
