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

import SwiftUI

enum KYCDocumentStatus: String {
    case accepted
    case missing
    case imported
    case pending
    case refused
    case expired

    var text: String {
        switch self {
        case .accepted:
            "Accepté"
        case .missing:
            "Manquant"
        case .imported:
            "Importé"
        case .pending:
            "En cours de vérification"
        case .refused:
            "Refusé"
        case .expired:
            "Expiré"
        }
    }

    var color: Color {
        switch self {
        case .accepted:
            .sqSemanticPositive
        case .missing:
            .sqNeutral(80)
        case .imported, .pending:
            .sqSemanticCritical
        case .refused, .expired:
            .sqSemanticNegative
        }
    }

    var icon: SQIcon {
        switch self {
        case .accepted:
            SQIcon(.check, size: .xs, color: color)
        case .missing:
            SQIcon(.circle_exclamation, size: .xs, color: color)
        case .imported, .pending:
            SQIcon(.hourglass_half, size: .xs, color: color)
        case .refused:
            SQIcon(.xmark, size: .xs, color: color)
        case .expired:
            SQIcon(.triangle_exclamation, size: .xs, color: color)
        }
    }
}

struct KYCDocumentButton: View {
    var name: String
    var desc: String
    var status: KYCDocumentStatus

    var body: some View {
        VStack(alignment: .leading) {
            HStack {
                SQText(name)
                    .sqFont(.bold)
                Spacer()
                HStack(spacing: 4) {
                    SQText(status.text)
                        .sqSize(13)
                        .sqFont(.semiBold)
                        .sqColor(status.color)
                    status.icon
                }
            }
            HStack {
                SQText(desc)
                    .sqSize(14)
                Spacer()
                if [.missing, .expired, .refused].contains(status) {
                    SQIcon(.chevron_right, size: .l)
                }
            }
        }
        .padding()
        .overlay(
            RoundedRectangle(cornerRadius: 8)
                .inset(by: 0.5)
                .stroke(Color.sqNeutral(30), lineWidth: 1)
        )
    }
}

#Preview {
    VStack {
        KYCDocumentButton(name: "Document d’identité", desc: "Carte d’identité, passeport, permis de conduire ou titre de séjour du représentant légal.", status: .pending)
        KYCDocumentButton(name: "Preuve d’immatriculation", desc: "Extrait Kbis de moins de 3 mois.", status: .accepted)
        KYCDocumentButton(name: "Statuts de la société", desc: "Statuts complets, à jour et signés.", status: .refused)
    }
    .padding()
}
