// Copyright (C) 2026 Jason M. Schwefel. All Rights Reserved.
package com.coldboreballisticsllc.scopedope.ui.crash

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import com.coldboreballisticsllc.scopedope.ui.theme.ColorAmber
import com.coldboreballisticsllc.scopedope.ui.theme.ColorBackground
import com.coldboreballisticsllc.scopedope.ui.theme.ColorTextMuted
import com.coldboreballisticsllc.scopedope.ui.theme.ColorTextPrimary

/**
 * One-time first-run crash-reporting consent prompt (SPEC §16.1).
 *
 * Opt-in: the safe/default action is to decline ("Not now"). Copy states plainly that
 * declining changes nothing about how the app works. Whichever way the user chooses,
 * the prompt is marked shown and never appears again (the choice remains changeable in
 * Settings → Privacy).
 *
 * @param onAllow  user opted in
 * @param onDecline user declined (or dismissed) — reporting stays OFF
 */
@Composable
fun CrashConsentDialog(
    onAllow: () -> Unit,
    onDecline: () -> Unit,
) {
    AlertDialog(
        onDismissRequest = onDecline, // dismissing = declining; default is OFF
        title = {
            Text("Help improve ScopeDOPE?", color = ColorTextPrimary)
        },
        text = {
            Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
                Text(
                    "ScopeDOPE can send anonymous crash diagnostics to help us find and fix " +
                        "bugs. No personal information, location, or any of your ammunition, " +
                        "rifle, or DOPE data is ever sent.",
                    color = ColorTextMuted,
                )
                Text(
                    "Declining changes nothing about how the app works. You can turn this on " +
                        "or off any time in Settings → Privacy.",
                    color = ColorTextMuted,
                )
            }
        },
        confirmButton = {
            TextButton(onClick = onAllow) {
                Text("Allow", color = ColorAmber)
            }
        },
        dismissButton = {
            TextButton(onClick = onDecline) {
                Text("Not now", color = ColorTextMuted)
            }
        },
        containerColor = ColorBackground,
    )
}
