package com.onthelevel.core.design

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Typography
import androidx.compose.material3.darkColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp

/**
 * Palette from the concept board (resources/Bubble Level Concepts.dc.html):
 * deep graphite glass, warm amber guidance, fluorescent spirit fluid, and lime
 * for the locked state.
 * The design is dark-only in v1 — this is an instrument, not a document.
 * Per BRIEF.md, color never carries state alone; labels and numbers always accompany it.
 */
object LevelColors {
    val Graphite = Color(0xFF0A0A0B)
    val GraphiteRaised = Color(0xFF15181D)
    val PanelStroke = Color(0x12FFFFFF)
    val Panel = Color(0x0AFFFFFF)

    val Amber = Color(0xFFFFC44E)
    val AmberHighlight = Color(0xFFFFEEB0)
    val AmberDeep = Color(0xFFE0961E)

    // Fluorescent yellow-green is both familiar from physical spirit levels and
    // substantially more legible than amber against the graphite vial.
    val VialLime = Color(0xFFD9FF38)
    val VialHighlight = Color(0xFFF7FFD5)
    val VialDeep = Color(0xFF86B800)
    val VialTarget = Color(0xFFFF6868)

    /** Stronger neutral surface reserved for live numeric instrument panels. */
    val ReadoutPanel = Color(0xFF242931)

    val LimeLock = Color(0xFFCBEF5C)
    val LimeLockText = Color(0xFFEAFFC2)

    val Cream = Color(0xFFEDEBE6)
    val TextPrimary = Color(0xFFF5F4F1)
    val TextDim = Color(0x6BFFFFFF)
    val TextFaint = Color(0x55FFFFFF)
}

private val DarkScheme = darkColorScheme(
    primary = LevelColors.Amber,
    onPrimary = LevelColors.Graphite,
    secondary = LevelColors.LimeLock,
    onSecondary = LevelColors.Graphite,
    background = LevelColors.Graphite,
    onBackground = LevelColors.TextPrimary,
    surface = LevelColors.GraphiteRaised,
    onSurface = LevelColors.TextPrimary,
    surfaceVariant = LevelColors.GraphiteRaised,
    onSurfaceVariant = LevelColors.TextDim,
    outline = LevelColors.PanelStroke,
)

// TODO(design): bundle Space Grotesk + IBM Plex Mono per the concept board.
// Until then: system sans for labels, platform monospace for all numeric readouts
// so digits don't jitter horizontally as values change.
val ReadoutFontFamily = FontFamily.Monospace

private val LevelTypography = Typography(
    displayLarge = TextStyle(
        fontFamily = ReadoutFontFamily,
        fontWeight = FontWeight.Light,
        fontSize = 96.sp,
        letterSpacing = (-2).sp,
    ),
    headlineMedium = TextStyle(
        fontFamily = ReadoutFontFamily,
        fontWeight = FontWeight.Normal,
        fontSize = 28.sp,
    ),
    labelSmall = TextStyle(
        fontWeight = FontWeight.SemiBold,
        fontSize = 11.sp,
        letterSpacing = 2.sp,
    ),
)

@Composable
fun OnTheLevelTheme(content: @Composable () -> Unit) {
    // Dark-only by design; isSystemInDarkTheme() intentionally unused in v1.
    MaterialTheme(
        colorScheme = DarkScheme,
        typography = LevelTypography,
        content = content,
    )
}
