package app.dudu.design

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color

/**
 * 语义化调色板：把自动生成的 DuduTheme.Light / DuduTheme.Dark（object，无公共类型）
 * 收敛成一个可注入 CompositionLocal 的 data class。颜色值全部来自 DuduTheme，禁止自造。
 */
@Immutable
data class DuduPalette(
    val accent: Color,
    val accentHover: Color,
    val accentPress: Color,
    val accentSoft: Color,
    val accentText: Color,
    val bgApp: Color,
    val surfaceCard: Color,
    val surface2: Color,
    val surface3: Color,
    val border1: Color,
    val border2: Color,
    val text1: Color,
    val text2: Color,
    val text3: Color,
    val textOnAccent: Color,
    val positive: Color,
    val positiveSoft: Color,
    val warning: Color,
    val warningSoft: Color,
    val danger: Color,
    val dangerSoft: Color,
    val overlayBg: Color,
    val overlayText: Color,
    val overlayText2: Color,
    val overlayText3: Color,
    val brandWechat: Color,
    val brandWechatPress: Color,
)

val DuduLightPalette = DuduPalette(
    accent = DuduTheme.Light.accent,
    accentHover = DuduTheme.Light.accentHover,
    accentPress = DuduTheme.Light.accentPress,
    accentSoft = DuduTheme.Light.accentSoft,
    accentText = DuduTheme.Light.accentText,
    bgApp = DuduTheme.Light.bgApp,
    surfaceCard = DuduTheme.Light.surfaceCard,
    surface2 = DuduTheme.Light.surface2,
    surface3 = DuduTheme.Light.surface3,
    border1 = DuduTheme.Light.border1,
    border2 = DuduTheme.Light.border2,
    text1 = DuduTheme.Light.text1,
    text2 = DuduTheme.Light.text2,
    text3 = DuduTheme.Light.text3,
    textOnAccent = DuduTheme.Light.textOnAccent,
    positive = DuduTheme.Light.positive,
    positiveSoft = DuduTheme.Light.positiveSoft,
    warning = DuduTheme.Light.warning,
    warningSoft = DuduTheme.Light.warningSoft,
    danger = DuduTheme.Light.danger,
    dangerSoft = DuduTheme.Light.dangerSoft,
    overlayBg = DuduTheme.Light.overlayBg,
    overlayText = DuduTheme.Light.overlayText,
    overlayText2 = DuduTheme.Light.overlayText2,
    overlayText3 = DuduTheme.Light.overlayText3,
    brandWechat = DuduTheme.Light.brandWechat,
    brandWechatPress = DuduTheme.Light.brandWechatPress,
)

val DuduDarkPalette = DuduPalette(
    accent = DuduTheme.Dark.accent,
    accentHover = DuduTheme.Dark.accentHover,
    accentPress = DuduTheme.Dark.accentPress,
    accentSoft = DuduTheme.Dark.accentSoft,
    accentText = DuduTheme.Dark.accentText,
    bgApp = DuduTheme.Dark.bgApp,
    surfaceCard = DuduTheme.Dark.surfaceCard,
    surface2 = DuduTheme.Dark.surface2,
    surface3 = DuduTheme.Dark.surface3,
    border1 = DuduTheme.Dark.border1,
    border2 = DuduTheme.Dark.border2,
    text1 = DuduTheme.Dark.text1,
    text2 = DuduTheme.Dark.text2,
    text3 = DuduTheme.Dark.text3,
    textOnAccent = DuduTheme.Dark.textOnAccent,
    positive = DuduTheme.Dark.positive,
    positiveSoft = DuduTheme.Dark.positiveSoft,
    warning = DuduTheme.Dark.warning,
    warningSoft = DuduTheme.Dark.warningSoft,
    danger = DuduTheme.Dark.danger,
    dangerSoft = DuduTheme.Dark.dangerSoft,
    overlayBg = DuduTheme.Dark.overlayBg,
    overlayText = DuduTheme.Dark.overlayText,
    overlayText2 = DuduTheme.Dark.overlayText2,
    overlayText3 = DuduTheme.Dark.overlayText3,
    brandWechat = DuduTheme.Dark.brandWechat,
    brandWechatPress = DuduTheme.Dark.brandWechatPress,
)

val LocalDuduPalette = staticCompositionLocalOf { DuduLightPalette }

/** 主题入口：light/dark 跟随系统。 */
@Composable
fun DuduDesign(content: @Composable () -> Unit) {
    val palette = if (isSystemInDarkTheme()) DuduDarkPalette else DuduLightPalette
    CompositionLocalProvider(LocalDuduPalette provides palette, content = content)
}
