import SwiftUI

// MARK: - Accent Theme

enum AccentTheme: String, CaseIterable, Identifiable {
    case ocean    = "ocean"
    case indigo   = "indigo"
    case teal     = "teal"
    case mint     = "mint"
    case sage     = "sage"
    case amber    = "amber"
    case rose     = "rose"
    case graphite = "graphite"

    var id: String { rawValue }

    var displayName: String {
        switch self {
        case .ocean:    return "Ocean"
        case .indigo:   return "Indigo"
        case .teal:     return "Teal"
        case .mint:     return "Mint"
        case .sage:     return "Sage"
        case .amber:    return "Amber"
        case .rose:     return "Rose"
        case .graphite: return "Graphite"
        }
    }

    /// Primary accent — used for shelves, primary buttons, active states
    var shelfColor: Color {
        switch self {
        case .ocean:    return .blue
        case .indigo:   return .indigo
        case .teal:     return .teal
        case .mint:     return .mint
        case .sage:     return Color(red: 0.369, green: 0.545, blue: 0.431)
        case .amber:    return .orange
        case .rose:     return .pink
        case .graphite: return Color(red: 0.420, green: 0.447, blue: 0.502)
        }
    }

    /// Secondary — used for books
    var bookColor: Color {
        switch self {
        case .ocean:    return .cyan
        case .indigo:   return .purple
        case .teal:     return .mint
        case .mint:     return .teal
        case .sage:     return Color(red: 0.290, green: 0.478, blue: 0.541)
        case .amber:    return Color(red: 0.816, green: 0.624, blue: 0.173)
        case .rose:     return .red
        case .graphite: return Color(red: 0.545, green: 0.584, blue: 0.631)
        }
    }

    /// Tertiary — used for pages
    var pageColor: Color {
        switch self {
        case .ocean:    return Color(red: 0.180, green: 0.639, blue: 0.659)  // custom teal-green
        case .indigo:   return .blue
        case .teal:     return .cyan
        case .mint:     return .green
        case .sage:     return Color(red: 0.420, green: 0.557, blue: 0.369)
        case .amber:    return Color(red: 0.910, green: 0.576, blue: 0.353)
        case .rose:     return .orange
        case .graphite: return Color(red: 0.612, green: 0.639, blue: 0.671)
        }
    }

    /// The single tint used for navigation bars, links, and interactive elements
    var accentColor: Color { shelfColor }
}

// MARK: - Environment Key

private struct AccentThemeKey: EnvironmentKey {
    static let defaultValue: AccentTheme = .ocean
}

extension EnvironmentValues {
    var accentTheme: AccentTheme {
        get { self[AccentThemeKey.self] }
        set { self[AccentThemeKey.self] = newValue }
    }
}
