'use client';
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useEffect, useState } from 'react';
import { Loader2 } from 'lucide-react';
import { Trans, useTranslation } from 'react-i18next';
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '../../ui/alert-dialog.js';
import { Checkbox } from '../../ui/checkbox.js';
import { Label } from '../../ui/label.js';
export function DeleteFeatureDialog({ open, onOpenChange, onConfirm, isDeleting, featureName, featureId, hasChildren, hasOpenPr, }) {
    const { t } = useTranslation('web');
    const [cleanup, setCleanup] = useState(true);
    const [cascadeDelete, setCascadeDelete] = useState(false);
    const [closePr, setClosePr] = useState(true);
    useEffect(() => {
        if (open) {
            setCleanup(true);
            setCascadeDelete(false);
            setClosePr(true);
        }
    }, [open]);
    useEffect(() => {
        if (cleanup) {
            setClosePr(true);
        }
        else {
            setClosePr(false);
        }
    }, [cleanup]);
    return (_jsx(AlertDialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(AlertDialogContent, { onCloseAutoFocus: (e) => e.preventDefault(), children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: t('deleteFeature.title') }), _jsx(AlertDialogDescription, { children: _jsx(Trans, { t: t, i18nKey: "deleteFeature.description", values: { featureName, featureId }, components: { strong: _jsx("strong", {}) } }) })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Checkbox, { id: "cleanup-checkbox", checked: cleanup, onCheckedChange: (checked) => setCleanup(checked === true), disabled: isDeleting, "aria-label": t('deleteFeature.cleanupLabel') }), _jsx(Label, { htmlFor: "cleanup-checkbox", className: "cursor-pointer text-sm", children: t('deleteFeature.cleanupLabel') })] }), hasChildren ? (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Checkbox, { id: "cascade-delete-checkbox", checked: cascadeDelete, onCheckedChange: (checked) => setCascadeDelete(checked === true), disabled: isDeleting, "aria-label": t('deleteFeature.deleteSubFeatures') }), _jsx(Label, { htmlFor: "cascade-delete-checkbox", className: "cursor-pointer text-sm", children: t('deleteFeature.deleteSubFeatures') })] })) : null, hasOpenPr ? (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Checkbox, { id: "close-pr-checkbox", checked: closePr, onCheckedChange: (checked) => setClosePr(checked === true), disabled: isDeleting || !cleanup, "aria-label": t('deleteFeature.closePullRequest') }), _jsx(Label, { htmlFor: "close-pr-checkbox", className: "cursor-pointer text-sm", children: t('deleteFeature.closePullRequest') })] })) : null] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { disabled: isDeleting, onClick: () => onOpenChange(false), children: t('deleteFeature.cancel') }), _jsx(AlertDialogAction, { variant: "destructive", disabled: isDeleting, onClick: () => onConfirm(cleanup, cascadeDelete, hasOpenPr ? closePr : false), children: isDeleting ? (_jsxs(_Fragment, { children: [_jsx(Loader2, { className: "me-2 h-4 w-4 animate-spin" }), t('deleteFeature.deleting')] })) : (t('deleteFeature.delete')) })] })] }) }));
}
