import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from "react";
import { Button, Modal, ModalBody, ModalFooter, ModalTitle, SelectBox, } from "@vertesia/ui/core";
import { useUserSession } from "@vertesia/ui/session";
import { CheckCircleIcon } from "lucide-react";
/**
 * A dedicated modal for selecting content types.
 *
 * This is a lightweight modal specifically for selecting a content type,
 * without any file upload functionality. Used for changing types, setting
 * types in other contexts, etc.
 */
export function SelectContentTypeModal({ isOpen, onClose, title = "Select Content Type", children, initialSelectedType = null, confirmLabel = "Select Type", allowNone = true, }) {
    const { typeRegistry } = useUserSession();
    const [selectedType, setSelectedType] = useState(initialSelectedType);
    // Get available types from the registry
    const types = typeRegistry?.types || [];
    // Handle close/cancel
    const handleClose = () => {
        onClose(undefined);
    };
    // Handle type selection and confirmation
    const handleConfirm = () => {
        onClose(selectedType?.id ?? null);
    };
    return (_jsxs(Modal, { isOpen: isOpen, onClose: handleClose, className: "w-full max-w-xl mx-auto", children: [_jsx(ModalTitle, { children: title }), _jsxs(ModalBody, { className: "p-6", children: [children, _jsxs("div", { className: "mb-4 mt-4", children: [_jsxs("label", { className: "block text-sm font-medium mb-2", children: ["Content Type ", allowNone && _jsx("span", { className: "text-gray-500 font-normal", children: "(Optional)" })] }), allowNone ? (_jsx(SelectBox, { options: types, value: selectedType, optionLabel: (type) => type ? type.name : 'Select a content type', placeholder: "Select a content type or leave empty for automatic detection", onChange: (selected) => setSelectedType(selected || null), filterBy: "name", isClearable: true })) : (_jsx(SelectBox, { options: types, value: selectedType, optionLabel: (type) => type ? type.name : 'Select a content type', placeholder: "Select a content type", onChange: (selected) => setSelectedType(selected || null), filterBy: "name" })), allowNone && (_jsxs("div", { className: "mt-2 text-sm text-blue-600 flex items-center", children: [_jsx(CheckCircleIcon, { className: "h-4 w-4 mr-1" }), _jsxs("span", { children: [_jsx("strong", { children: "Type selection is optional." }), " Leave empty to let Vertesia choose the appropriate type"] })] }))] }), selectedType ? (_jsxs("div", { className: "text-sm text-gray-500 bg-gray-50 p-3 rounded-md mb-4", children: [_jsx("div", { className: "font-medium", children: selectedType.name }), selectedType.description && (_jsx("div", { className: "mt-1", children: selectedType.description }))] })) : allowNone && (_jsxs("div", { className: "text-sm text-blue-600 bg-blue-50 p-3 rounded-md mb-4", children: [_jsx("div", { className: "font-medium", children: "Automatic Type Detection" }), _jsxs("div", { className: "mt-1", children: ["Vertesia will analyze each file's content and automatically select the most appropriate type.", _jsx("br", {}), _jsx("span", { className: "mt-1 block font-medium", children: "This is recommended for most uploads." })] })] }))] }), _jsxs(ModalFooter, { children: [_jsx(Button, { variant: "ghost", onClick: handleClose, children: "Cancel" }), _jsx(Button, { onClick: handleConfirm, children: selectedType ? `${confirmLabel}: ${selectedType.name}` : allowNone ? "Let Vertesia Choose" : confirmLabel })] })] }));
}
//# sourceMappingURL=SelectContentTypeModal.js.map