package com.pixelized.biblib.ui.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import com.pixelized.biblib.ui.composable.SystemTheme
import com.pixelized.biblib.ui.theme.color.bibLibDarkColors
import com.pixelized.biblib.ui.theme.color.bibLibLightColors
import com.pixelized.biblib.ui.theme.dimen.BibLibDimen
import com.pixelized.biblib.ui.theme.shape.BibLibShape
import com.pixelized.biblib.ui.theme.typography.BibLibTypography
import com.pixelized.biblib.utils.extention.bibLib

@Composable
fun BibLibTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit
) {
    val theme = BibLibTheme(
        colors = if (darkTheme) bibLibDarkColors() else bibLibLightColors(),
        dimen = BibLibDimen(),
        typography = BibLibTypography(),
        shapes = BibLibShape(),
    )
    CompositionLocalProvider(LocalBibLibTheme provides theme) {
        MaterialTheme(
            colors = theme.colors.base,
            typography = theme.typography.base,
            shapes = theme.shapes.base,
            content = {
                SystemTheme(
                    statusBackground = MaterialTheme.bibLib.colors.system.status,
                    statusDarkIcons = darkTheme.not(),
                    navigationBackground = MaterialTheme.bibLib.colors.system.navigation,
                    navigationDarkIcons = darkTheme.not(),
                    content = content,
                )
            }
        )
    }
}