import SwiftUI

// MARK: - Legend Bar (iOS)

/// Horizontal bar showing part names in their respective colors.
/// Shows a microphone icon next to parts that have recordings.
struct LegendBar_iOS: View {
    let parts: [Part]
    let recordedParts: Set<String>

    var body: some View {
        ScrollView(.horizontal, showsIndicators: false) {
            HStack(spacing: 14) {
                ForEach(Array(parts.enumerated()), id: \.element.name) { index, part in
                    HStack(spacing: 5) {
                        Circle()
                            .fill(partColor(for: part.colorIndex))
                            .frame(width: 8, height: 8)
                        Text(part.name)
                            .font(.system(size: 12, weight: .medium))
                            .foregroundColor(partColor(for: part.colorIndex))

                        if recordedParts.contains(part.name) {
                            Image(systemName: "mic.fill")
                                .font(.system(size: 9))
                                .foregroundColor(.green)
                        }
                    }
                }
            }
            .padding(.horizontal, 16)
            .padding(.vertical, 6)
        }
        .background(Color(uiColor: .systemGroupedBackground))
    }

    private func partColor(for index: Int) -> Color {
        let rgb = PartColors.paletteRGB[index % PartColors.paletteRGB.count]
        return Color(red: rgb.r, green: rgb.g, blue: rgb.b)
    }
}
