'use client';
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useState } from 'react';
import { Trash2 } from 'lucide-react';
import { useRouter } from 'next/navigation';
import { toast } from 'sonner';
import { Button } from '../../ui/button.js';
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '../../ui/dialog.js';
import { deleteApplication } from '../../../app/actions/delete-application.js';
export function DeleteButton({ applicationId, applicationName }) {
    const router = useRouter();
    const [confirmOpen, setConfirmOpen] = useState(false);
    return (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", size: "icon", onClick: () => setConfirmOpen(true), className: "text-muted-foreground hover:bg-destructive/10 hover:text-destructive h-7 w-7 cursor-pointer transition-colors", "aria-label": "Delete application", title: "Delete application", children: _jsx(Trash2, { className: "h-3.5 w-3.5" }) }), _jsx(Dialog, { open: confirmOpen, onOpenChange: setConfirmOpen, children: _jsxs(DialogContent, { className: "max-w-xs", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: "Delete application?" }), _jsxs(DialogDescription, { children: ["This will permanently remove ", _jsx("strong", { children: applicationName }), "."] })] }), _jsxs(DialogFooter, { className: "grid grid-cols-2 gap-2 sm:flex-none", children: [_jsx(DialogClose, { asChild: true, children: _jsx(Button, { variant: "outline", children: "Cancel" }) }), _jsx(Button, { variant: "destructive", onClick: async () => {
                                        setConfirmOpen(false);
                                        const result = await deleteApplication(applicationId);
                                        if (result.error) {
                                            toast.error('Failed to delete', { description: result.error });
                                        }
                                        else {
                                            toast.success('Application deleted');
                                            router.push('/applications');
                                        }
                                    }, children: "Delete" })] })] }) })] }));
}
