package app.closer.ui.components

import app.closer.ui.theme.CloserPalette
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight

@Composable
fun ErrorState(
    title: String = "Didn't quite load",
    message: String,
    retryLabel: String = "Try again",
    onRetry: (() -> Unit)? = null,
    modifier: Modifier = Modifier
) {
    CloserCard(
        modifier = modifier.fillMaxWidth(),
        containerColor = CloserPalette.PinkMist
    ) {
        Column(
            modifier = Modifier.padding(CloserSpacing.Xxl),
            verticalArrangement = Arrangement.spacedBy(CloserSpacing.Md)
        ) {
            Text(
                text = title,
                style = MaterialTheme.typography.titleMedium,
                fontWeight = FontWeight.SemiBold,
                color = CloserPalette.Danger
            )
            Text(
                text = message,
                style = MaterialTheme.typography.bodyMedium,
                color = MaterialTheme.colorScheme.onSurfaceVariant
            )
            if (onRetry != null) {
                CloserActionButton(
                    label = retryLabel,
                    onClick = onRetry,
                    modifier = Modifier.fillMaxWidth(),
                    style = CloserButtonStyle.Destructive
                )
            }
        }
    }
}
