package eu.friedcutlet.yokan.ui.theme import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import eu.friedcutlet.yokan.database.DbSettings import eu.friedcutlet.yokan.services.system.isTvDevice import eu.friedcutlet.yokan.ui.tv.resolveTvUiScale /** [YokanTheme] as configured in [db]; [themeIsDark] is the user's dark-mode choice when not following the system. */ @Composable fun YokanThemeFromSettings(db: DbSettings, themeIsDark: Boolean, content: @Composable () -> Unit) { val systemDark = rememberSystemDark() // E-ink display mode is always black on white. val appDark = !db.einkMode && resolveDarkMode( followSystem = db.followSystemTheme, themeIsDark = themeIsDark, systemDark = systemDark, ) // Android: system bar icon contrast must follow the in-app theme, which // can diverge from the system dark mode (followSystemTheme = false). LaunchedEffect(appDark) { applySystemBarTheme(appDark) } YokanTheme( darkTheme = appDark, schemeIndex = db.flexSchemeColorIndex, pureBlackDark = db.pureBlackDarkMode, blendLevel = (db.flexColorSchemeBlendLevel / 100.0).toFloat().coerceIn(0f, 1f), uiScale = resolveTvUiScale(isTvDevice(), db), seedColorArgb = db.themeSeedColor, seedImagePath = db.themeSeedImagePath, materialYou = db.materialYou, materialExpressive = db.materialExpressive, paletteStyleName = db.themePaletteStyle, fontFamily = resolveAppFontFamily(db.appFontFamily), eink = db.einkMode, content = content, ) }