package llc.arma.ble.app.ui.theme

import android.app.Activity
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat
import llc.arma.nfc.app.ui.theme.Typography
import llc.arma.nfc.app.ui.theme.shapes

val LightColorScheme = lightColorScheme(
    primary = Color(0xFF1B1B1F),
    onPrimary = Color(0xFFFFFFFF),
    primaryContainer = Color(0xFF2D2C27),
    onPrimaryContainer = Color(0xFFFFFFFF),
    secondary = Color(0xFF555555),
    onSecondary = Color(0xFFFFFFFF),
    secondaryContainer = Color(0xFFDFDFDF),
    onSecondaryContainer = Color(0xFF1B1B1F),
    tertiary = Color(0xFFFFE418),
    onTertiary = Color(0xFF1B1B1F),
    tertiaryContainer = Color(0xFFFFF396),
    onTertiaryContainer = Color(0xFF1B1B1F),
    error = Color(0xFFBA1A1A),
    onError = Color(0xFFFFFFFF),
    errorContainer = Color(0xFFFFDAD6),
    onErrorContainer = Color(0xFF410002),
    background = Color(0xFFFFFFFF),
    onBackground = Color(0xFF212121),
    surface = Color(0xFFFFFFFF),
    onSurface = Color(0xFF1D1C16),
    surfaceVariant = Color(0xFFF1F1F1),
    onSurfaceVariant = Color(0xFF212121),
    outline = Color(0xFFACACAC),
    inverseSurface = Color(0xFF32302A),
    inverseOnSurface = Color(0xFFF5F0E7),
    inversePrimary = Color(0xFFDFC700),
    surfaceTint = Color(0xFF755B00),
)


@Composable
fun BleTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit
) {

    val view = LocalView.current
    if (!view.isInEditMode) {

        val currentWindow = (view.context as? Activity)?.window
            ?: throw Exception("Not in an activity - unable to get Window reference")

        SideEffect {
            currentWindow.statusBarColor = LightColorScheme.primary.copy(alpha = 0f).toArgb()
            WindowCompat.getInsetsController(currentWindow, view).isAppearanceLightStatusBars = true
        }
    }

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