package id.ac.ubharajaya.panicbutton.ui.theme

import android.app.Activity
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat

private val DarkColorScheme = darkColorScheme(
    primary = Blue_secondary,
    secondary = Blue_primary,
    background = Grey_dark,
    surface = Color(0xFF1E1E1E),
    onPrimary = Grey_dark,
    onSecondary = Grey_dark,
    onBackground = Grey_light,
    onSurface = Grey_light,
    error = Red_cancel
)

private val LightColorScheme = lightColorScheme(
    primary = Blue_primary,
    secondary = Blue_secondary,
    tertiary = Dark_blue,
    background = Grey_light,
    surface = Color.White,
    onPrimary = Color.White,
    onSecondary = Color.White,
    onBackground = Grey_dark,
    onSurface = Grey_dark,
    error = Red_cancel
)

@Composable
fun PanicButtonTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    dynamicColor: Boolean = false, // Disable dynamic color
    content: @Composable () -> Unit
) {
    val colorScheme = if (darkTheme) DarkColorScheme else LightColorScheme
    val view = LocalView.current
    if (!view.isInEditMode) {
        val window = (view.context as Activity).window
        window.statusBarColor = colorScheme.primary.toArgb()
        WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
    }

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