package dev.ulfrx.recipe.ui.theme

import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.lerp

data object RecipeGlass {
    /** Strong refraction tuned for thin chrome elements (dock, pills, search bar). */
    val menu: RecipeGlassStyle =
        RecipeGlassStyle(
            refraction = 0.10f,
            curve = 0.5f,
            edge = 0.04f,
            dispersion = 0.05f,
            saturation = 0.5f,
            contrast = 1.3f,
            frost = 15.dp,
        )

    val dockPress: RecipeGlassStyle =
        RecipeGlassStyle(
            refraction = 0.05f,
            curve = 0.25f,
            edge = 0.04f,
            dispersion = 0.0f,
            saturation = 1.0f,
            contrast = 1.0f,
            frost = 0.dp,
        )

    /** Calm refraction with strong frost — for large surfaces where [menu] would read as a murky lens. */
    val panel: RecipeGlassStyle =
        RecipeGlassStyle(
            refraction = 0.10f,
            curve = 0.3f,
            edge = 0.01f,
            dispersion = 0.03f,
            saturation = 0.5f,
            contrast = 1.5f,
            frost = 28.dp,
        )

    val heroBand: RecipeGlassStyle =
        RecipeGlassStyle(
            refraction = 0.05f,
            curve = 0.20f,
            edge = 0f,
            dispersion = 0.03f,
            saturation = 0.5f,
            contrast = 1.5f,
            frost = 5.dp,
        )

    val chipOnGlass: RecipeGlassStyle =
        RecipeGlassStyle(
            refraction = 0f,
            curve = 0f,
            edge = 0.1f,
            dispersion = 0.03f,
            saturation = 0.5f,
            contrast = 1.5f,
            frost = 5.dp,
        )
}

data class RecipeGlassStyle(
    val refraction: Float,
    val curve: Float,
    val edge: Float,
    val dispersion: Float,
    val saturation: Float,
    val contrast: Float,
    val frost: Dp,
)

fun lerp(
    start: RecipeGlassStyle,
    stop: RecipeGlassStyle,
    fraction: Float,
): RecipeGlassStyle =
    RecipeGlassStyle(
        refraction = lerp(start.refraction, stop.refraction, fraction),
        curve = lerp(start.curve, stop.curve, fraction),
        edge = lerp(start.edge, stop.edge, fraction),
        dispersion = lerp(start.dispersion, stop.dispersion, fraction),
        saturation = lerp(start.saturation, stop.saturation, fraction),
        contrast = lerp(start.contrast, stop.contrast, fraction),
        frost = lerp(start.frost.value, stop.frost.value, fraction).dp,
    )
