//
//  SQProgressIndicator.swift
//  AlloVoisinsSwiftUI
//
//  Created by Victor on 02/06/2025.
//

import SwiftUI

struct SQProgressIndicator: View {
    @Binding var isActivated: Bool

    @State private var colorScheme: SQProgressIndicatorColorScheme = .neutral

    init(_ isActivated: Binding<Bool>) {
        self._isActivated = isActivated
    }

    var body: some View {
        Rectangle()
            .foregroundColor(.clear)
            .frame(maxWidth: .infinity, minHeight: 4, maxHeight: 4)
            .background(isActivated ? colorScheme.baseColor : Color.sqNeutral(20))
            .cornerRadius(8)
    }
}

// MARK: - Modifiers

extension SQProgressIndicator {
    func colorScheme(_ scheme: SQProgressIndicatorColorScheme) -> SQProgressIndicator {
        var copy = self
        copy._colorScheme = State(initialValue: scheme)
        return copy
    }
}

enum SQProgressIndicatorColorScheme: String, CaseIterable {
    case neutral
    case green

    var baseColor: Color {
        switch self {
        case .neutral:
            return .sqNeutral(80)
        case .green:
            return .sqSemanticGreen
        }
    }
}

#Preview {
    VStack {
        HStack {
            SQProgressIndicator(.constant(true))
            SQProgressIndicator(.constant(false))
            SQProgressIndicator(.constant(false))
        }
        HStack {
            SQProgressIndicator(.constant(true))
                .colorScheme(.green)
            SQProgressIndicator(.constant(true))
                .colorScheme(.green)
            SQProgressIndicator(.constant(false))
                .colorScheme(.green)
            SQProgressIndicator(.constant(false))
                .colorScheme(.green)
        }
    }
    .padding()
}
