//
//  IdentityDocumentButton.swift
//  AlloVoisinsSwiftUI
//
//  Created by Victor on 11/12/2024.
//

import SwiftUI

enum IdentityDocumentButtonType {
    case nationalID
    case passport
    case driverLicense
    case residencePermit

    var title: String {
        switch self {
        case .nationalID:
            "Carte nationale d’identité"
        case .passport:
            "Passeport"
        case .driverLicense:
            "Permis de conduire"
        case .residencePermit:
            "Titre de séjour"
        }
    }

    var subtitle: String {
        switch self {
        case .driverLicense:
            "Nouveau format (après septembre 2013)"
        default:
            ""
        }
    }

    var icon: SQIcon {
        switch self {
        case .nationalID:
            SQIcon(.address_card)
        case .passport:
            SQIcon(.passport)
        case .driverLicense:
            SQIcon(.car_side)
        case .residencePermit:
            SQIcon(.address_card)
        }
    }
}

struct IdentityDocumentButton: View {
    var type: IdentityDocumentButtonType
    var action: () -> Void

    var body: some View {
        Button {
            action()
        } label: {
            HStack {
                type.icon
                    .padding(8)
                    .background {
                        RoundedRectangle(cornerRadius: 8)
                            .fill(Color.sqNeutral(10))
                    }
                VStack(alignment: .leading) {
                    SQText(type.title)
                    if !type.subtitle.isEmpty {
                        SQText(type.subtitle)
                            .sqSize(13)
                            .sqColor(.sqNeutral(70))
                    }
                }
                Spacer()
                SQIcon(.chevron_right, size: .xl)
            }
            .padding()
            .overlay(
                RoundedRectangle(cornerRadius: 8)
                    .inset(by: 0.5)
                    .stroke(Color.sqNeutral(30), lineWidth: 1)
            )
        }
    }
}

#Preview {
    VStack {
        IdentityDocumentButton(type: .nationalID) {

        }
        IdentityDocumentButton(type: .passport) {

        }
        IdentityDocumentButton(type: .driverLicense) {

        }
        IdentityDocumentButton(type: .residencePermit) {

        }
    }
    .padding()
}
