package ru.fincode.tsudesk.core.ui.components

import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
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.LocalContext

@Composable
fun ConfigureSystemBars(
    statusBarColor: Color,
    navigationBarColor: Color = statusBarColor,
    darkIcons: Boolean = false, // false = светлые иконки
) {
    val context = LocalContext.current
    val status = statusBarColor.toArgb()
    val nav = navigationBarColor.toArgb()

    SideEffect {
        val activity = context as? ComponentActivity ?: return@SideEffect

        activity.enableEdgeToEdge(
            statusBarStyle = if (darkIcons) {
                SystemBarStyle.light(status, status)
            } else {
                SystemBarStyle.dark(status)
            },
            navigationBarStyle = SystemBarStyle.auto(
                lightScrim = nav,
                darkScrim = nav,
                detectDarkMode = { darkIcons }
            )
        )
    }
}