import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState, useEffect } from 'react';
import { Button, Modal, ModalBody, ModalFooter, ModalTitle, Input, RadioGroup, RadioOptionAdapter, FormItem } from '@vertesia/ui/core';
class SaveOptionAdapter extends RadioOptionAdapter {
    labelOf(item) {
        return item.label;
    }
    idOf(item) {
        return item.id;
    }
    renderOption(item) {
        return (_jsxs("div", { children: [_jsx("div", { className: "font-medium", children: item.label }), _jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-1", children: item.description })] }));
    }
}
export function SaveVersionConfirmModal({ isOpen, onClose, onConfirm, isLoading, uploadedFileName }) {
    const saveOptions = [
        {
            id: "update",
            label: "Update current version",
            description: uploadedFileName
                ? "Replace the content file and modify properties directly in the current revision."
                : "Modify the properties directly in the current revision."
        },
        {
            id: "new-version",
            label: "Create new version",
            description: uploadedFileName
                ? "Create a new revision with the replacement file while preserving the original."
                : "Create a new revision with these property changes while preserving the original."
        }
    ];
    // Default to "create new version" when replacing a file, "update current version" when editing properties
    const defaultOption = uploadedFileName ? saveOptions[1] : saveOptions[0];
    const [selectedOption, setSelectedOption] = useState(defaultOption);
    const [versionLabel, setVersionLabel] = useState('');
    const optionAdapter = new SaveOptionAdapter();
    // Reset to default when modal opens or uploadedFileName changes
    useEffect(() => {
        if (isOpen) {
            setSelectedOption(defaultOption);
            setVersionLabel('');
        }
    }, [isOpen, uploadedFileName]);
    const createVersion = selectedOption?.id === "new-version";
    const handleOptionChange = (option) => {
        setSelectedOption(option);
    };
    const handleConfirm = async () => {
        await onConfirm(createVersion, createVersion ? versionLabel : undefined);
    };
    return (_jsxs(Modal, { isOpen: isOpen, onClose: onClose, className: "sm:max-w-md", children: [_jsx(ModalTitle, { children: "Save Changes" }), _jsx(ModalBody, { children: _jsxs("div", { className: "space-y-4", children: [uploadedFileName && (_jsx("div", { className: "mb-4 p-3 bg-blue-50 dark:bg-blue-900/20 rounded-md", children: _jsxs("p", { className: "text-sm text-blue-700 dark:text-blue-300 font-medium", children: ["You're about to replace the content file with: ", _jsx("span", { className: "font-bold", children: uploadedFileName })] }) })), _jsx("p", { className: "text-sm text-mixer-muted/5", children: "How would you like to save these changes?" }), _jsx(RadioGroup, { adapter: optionAdapter, options: saveOptions, value: selectedOption, onChange: handleOptionChange, gap: "gap-4" }), createVersion && (_jsx(FormItem, { label: "Version Label (Optional)", description: "Optional label for the new version.", className: "mt-3 pl-8", children: _jsx(Input, { value: versionLabel, onChange: setVersionLabel, placeholder: "e.g., v1.2, approved, post-review", className: "w-full" }) }))] }) }), _jsxs(ModalFooter, { children: [_jsx(Button, { variant: "secondary", onClick: onClose, disabled: isLoading, children: "Cancel" }), _jsx(Button, { variant: "primary", onClick: handleConfirm, isLoading: isLoading, children: "Save" })] })] }));
}
//# sourceMappingURL=SaveVersionConfirmModal.js.map