import SwiftUI

enum DefaultCoverArt {
    private static let palettes: [(Color, Color, String)] = [
        (Color(red: 0.55, green: 0.78, blue: 0.95), Color(red: 0.35, green: 0.55, blue: 0.85), "rocket"),
        (Color(red: 1.0, green: 0.92, blue: 0.55), Color(red: 0.95, green: 0.70, blue: 0.30), "pawprint"),
        (Color(red: 0.75, green: 0.90, blue: 0.65), Color(red: 0.40, green: 0.70, blue: 0.45), "textformat.123"),
        (Color(red: 0.95, green: 0.70, blue: 0.75), Color(red: 0.85, green: 0.45, blue: 0.55), "paintpalette"),
        (Color(red: 0.70, green: 0.82, blue: 0.95), Color(red: 0.50, green: 0.60, blue: 0.85), "house"),
        (Color(red: 0.85, green: 0.75, blue: 0.95), Color(red: 0.60, green: 0.45, blue: 0.80), "star"),
    ]

    static func index(for id: String) -> Int {
        abs(id.hashValue) % palettes.count
    }

    static func view(for courseId: String, title: String) -> some View {
        let i = index(for: courseId)
        let (bg, accent, symbol) = palettes[i]
        return ZStack {
            LinearGradient(colors: [bg, accent.opacity(0.55)], startPoint: .topLeading, endPoint: .bottomTrailing)
            Image(systemName: symbol)
                .font(.system(size: 44, weight: .medium))
                .foregroundStyle(.white.opacity(0.92))
                .shadow(color: .black.opacity(0.12), radius: 4, y: 2)
        }
        .overlay(alignment: .bottom) {
            Text(title)
                .font(.caption.weight(.semibold))
                .foregroundStyle(.white.opacity(0.001)) // accessibility label only on tile
                .accessibilityHidden(true)
        }
        .accessibilityLabel(title)
    }
}
