package com.radiola.ui.theme

import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color

/**
 * Расширенные токены, которых нет в Material ColorScheme.
 * Доступ через MaterialTheme-стиль: `RadiolaTheme.colors`.
 */
data class RadiolaColors(
    val bgBase: Color = BgBase,
    val surface: Color = BgSurface,
    val surface2: Color = BgSurface2,
    val elevated: Color = BgElevated,
    val accent: Color = Accent,
    val accentDim: Color = AccentDim,
    val textPrimary: Color = TextPrimary,
    val textSecondary: Color = TextSecondary,
    val textMuted: Color = TextMuted,
    val border: Color = BorderColor,
    val live: Color = LiveRed,
) {
    val brandGradient: Brush
        get() = Brush.linearGradient(listOf(BrandGradientStart, BrandGradientEnd))
}

val LocalRadiolaColors = staticCompositionLocalOf { RadiolaColors() }

object RadiolaTheme {
    val colors: RadiolaColors
        @Composable get() = LocalRadiolaColors.current
}

private val DarkColorScheme = darkColorScheme(
    primary = Accent,
    onPrimary = BgBase,
    secondary = AccentDim,
    onSecondary = BgBase,
    background = BgBase,
    onBackground = TextPrimary,
    surface = BgSurface,
    onSurface = TextPrimary,
    surfaceVariant = BgSurface2,
    onSurfaceVariant = TextSecondary,
    outline = BorderColor,
    outlineVariant = BorderColor,
    error = LiveRed,
    onError = BgBase,
)

@Composable
fun RadiolaTheme(
    content: @Composable () -> Unit
) {
    // Приложение всегда в тёмной фирменной теме.
    CompositionLocalProvider(LocalRadiolaColors provides RadiolaColors()) {
        MaterialTheme(
            colorScheme = DarkColorScheme,
            typography = Typography,
            shapes = RadiolaShapes,
            content = content
        )
    }
}
