package com.fabledsword.minstrel.theme

import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp

/**
 * Mode-resolved snapshot of the FabledSword design system, exposed via
 * [LocalFabledSwordTheme]. Mirrors the Flutter `FabledSwordTheme`
 * ThemeExtension — most Flutter widgets read `Theme.of(context).extension<
 * FabledSwordTheme>()!.parchment` directly rather than via `colorScheme`,
 * and the Android port follows the same convention to keep token
 * semantics centralized rather than scattered across Material role mappings.
 *
 * UI code reads tokens via `LocalFabledSwordTheme.current.parchment`,
 * `.iron`, `.accent`, etc. The MinstrelTheme composable swaps between
 * the dark and light instances based on system mode.
 */
data class FabledSwordTheme(
    // Surface ladder (lightest text → darkest bg).
    val parchment: Color,
    val vellum: Color,
    val ash: Color,
    val pewter: Color,
    val slate: Color,
    val iron: Color,
    val obsidian: Color,

    // Mode-independent action + status colors.
    val moss: Color,
    val bronze: Color,
    val oxblood: Color,
    val warning: Color,
    val error: Color,
    val info: Color,
    val accent: Color,
    val onAction: Color,

    // Radii.
    val radiusSm: Dp,
    val radiusMd: Dp,
    val radiusLg: Dp,
    val radiusXl: Dp,
) {
    companion object {
        val Dark: FabledSwordTheme = FabledSwordTheme(
            parchment = FabledSwordDarkTokens.parchment,
            vellum = FabledSwordDarkTokens.vellum,
            ash = FabledSwordDarkTokens.ash,
            pewter = FabledSwordDarkTokens.pewter,
            slate = FabledSwordDarkTokens.slate,
            iron = FabledSwordDarkTokens.iron,
            obsidian = FabledSwordDarkTokens.obsidian,
            moss = FabledSwordFlatTokens.moss,
            bronze = FabledSwordFlatTokens.bronze,
            oxblood = FabledSwordFlatTokens.oxblood,
            warning = FabledSwordFlatTokens.warning,
            error = FabledSwordFlatTokens.error,
            info = FabledSwordFlatTokens.info,
            accent = FabledSwordFlatTokens.accent,
            onAction = FabledSwordFlatTokens.onAction,
            radiusSm = FabledSwordFlatTokens.radiusSm,
            radiusMd = FabledSwordFlatTokens.radiusMd,
            radiusLg = FabledSwordFlatTokens.radiusLg,
            radiusXl = FabledSwordFlatTokens.radiusXl,
        )

        val Light: FabledSwordTheme = FabledSwordTheme(
            parchment = FabledSwordLightTokens.parchment,
            vellum = FabledSwordLightTokens.vellum,
            ash = FabledSwordLightTokens.ash,
            pewter = FabledSwordLightTokens.pewter,
            slate = FabledSwordLightTokens.slate,
            iron = FabledSwordLightTokens.iron,
            obsidian = FabledSwordLightTokens.obsidian,
            moss = FabledSwordFlatTokens.moss,
            bronze = FabledSwordFlatTokens.bronze,
            oxblood = FabledSwordFlatTokens.oxblood,
            warning = FabledSwordFlatTokens.warning,
            error = FabledSwordFlatTokens.error,
            info = FabledSwordFlatTokens.info,
            accent = FabledSwordFlatTokens.accent,
            onAction = FabledSwordFlatTokens.onAction,
            radiusSm = FabledSwordFlatTokens.radiusSm,
            radiusMd = FabledSwordFlatTokens.radiusMd,
            radiusLg = FabledSwordFlatTokens.radiusLg,
            radiusXl = FabledSwordFlatTokens.radiusXl,
        )
    }
}

/**
 * Reads as `LocalFabledSwordTheme.current.X` from anywhere inside a
 * [MinstrelTheme] composable scope. Default = dark; the MinstrelTheme
 * composable overrides this based on system mode.
 */
val LocalFabledSwordTheme = staticCompositionLocalOf { FabledSwordTheme.Dark }
