package com.anypreta.bountyboard.ui.theme

import androidx.compose.foundation.layout.offset
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

/**
 * The Y2K signature: a hard offset shadow with NO blur, drawn behind the element.
 * Replaces Material's soft elevation. Mirrors the web's `--ink-shadow: 3px 3px 0`.
 */
fun Modifier.hardShadow(
    palette: BBPalette,
    offset: Dp = 3.dp,
    cornerRadius: Dp = 2.dp,
): Modifier = this.drawBehind {
    val o = offset.toPx()
    val r = cornerRadius.toPx()
    val shadowColor = if (palette.isDark) {
        Color.Black.copy(alpha = 0.55f)
    } else {
        palette.border.copy(alpha = 0.45f)
    }
    drawRoundRect(
        color = shadowColor,
        topLeft = Offset(o, o),
        size = Size(size.width, size.height),
        cornerRadius = androidx.compose.ui.geometry.CornerRadius(r, r),
    )
}

/**
 * Pressed-button effect: translate content into the page and drop the shadow.
 * Use the [pressed] flag from an InteractionSource.
 */
fun Modifier.pressTranslate(pressed: Boolean, amount: Dp = 2.dp): Modifier =
    if (pressed) this.offset(amount, amount) else this
