/*
 * Copyright (c) 2026 QPQ IaaS AG <info@qpq.swiss>. All rights reserved.
 * Project: Gajumaru Core Java Libraries <gajumaru.io>
 *
 * This program is dual-licensed:
 * 1) Under the GNU Affero General Public License as published by the Free
 *    Software Foundation, either version 3 of the License, or (at your option)
 *    any later version (AGPL-3.0-or-later).
 *
 * 2) Under a commercial/proprietary license available directly from QPQ IaaS AG.
 *    If you wish to use this software outside the strict constraints of the
 *    AGPLv3 (e.g. within a closed-source or proprietary product), you must
 *    purchase a commercial license from QPQ IaaS AG.
 *
 * Authors:
 *   - Craig Everett <craigeverett@qpq.swiss>
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-QPQ-Commercial
 */

package swiss.qpq.gajumobile.ui.theme

import android.app.Activity
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat

private val ArborealDarkColorScheme = darkColorScheme(
    primary = GajuDarkPrimary,
    secondary = GajuDarkSecondary,
    tertiary = GajuDarkTertiary,
    background = GajuDarkBackground,
    surface = GajuDarkSurface,
    surfaceVariant = GajuDarkSurfaceVariant,
    onPrimary = GajuDarkOnPrimary,
    onSecondary = GajuDarkOnSecondary,
    onTertiary = GajuDarkOnTertiary,
    onBackground = GajuDarkOnBackground,
    onSurface = GajuDarkOnSurface,
    onSurfaceVariant = GajuDarkOnSurfaceVariant,
)

private val ArborealLightColorScheme = lightColorScheme(
    primary = GajuLightPrimary,
    secondary = GajuLightSecondary,
    tertiary = GajuLightTertiary,
    background = GajuLightBackground,
    surface = GajuLightSurface,
    surfaceVariant = GajuLightSurfaceVariant,
    onPrimary = GajuLightOnPrimary,
    onSecondary = GajuLightOnSecondary,
    onTertiary = GajuLightOnTertiary,
    onBackground = GajuLightOnBackground,
    onSurface = GajuLightOnSurface,
    onSurfaceVariant = GajuLightOnSurfaceVariant,
)

@Composable
fun MyApplicationTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit
) {
    val colorScheme = if (darkTheme) ArborealDarkColorScheme else ArborealLightColorScheme

    val view = LocalView.current
    if (!view.isInEditMode) {
        SideEffect {
            val window = (view.context as Activity).window
            WindowCompat.getInsetsController(window, view).apply {
                isAppearanceLightStatusBars = !darkTheme
            }
        }
    }

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