package com.optix.android.ui.theme

import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.luminance

// ── Static fallback values (RED_DARK defaults) — used in non-composable contexts ──
val NeonBackground   = Color(0xFF000000)
val NeonSurface      = Color(0xFF0A0C0F)
val NeonSurfaceVar   = Color(0xFF111418)
val NeonBorder       = Color(0xFF1C2028)
val NeonRed          = Color(0xFFFF1744)
val NeonRedDim       = Color(0xFF4A0000)
val NeonRedGlow      = Color(0xFFFF5252)
val NeonRedDeep      = Color(0xFF1A0000)
val NeonOrange       = Color(0xFFFFAB40)
val NeonGreen        = Color(0xFF00E676)
val NeonPurple       = Color(0xFF7B1FA2)
val NeonOnSurface    = Color(0xFFE0E4EA)
val NeonOnSurfaceMid = Color(0xFF4A5568)
val NeonOnSurfaceDim = Color(0xFF1E2530)
val ColorNetwork     = Color(0xFFFF1744)
val ColorWeb         = Color(0xFFFFAB40)
val ColorExploit     = Color(0xFFFF1744)
val ColorUtility     = NeonPurple
val GlassWhite       = Color(0x08FFFFFF)
val GlassBorder      = Color(0x14FFFFFF)

// ── Theme-aware accessors ───────────────────────────────────────────────────────
// `T.*` now resolves primarily to `MaterialTheme` tokens so Compose previews render
// correctly (MaterialTheme provides a default scheme). Colors not present in the
// standard MaterialTheme (accent-driven extras) fall back to the custom
// `LocalAppTheme` composition local that `NeonTheme` still provides.
object T {
    // ── Standard MaterialTheme color tokens ──
    val background:      Color  @Composable @ReadOnlyComposable get() = MaterialTheme.colorScheme.background
    val surface:         Color  @Composable @ReadOnlyComposable get() = MaterialTheme.colorScheme.surface
    val surfaceVar:      Color  @Composable @ReadOnlyComposable get() = MaterialTheme.colorScheme.surfaceVariant
    val border:          Color  @Composable @ReadOnlyComposable get() = MaterialTheme.colorScheme.outline
    val accent:          Color  @Composable @ReadOnlyComposable get() = MaterialTheme.colorScheme.primary
    val accentDim:       Color  @Composable @ReadOnlyComposable get() = MaterialTheme.colorScheme.primaryContainer
    val onSurface:       Color  @Composable @ReadOnlyComposable get() = MaterialTheme.colorScheme.onSurface
    val onSurfaceMid:    Color  @Composable @ReadOnlyComposable get() = MaterialTheme.colorScheme.onSurfaceVariant
    val success:         Color  @Composable @ReadOnlyComposable get() = MaterialTheme.colorScheme.tertiary
    val warning:         Color  @Composable @ReadOnlyComposable get() = MaterialTheme.colorScheme.error

    // ── Extra (non-standard) tokens read from the custom LocalAppTheme ──
    val accentGlow:      Color  @Composable @ReadOnlyComposable get() = LocalAppTheme.current.accentGlow
    val textAccent:      Color  @Composable @ReadOnlyComposable get() = LocalAppTheme.current.textAccent
    val graphics:        Color  @Composable @ReadOnlyComposable get() = LocalAppTheme.current.graphicsColor
    val surfaceGradient: Brush  @Composable @ReadOnlyComposable get() = LocalAppTheme.current.surfaceGradient
    val exploit:         Color  @Composable @ReadOnlyComposable get() = LocalAppTheme.current.exploit
    val utility:         Color  @Composable @ReadOnlyComposable get() = LocalAppTheme.current.utility
    val nodeDefault:     Color  @Composable @ReadOnlyComposable get() = LocalAppTheme.current.nodeDefault
    val nodeGateway:     Color  @Composable @ReadOnlyComposable get() = LocalAppTheme.current.nodeGateway

    // Derived from the resolved background luminance.
    val isDark:          Boolean @Composable @ReadOnlyComposable
        get() = MaterialTheme.colorScheme.background.luminance() < 0.5f
}
