package app.closer.ui.theme

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

object CloserPalette {
    val BackgroundWash = Color(0xFFF8F1FF)
    val PurpleDeep = Color(0xFF56306F)
    val PurpleRich = Color(0xFF8F67C5)
    val PurpleSoft = Color(0xFFF4E8FF)
    val PurpleMist = Color(0xFFF0EDF9)
    val PurpleGlow = Color(0xFFF0DFFF)
    val PinkSoft = Color(0xFFFFE8F4)
    val PinkMist = Color(0xFFFFEEF7)
    val PinkBright = Color(0xFFE7A2D1)
    val PinkWheel = Color(0xFFFFC2DD)
    val PinkShell = Color(0xFFF7C8E4)
    val PinkAccentDeep = Color(0xFF6D2B55)
    val Romantic = Color(0xFF9B1B5A)
    val Gold = Color(0xFF6A4A00)
    val Evergreen = Color(0xFF2F5B4F)
    val Danger = Color(0xFF8D2D35)
}

@Composable
fun closerBackgroundBrush(): Brush =
    if (isCloserDarkTheme()) {
        Brush.linearGradient(
            colors = listOf(
                MaterialTheme.colorScheme.background,
                MaterialTheme.colorScheme.surface,
                MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.72f)
            ),
            start = Offset.Zero,
            end = Offset.Infinite
        )
    } else {
        Brush.linearGradient(
            colors = listOf(
                MaterialTheme.colorScheme.background,
                MaterialTheme.colorScheme.surfaceVariant,
                MaterialTheme.colorScheme.secondaryContainer
            ),
            start = Offset.Zero,
            end = Offset.Infinite
        )
    }

@Composable
fun closerInkColor(): Color = MaterialTheme.colorScheme.onSurface

@Composable
fun closerMutedColor(): Color = MaterialTheme.colorScheme.onSurfaceVariant

@Composable
fun closerActionTextColor(): Color = MaterialTheme.colorScheme.onPrimary

@Composable
fun closerCardColor(alpha: Float = 0.9f): Color =
    MaterialTheme.colorScheme.surface.copy(alpha = alpha)

@Composable
fun closerQuietCardColor(): Color = closerCardColor(alpha = 0.82f)

@Composable
fun closerElevatedCardColor(): Color = closerCardColor(alpha = 0.92f)

@Composable
fun closerSolidCardColor(): Color = MaterialTheme.colorScheme.surface

@Composable
fun closerSoftSurfaceColor(alpha: Float = 0.92f): Color =
    if (isCloserDarkTheme()) {
        MaterialTheme.colorScheme.surfaceVariant.copy(alpha = alpha)
    } else {
        Color.White.copy(alpha = alpha)
    }

@Composable
fun closerSoftPurpleColor(alpha: Float = 1f): Color =
    if (isCloserDarkTheme()) {
        MaterialTheme.colorScheme.primaryContainer.copy(alpha = alpha)
    } else {
        CloserPalette.PurpleMist.copy(alpha = alpha)
    }

@Composable
fun closerSoftPinkColor(alpha: Float = 1f): Color =
    if (isCloserDarkTheme()) {
        MaterialTheme.colorScheme.secondaryContainer.copy(alpha = alpha)
    } else {
        CloserPalette.PinkMist.copy(alpha = alpha)
    }

@Composable
fun closerScrimColor(alpha: Float = 0.54f): Color =
    MaterialTheme.colorScheme.onSurface.copy(alpha = alpha)

@Composable
fun closerPlayCardBrush(): Brush =
    Brush.linearGradient(
        colors = if (isCloserDarkTheme()) {
            listOf(
                MaterialTheme.colorScheme.surface,
                MaterialTheme.colorScheme.surfaceVariant,
                MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.78f)
            )
        } else {
            listOf(
                MaterialTheme.colorScheme.surface,
                MaterialTheme.colorScheme.primaryContainer,
                MaterialTheme.colorScheme.secondaryContainer
            )
        },
        start = Offset.Zero,
        end = Offset.Infinite
    )

@Composable
fun closerBrandGlyphBrush(): Brush =
    Brush.linearGradient(
        colors = listOf(
            MaterialTheme.colorScheme.primary,
            MaterialTheme.colorScheme.secondary,
            if (isCloserDarkTheme()) MaterialTheme.colorScheme.tertiary else CloserPalette.PurpleDeep
        ),
        start = Offset.Zero,
        end = Offset.Infinite
    )

@Composable
fun closerWheelSegmentColors(): List<Color> =
    if (isCloserDarkTheme()) {
        listOf(
            MaterialTheme.colorScheme.primary,
            MaterialTheme.colorScheme.secondary,
            MaterialTheme.colorScheme.tertiary,
            MaterialTheme.colorScheme.primaryContainer,
            MaterialTheme.colorScheme.secondaryContainer,
            MaterialTheme.colorScheme.tertiaryContainer,
            MaterialTheme.colorScheme.surfaceVariant,
            MaterialTheme.colorScheme.outline
        )
    } else {
        listOf(
            MaterialTheme.colorScheme.primary,
            CloserPalette.PinkWheel,
            MaterialTheme.colorScheme.secondary,
            CloserPalette.PurpleGlow,
            CloserPalette.PurpleRich,
            MaterialTheme.colorScheme.secondaryContainer,
            CloserPalette.PurpleDeep,
            CloserPalette.PinkShell
        )
    }

@Composable
fun isCloserDarkTheme(): Boolean = MaterialTheme.colorScheme.background.luminance() < 0.5f
