package com.aiosman.riderpro

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.areNavigationBarsVisible
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.systemBars
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.google.accompanist.systemuicontroller.rememberSystemUiController

@Composable
fun StatusBarMask(darkIcons: Boolean = true) {
    val paddingValues = WindowInsets.systemBars.asPaddingValues()
    val systemUiController = rememberSystemUiController()
    LaunchedEffect(Unit) {
        systemUiController.setStatusBarColor(Color.Transparent, darkIcons = darkIcons)

    }
    Spacer(modifier = Modifier.height(paddingValues.calculateTopPadding()))

}

@Composable
fun StatusBarMaskLayout(
    modifier: Modifier = Modifier,
    darkIcons: Boolean = true,
    maskBoxBackgroundColor: Color = Color.Transparent,
    content: @Composable ColumnScope.() -> Unit
) {
    val paddingValues = WindowInsets.systemBars.asPaddingValues()
    val systemUiController = rememberSystemUiController()
    val navigationBarPaddings =
        WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
    LaunchedEffect(Unit) {
        systemUiController.setStatusBarColor(Color.Transparent, darkIcons = darkIcons)
    }
    Column(
        modifier = modifier.fillMaxSize()
    ) {
        Box(
            modifier = Modifier
                .height(paddingValues.calculateTopPadding())
                .fillMaxWidth()
                .background(maskBoxBackgroundColor)
        ) {

        }
        content()
        if (navigationBarPaddings > 24.dp) {
            Box(
                modifier = Modifier
                    .height(navigationBarPaddings).fillMaxWidth().background(Color.White)
            )
        }
    }
}