package dev.ulfrx.recipe.ui.components.empty

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.composeunstyled.UnstyledIcon
import dev.ulfrx.recipe.ui.theme.RecipeTheme

/**
 * Reusable empty-state composable per CONTEXT D-13 / UI-SPEC line 183.
 *
 * Visual contract:
 *  - Centered Column on the screen.
 *  - 48dp icon tinted [RecipeTheme.colors.contentMuted] (calm, low-saturation per D-10).
 *  - 8dp gap (`sm`) between icon and headline.
 *  - Headline in [RecipeTheme.typography.display] color [RecipeTheme.colors.content].
 *  - 16dp gap (`lg`) between headline and subline.
 *  - Subline in [RecipeTheme.typography.body] color [RecipeTheme.colors.contentMuted].
 *  - Optional [action] slot below subline at 24dp gap (`xl`); unused this phase
 *    (D-12 — no CTAs in empty states), but the slot is reserved per D-13.
 *
 * Accessibility: column carries `Modifier.semantics(mergeDescendants = true)` so
 * VoiceOver reads headline + subline as one announcement (UI-SPEC line 226).
 */
@Composable
fun EmptyState(
    icon: ImageVector,
    title: String,
    subtitle: String,
    modifier: Modifier = Modifier,
    action: (@Composable () -> Unit)? = null,
) {
    Column(
        modifier =
            modifier
                .fillMaxSize()
                .padding(horizontal = RecipeTheme.spacing.xl)
                .semantics(mergeDescendants = true) {},
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center,
    ) {
        UnstyledIcon(
            imageVector = icon,
            contentDescription = null,
            tint = RecipeTheme.colors.contentMuted,
            modifier = Modifier.size(48.dp),
        )
        Spacer(Modifier.height(RecipeTheme.spacing.sm))
        BasicText(
            text = title,
            style =
                RecipeTheme.typography.display.copy(
                    color = RecipeTheme.colors.content,
                    textAlign = TextAlign.Center,
                ),
        )
        Spacer(Modifier.height(RecipeTheme.spacing.lg))
        BasicText(
            text = subtitle,
            style =
                RecipeTheme.typography.body.copy(
                    color = RecipeTheme.colors.contentMuted,
                    textAlign = TextAlign.Center,
                ),
        )
        if (action != null) {
            Spacer(Modifier.height(RecipeTheme.spacing.xl))
            action()
        }
    }
}
