import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useRef, useState } from "react";
import { Upload } from "lucide-react";
import { toast } from "sonner";
import { Dialog, DialogContent } from "../../components/ui/dialog";
import { Button } from "../../components/ui/button";
import { StyledDialogTitle } from "../../components/ui/styled-dialog-title";
import DialogButtons from "./DialogButtons";
export function ImportItemsDialog({ targetItem, onClose, }) {
    const textareaRef = useRef(null);
    const [restoreToOriginalParents, setRestoreToOriginalParents] = useState(false);
    const handlePasteFromClipboard = async () => {
        try {
            if (typeof navigator === "undefined" ||
                !navigator.clipboard ||
                typeof navigator.clipboard.readText !== "function") {
                toast.error("Reading from the clipboard is not supported in this browser. Please paste the YAML manually.");
                return;
            }
            const clipboardText = await navigator.clipboard.readText();
            if (textareaRef.current) {
                textareaRef.current.value = clipboardText;
            }
        }
        catch (error) {
            console.warn("Could not read from clipboard:", error);
            toast.error("Could not read from the clipboard. Please paste the YAML manually.");
        }
    };
    const handleAccept = () => {
        const yamlValue = textareaRef.current?.value?.trim();
        if (!yamlValue) {
            onClose(null);
            return;
        }
        onClose({ yaml: yamlValue, restoreToOriginalParents });
    };
    return (_jsx(Dialog, { open: true, onOpenChange: (open) => !open && onClose(null), children: _jsxs(DialogContent, { className: "flex max-w-2xl flex-col overflow-hidden border-none p-0 shadow-2xl", style: { maxHeight: "90vh" }, showCloseButton: true, "data-testid": "confirmation-dialog", children: [_jsx(StyledDialogTitle, { icon: _jsx(Upload, { strokeWidth: 1 }), title: "Import Items", subtitle: `Import items into ${targetItem.name}` }), _jsxs("div", { className: "flex min-h-0 flex-1 flex-col overflow-y-auto px-6 py-5", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("span", { className: "text-sm font-medium", children: "Import Location:" }), _jsxs("div", { className: "ml-2 flex flex-col gap-2", children: [_jsxs("label", { className: "flex cursor-pointer items-center gap-2 text-sm", children: [_jsx("input", { type: "radio", name: "import-location", value: "target", checked: !restoreToOriginalParents, onChange: () => setRestoreToOriginalParents(false) }), "Import to current folder (", targetItem.name, ")"] }), _jsxs("label", { className: "flex cursor-pointer items-center gap-2 text-sm", children: [_jsx("input", { type: "radio", name: "import-location", value: "original", checked: restoreToOriginalParents, onChange: () => setRestoreToOriginalParents(true) }), "Restore to original parent paths (will fail if parents don't exist)"] })] })] }), _jsxs("div", { className: "mt-4 flex flex-col gap-2", children: [_jsx("label", { htmlFor: "yaml-input", className: "text-sm font-medium", children: "YAML Content:" }), _jsx("textarea", { id: "yaml-input", ref: textareaRef, rows: 15, placeholder: "Paste your YAML content here...", className: "w-full resize-y rounded-md border border-input bg-background px-3 py-2 font-mono text-xs shadow-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring" })] }), _jsxs("div", { className: "mt-3 flex items-center gap-3 text-xs text-muted-foreground", children: [_jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: handlePasteFromClipboard, children: "\uD83D\uDCCB Paste from Clipboard" }), _jsx("span", { children: "Tip: Use Ctrl+V to paste YAML content directly into the text area" })] })] }), _jsxs(DialogButtons, { children: [_jsx(Button, { variant: "outline", onClick: () => onClose(null), children: "Cancel" }), _jsx(Button, { onClick: handleAccept, children: "Import" })] })] }) }));
}
//# sourceMappingURL=ImportItemsDialog.js.map