package com.tt.honeyDue.ui.components

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.graphics.Color
import com.tt.honeyDue.ui.haptics.Haptics

/**
 * Reusable error dialog component that shows network errors with retry/cancel options
 *
 * @param title Dialog title (default: "Network Error")
 * @param message Error message to display
 * @param onRetry Callback when user clicks Retry button
 * @param onDismiss Callback when user clicks Cancel or dismisses dialog
 * @param retryButtonText Text for retry button (default: "Try Again")
 * @param dismissButtonText Text for dismiss button (default: "Cancel")
 */
@Composable
fun ErrorDialog(
    title: String = "Network Error",
    message: String,
    onRetry: () -> Unit,
    onDismiss: () -> Unit,
    retryButtonText: String = "Try Again",
    dismissButtonText: String = "Cancel"
) {
    // P5 Stream S — error haptic when the dialog appears
    LaunchedEffect(message) { Haptics.error() }
    AlertDialog(
        onDismissRequest = onDismiss,
        title = {
            Text(
                text = title,
                style = MaterialTheme.typography.headlineSmall,
                color = MaterialTheme.colorScheme.error
            )
        },
        text = {
            Text(
                text = message,
                style = MaterialTheme.typography.bodyMedium
            )
        },
        confirmButton = {
            Button(
                onClick = {
                    Haptics.light() // P5 Stream S — primary-tap haptic on retry
                    onDismiss()
                    onRetry()
                },
                colors = ButtonDefaults.buttonColors(
                    containerColor = MaterialTheme.colorScheme.primary
                )
            ) {
                Text(retryButtonText)
            }
        },
        dismissButton = {
            TextButton(onClick = onDismiss) {
                Text(dismissButtonText)
            }
        }
    )
}
