package com.anypreta.bountyboard.ui.theme

import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color

/**
 * The BountyBoard palette — "The Ledger". Warm paper grounds, brown/amber ink,
 * editorial accents. Mirrors the web app's CSS custom properties
 * (web/static/css/app.css) for light + dark, plus the four alternate themes.
 */
@Immutable
data class BBPalette(
    val bg: Color,
    val surface: Color,
    val surface2: Color,
    val border: Color,
    val text: Color,
    val muted: Color,
    val accent: Color,
    val onAccent: Color,
    val ok: Color,
    val warn: Color,
    val err: Color,
    val radius: Int,
    val isDark: Boolean,
)

enum class BBTheme(val id: String, val label: String) {
    Light("light", "Light"),
    Dark("dark", "Dark"),
    Neon("neon", "Neon"),
    Terminal("terminal", "Terminal"),
    Blueprint("blueprint", "Blueprint"),
    Sunset("sunset", "Sunset");

    companion object {
        fun from(id: String?): BBTheme = entries.firstOrNull { it.id == id } ?: Light
    }
}

val LightPalette = BBPalette(
    bg = Color(0xFFFFFFFF),
    surface = Color(0xFFFDFBF6),
    surface2 = Color(0xFFF2E9D8),
    border = Color(0xFFA88452),
    text = Color(0xFF33230E),
    muted = Color(0xFF7C6647),
    accent = Color(0xFF7A4A14),
    onAccent = Color(0xFFFFFFFF),
    ok = Color(0xFF2E6B3C),
    warn = Color(0xFF955D0E),
    err = Color(0xFF9C3A2E),
    radius = 2,
    isDark = false,
)

val DarkPalette = BBPalette(
    bg = Color(0xFF171209),
    surface = Color(0xFF221A0E),
    surface2 = Color(0xFF2E2414),
    border = Color(0xFF7C5F33),
    text = Color(0xFFF3E8D2),
    muted = Color(0xFFB59C74),
    accent = Color(0xFFD9A548),
    onAccent = Color(0xFF241606),
    ok = Color(0xFF7FB78A),
    warn = Color(0xFFD9A44A),
    err = Color(0xFFD97B6C),
    radius = 2,
    isDark = true,
)

val NeonPalette = BBPalette(
    bg = Color(0xFF080014),
    surface = Color(0xFF160A32),
    surface2 = Color(0xFF221248),
    border = Color(0xFF7A3BF0),
    text = Color(0xFFECE6FF),
    muted = Color(0xFFA48FE0),
    accent = Color(0xFF00E5FF),
    onAccent = Color(0xFF06000F),
    ok = Color(0xFF39FF9E),
    warn = Color(0xFFFFD23F),
    err = Color(0xFFFF3B8B),
    radius = 8,
    isDark = true,
)

val TerminalPalette = BBPalette(
    bg = Color(0xFF000A02),
    surface = Color(0xFF04140A),
    surface2 = Color(0xFF06200F),
    border = Color(0xFF1F8F3F),
    text = Color(0xFF41FF7A),
    muted = Color(0xFF1FB04F),
    accent = Color(0xFF7DFF9F),
    onAccent = Color(0xFF021006),
    ok = Color(0xFF7DFF9F),
    warn = Color(0xFFD7FF3F),
    err = Color(0xFFFF5D5D),
    radius = 0,
    isDark = true,
)

val BlueprintPalette = BBPalette(
    bg = Color(0xFF082A4D),
    surface = Color(0xFF0C3460),
    surface2 = Color(0xFF114576),
    border = Color(0xFF6FB8FF),
    text = Color(0xFFEAF4FF),
    muted = Color(0xFF9CC6F0),
    accent = Color(0xFFFFD24A),
    onAccent = Color(0xFF082A4D),
    ok = Color(0xFF7FFFD4),
    warn = Color(0xFFFFD24A),
    err = Color(0xFFFF9A8A),
    radius = 0,
    isDark = true,
)

val SunsetPalette = BBPalette(
    bg = Color(0xFF2A1138),
    surface = Color(0xFF3A1A4E),
    surface2 = Color(0xFF4D2363),
    border = Color(0xFFFF8EC7),
    text = Color(0xFFFFF0FB),
    muted = Color(0xFFE0A9D6),
    accent = Color(0xFFFFB347),
    onAccent = Color(0xFF2A1138),
    ok = Color(0xFF7EF0C4),
    warn = Color(0xFFFFD76A),
    err = Color(0xFFFF6B8E),
    radius = 12,
    isDark = true,
)

fun paletteFor(theme: BBTheme): BBPalette = when (theme) {
    BBTheme.Light -> LightPalette
    BBTheme.Dark -> DarkPalette
    BBTheme.Neon -> NeonPalette
    BBTheme.Terminal -> TerminalPalette
    BBTheme.Blueprint -> BlueprintPalette
    BBTheme.Sunset -> SunsetPalette
}
