import SwiftUI

/// The leading icon a list row renders when its item has one — the symbol name straight from
/// frontmatter, tinted through the palette with `.secondary` standing in for any name the
/// palette does not know. Decorative: the row's text is the accessible content.
struct ItemIconView: View {
    let icon: String?
    let iconColor: String?

    var body: some View {
        if let icon, !icon.isEmpty {
            Image(systemName: icon)
                .foregroundStyle(tint)
                .accessibilityHidden(true)
        }
    }

    /// An unrecognized colour name falls back to `.secondary` rather than guessing — the same
    /// leniency `CardPalette.color(named:in:)` documents for itself.
    private var tint: Color {
        iconColor.flatMap { CardPalette.color(named: $0, in: CardPalette.foregrounds) } ?? .secondary
    }
}
