import SwiftUI

struct PriorityBadge: View {
    let priority: String

    var body: some View {
        HStack(spacing: 5) {
            Image(systemName: priorityIcon)
                .font(.system(size: 10, weight: .bold))

            Text(priority.capitalized)
                .font(.system(size: 11, weight: .semibold, design: .rounded))
        }
        .padding(.horizontal, 10)
        .padding(.vertical, 5)
        .foregroundColor(priorityColor)
        .background(
            Capsule()
                .fill(priorityColor.opacity(0.12))
                .overlay(
                    Capsule()
                        .stroke(priorityColor.opacity(0.2), lineWidth: 1)
                )
        )
        .accessibilityElement(children: .combine)
        .accessibilityLabel(A11y.Task.priorityBadge(level: priority.capitalized))
    }

    private var priorityIcon: String {
        switch priority.lowercased() {
        case "high": return "exclamationmark.triangle.fill"
        case "medium": return "exclamationmark.circle.fill"
        case "low": return "minus.circle.fill"
        default: return "circle.fill"
        }
    }

    private var priorityColor: Color {
        switch priority.lowercased() {
        case "high": return Color.appError
        case "medium": return Color.appAccent
        case "low": return Color.appPrimary
        default: return Color.appTextSecondary
        }
    }
}

#Preview {
    VStack(spacing: 12) {
        PriorityBadge(priority: "high")
        PriorityBadge(priority: "medium")
        PriorityBadge(priority: "low")
    }
    .padding()
    .background(WarmGradientBackground())
}
