/**
 * Overwrite confirmation dialog for autofill.
 *
 * Shows a list of fields that have existing values which would be replaced
 * by the autofill extraction, and asks the user to confirm or cancel.
 */
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Dialog, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, } from '../shared/dialog/index.js';
function format_value(value) {
    if (value === null || value === undefined || value === '')
        return '(empty)';
    if (typeof value === 'boolean')
        return value ? 'Yes' : 'No';
    if (Array.isArray(value))
        return `${value.length} row(s)`;
    if (typeof value === 'string' && value.length > 60)
        return value.slice(0, 60) + '...';
    return String(value);
}
export function OverwriteConfirmDialog({ open, on_open_change, conflicts, on_confirm, on_cancel, }) {
    return (_jsx(Dialog, { open: open, onOpenChange: on_open_change, children: _jsxs(DialogContent, { className: "sm:max-w-[480px]", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: "Overwrite existing values?" }), _jsxs(DialogDescription, { children: ["Autofill wants to replace ", conflicts.length, " field", conflicts.length !== 1 ? 's' : '', " that already have values."] })] }), _jsx("div", { className: "max-h-[300px] overflow-y-auto space-y-2 py-2", children: conflicts.map((conflict) => (_jsxs("div", { className: "text-sm border rounded-md p-2 space-y-1", children: [_jsx("div", { className: "font-medium", children: conflict.label }), _jsxs("div", { className: "grid grid-cols-[auto_1fr] gap-x-2 text-muted-foreground", children: [_jsx("span", { children: "Current:" }), _jsx("span", { className: "truncate", children: format_value(conflict.current_value) }), _jsx("span", { children: "New:" }), _jsx("span", { className: "truncate text-foreground", children: format_value(conflict.new_value) })] })] }, conflict.field_id))) }), _jsxs(DialogFooter, { className: "gap-2 sm:gap-0", children: [_jsx("button", { type: "button", onClick: on_cancel, className: "inline-flex items-center justify-center rounded-md text-sm font-medium h-9 px-4 border border-input bg-background hover:bg-accent hover:text-accent-foreground", children: "Cancel" }), _jsx("button", { type: "button", onClick: on_confirm, className: "inline-flex items-center justify-center rounded-md text-sm font-medium h-9 px-4 bg-primary text-primary-foreground hover:bg-primary/90", children: "Overwrite" })] })] }) }));
}
//# sourceMappingURL=overwrite_confirm_dialog.js.map