/**
 * Field type combobox with icons for type selection
 */
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState, useCallback } from 'react';
import { IoTextOutline, IoDocumentTextOutline, IoCheckboxOutline, IoRadioButtonOnOutline, IoChevronDownCircleOutline, IoCalendarOutline, IoCloudUploadOutline, IoLayersOutline, IoChevronDown, IoCheckmark, } from 'react-icons/io5';
import { cn } from '../../../utils/cn.js';
/**
 * Icon mapping for field types
 */
const FIELD_TYPE_ICONS = {
    IoTextOutline,
    IoDocumentTextOutline,
    IoCheckboxOutline,
    IoRadioButtonOnOutline,
    IoChevronDownCircleOutline,
    IoCalendarOutline,
    IoCloudUploadOutline,
    IoLayersOutline,
};
/**
 * FieldTypeCombobox - Combobox with icons for selecting field type
 * Uses shadcn Popover/Command components from props, falls back to native select
 */
export function FieldTypeCombobox({ value, available_types, on_change, id, combobox_components, }) {
    const [open, set_open] = useState(false);
    // Get icon component for a field type
    const get_icon = (icon_name) => {
        return FIELD_TYPE_ICONS[icon_name] || null;
    };
    // Get selected type metadata
    const selected_meta = available_types.find(t => t.type === value);
    const SelectedIcon = selected_meta ? get_icon(selected_meta.icon) : null;
    // Handle selection
    const handle_select = useCallback((type) => {
        on_change(type);
        set_open(false);
    }, [on_change]);
    // Fallback to native select if shadcn components not available
    if (!combobox_components) {
        return (_jsx("select", { value: value, onChange: e => on_change(e.target.value), className: "cls_field_type_select h-10 rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", "aria-label": "Select field type", children: available_types.map(meta => (_jsx("option", { value: meta.type, children: meta.label }, meta.type))) }));
    }
    const { Popover, PopoverTrigger, PopoverContent, Command, CommandList, CommandEmpty, CommandGroup, CommandItem, } = combobox_components;
    return (_jsxs(Popover, { open: open, onOpenChange: set_open, modal: true, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { type: "button", role: "combobox", "aria-expanded": open, "aria-label": "Select field type", className: cn('cls_field_type_trigger inline-flex items-center justify-between gap-1.5 h-10 px-3 py-2 rounded-md border border-input bg-background text-sm', 'hover:bg-accent hover:text-accent-foreground', 'focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2', 'min-w-[120px]'), children: [_jsxs("span", { className: "flex items-center gap-1.5 truncate", children: [SelectedIcon && _jsx(SelectedIcon, { className: "h-4 w-4 flex-shrink-0" }), _jsx("span", { className: "truncate", children: selected_meta?.label || 'Select' })] }), _jsx(IoChevronDown, { className: "h-4 w-4 opacity-50 flex-shrink-0" })] }) }), _jsx(PopoverContent, { className: "w-[180px] p-0", align: "start", onOpenAutoFocus: (e) => e.preventDefault(), onCloseAutoFocus: (e) => e.preventDefault(), children: _jsx(Command, { children: _jsxs(CommandList, { children: [_jsx(CommandEmpty, { children: "No field type found." }), _jsx(CommandGroup, { children: available_types.map(meta => {
                                    const IconComponent = get_icon(meta.icon);
                                    const is_selected = value === meta.type;
                                    return (_jsxs(CommandItem, { value: meta.type, onSelect: () => handle_select(meta.type), className: "flex items-center gap-2 cursor-pointer", children: [IconComponent && (_jsx(IconComponent, { className: "h-4 w-4 flex-shrink-0" })), _jsx("span", { className: "flex-1 truncate", children: meta.label }), is_selected && (_jsx(IoCheckmark, { className: "h-4 w-4 flex-shrink-0 text-primary" }))] }, meta.type));
                                }) })] }) }) })] }));
}
//# sourceMappingURL=field_type_combobox.js.map