//
//  SQCircleButton.swift
//  AlloVoisinsSwiftUI
//
//  Created by Victor on 05/06/2025.
//

import SwiftUI

enum SQCircleButtonSize {
    case s
    case m
    case l

    var vertical: CGFloat {
        switch self {
        case .s:
            return 12
        case .m:
            return 12
        case .l:
            return 16
        }
    }

    var horizontal: CGFloat {
        switch self {
        case .s:
            return 30
        case .m:
            return 30
        case .l:
            return 25
        }
    }
}

struct SQCircleButton: View {
    let icon: SQIcon
    let text: String
    var color: Color
    var size: SQCircleButtonSize
    var isFull: Bool
    let action: () -> Void

    init(_ icon: SQIcon, text: String = "", color: Color = .white, size: SQCircleButtonSize = .m, isFull: Bool = true, action: @escaping () -> Void) {
        self.icon = icon
        self.text = text
        self.color = color
        self.size = size
        self.isFull = isFull
        self.action = action
    }

    var body: some View {
        Button {
            self.action()
        } label: {
            VStack(spacing: 2) {
                icon
                    .padding(.horizontal, size.horizontal)
                    .padding(.vertical, size.vertical)
                    .cornerRadius(100)
                    .background {
                        Circle()
                            .fill(isFull ? color : .white)
                            .overlay(
                                Circle()
                                    .stroke(isFull ? Color.white : color, lineWidth: 1)
                            )
                    }
                    .shadow(color: Color.black.opacity(0.15), radius: 8, x: 0, y: 4)

                if !text.isEmpty {
                    SQText(text)
                        .sqFont(.semiBold)
                        .sqColor(.sqNeutral(80))
                }
            }
        }
    }
}

#Preview {
    SQCircleButton(
        SQIcon(.arrow_right, size: .l)
    ) {}
    SQCircleButton(
        SQIcon(.arrow_left, size: .l)
    ) {}
    SQCircleButton(
        SQIcon(.plus, size: .l, color: .sqNeutral(80)),
        text: "Sélectionner",
        color: .sqNeutral(80),
        size: .l,
        isFull: false
    ) {}
}
