package lu.rewardflow.terminal.ui.theme

import android.app.Activity
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat

// RewardFlow brand colors
private val Purple600 = Color(0xFF7C3AED)
private val Purple700 = Color(0xFF6D28D9)
private val Purple50 = Color(0xFFF5F3FF)

private val LightColorScheme = lightColorScheme(
    primary = Purple600,
    onPrimary = Color.White,
    primaryContainer = Purple50,
    onPrimaryContainer = Purple700,
    secondary = Color(0xFF10B981),
    background = Color(0xFFF9FAFB),
    surface = Color.White,
    error = Color(0xFFEF4444),
)

private val DarkColorScheme = darkColorScheme(
    primary = Color(0xFFA78BFA),
    onPrimary = Color(0xFF1E1B4B),
    primaryContainer = Color(0xFF312E81),
    onPrimaryContainer = Color(0xFFE0E7FF),
    secondary = Color(0xFF34D399),
    background = Color(0xFF111827),
    surface = Color(0xFF1F2937),
    error = Color(0xFFF87171),
)

@Composable
fun RewardFlowTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit,
) {
    val colorScheme = if (darkTheme) DarkColorScheme else LightColorScheme

    // Status-bar color is handled by enableEdgeToEdge() in MainActivity
    // (Window.statusBarColor is deprecated since API 35). We only need to
    // set the icon tint for the brief moments the bars are revealed via
    // swipe (immersive mode keeps them hidden the rest of the time).
    val view = LocalView.current
    if (!view.isInEditMode) {
        SideEffect {
            val window = (view.context as Activity).window
            WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
        }
    }

    MaterialTheme(
        colorScheme = colorScheme,
        content = content,
    )
}
