import { jsx, jsxs } from 'react/jsx-runtime';
import React__default, { useState, useRef, useEffect, useCallback, useMemo, useId, forwardRef } from 'react';
import { S as SelectFieldWrapper } from './SelectFieldWrapper-BJzq9aCY.js';
import { c as cn } from './utils-DdHUxIdC.js';
import { ComboboxItem, ComboboxList, ComboboxEmpty, ComboboxCollection, ComboboxGroup, ComboboxLabel, Combobox, ComboboxChips, ComboboxChipsInput, ComboboxContent, ComboboxChip } from './primitives/Combobox.js';
import { Spinner } from './primitives/Spinner.js';
import { X } from './x-_o2T3n6D.js';
import { C as ChevronDown } from './chevron-down-BNi0ntys.js';

function hyphenize(str) {
    return str
        .replace(/([a-z])([A-Z])/g, "$1-$2")
        .replace(/[\s_]+/g, "-")
        .toLowerCase();
}

function buildAriaDescribedBy(error, errorId, helpText, helpTextId) {
    return ([error ? errorId : null, helpText ? helpTextId : null]
        .filter(Boolean)
        .join(" ") || undefined);
}
function buildTestIdPrefix(dataTestId, label) {
    return dataTestId ?? (label ? hyphenize(label) : undefined);
}

function useAsyncOptions({ loadOptions, defaultOptions = false, cacheOptions = false, }) {
    const [asyncOptions, setAsyncOptions] = useState(() => Array.isArray(defaultOptions) ? defaultOptions : []);
    const [isLoading, setIsLoading] = useState(false);
    const cacheRef = useRef({});
    const debounceRef = useRef(null);
    const latestRequestRef = useRef(0);
    const mountedRef = useRef(true);
    // Load default options on mount when `defaultOptions === true`
    useEffect(() => {
        if (!loadOptions || defaultOptions !== true)
            return;
        let cancelled = false;
        setIsLoading(true);
        loadOptions("")
            .then(results => {
            if (cancelled)
                return;
            setAsyncOptions(results);
            if (cacheOptions)
                cacheRef.current[""] = results;
            setIsLoading(false);
        })
            .catch(() => {
            if (!cancelled)
                setIsLoading(false);
        });
        return () => {
            cancelled = true;
        };
    }, []);
    // Clean up debounce timer and mark unmounted
    useEffect(() => {
        return () => {
            mountedRef.current = false;
            if (debounceRef.current)
                clearTimeout(debounceRef.current);
        };
    }, []);
    const handleAsyncInputChange = useCallback((value) => {
        if (!loadOptions)
            return;
        const query = value.trim();
        // Check cache first
        if (cacheOptions && query in cacheRef.current) {
            setAsyncOptions(cacheRef.current[query]);
            return;
        }
        // Debounce the fetch
        if (debounceRef.current)
            clearTimeout(debounceRef.current);
        debounceRef.current = setTimeout(() => {
            const requestId = ++latestRequestRef.current;
            setIsLoading(true);
            loadOptions(query)
                .then(results => {
                if (requestId !== latestRequestRef.current || !mountedRef.current)
                    return;
                setAsyncOptions(results);
                if (cacheOptions)
                    cacheRef.current[query] = results;
                setIsLoading(false);
            })
                .catch(() => {
                if (requestId === latestRequestRef.current && mountedRef.current) {
                    setIsLoading(false);
                }
            });
        }, 300);
    }, [loadOptions, cacheOptions]);
    return { asyncOptions, isLoading, handleAsyncInputChange };
}

function useLazyLoadSentinel({ fetchMore, isEnabled, }) {
    const observerRef = useRef(null);
    const fetchMoreRef = useRef(fetchMore);
    fetchMoreRef.current = fetchMore;
    const sentinelRef = useCallback((node) => {
        observerRef.current?.disconnect();
        observerRef.current = null;
        if (!node || !isEnabled)
            return;
        const observer = new IntersectionObserver(entries => {
            if (entries[0]?.isIntersecting)
                fetchMoreRef.current?.();
        }, { root: null, rootMargin: "0px", threshold: 0.1 });
        observer.observe(node);
        observerRef.current = observer;
    }, [isEnabled]);
    // Clean up observer on unmount
    useEffect(() => {
        return () => {
            observerRef.current?.disconnect();
        };
    }, []);
    return sentinelRef;
}

const CREATE_PREFIX = "__create__:";
function useCreatableItems({ isCreatable, isGrouped, flatOptions, selectedValues, baseUiItems, onCreateOption, onChange, onAsyncInputChange, children, }) {
    const [inputValue, setInputValue] = useState("");
    const handleInputValueChange = useCallback((value) => {
        setInputValue(value);
        onAsyncInputChange?.(value);
    }, [onAsyncInputChange]);
    const trimmedInput = inputValue.trim();
    const showCreateOption = useMemo(() => {
        if (!isCreatable || trimmedInput.length === 0)
            return false;
        const lower = trimmedInput.toLowerCase();
        return (!flatOptions.some(o => o.label.toLowerCase() === lower || o.value.toLowerCase() === lower) && !selectedValues.includes(trimmedInput));
    }, [isCreatable, trimmedInput, flatOptions, selectedValues]);
    const effectiveItems = React__default.useMemo(() => computeEffectiveItems(children, baseUiItems, showCreateOption, isGrouped, trimmedInput), [baseUiItems, children, isGrouped, showCreateOption, trimmedInput]);
    // Custom filter: always pass the "Create" item through
    const creatableFilter = useCallback((itemValue, query, itemToString) => {
        if (itemValue.startsWith(CREATE_PREFIX))
            return true;
        const label = itemToString?.(itemValue) ?? itemValue;
        return label.toLowerCase().includes(query.toLowerCase());
    }, []);
    const handleValueChange = useCallback((next) => {
        const raw = next ?? [];
        const createEntry = raw.find(v => v.startsWith(CREATE_PREFIX));
        if (createEntry) {
            const newValue = createEntry.slice(CREATE_PREFIX.length);
            const withNewValue = raw.map(v => (v === createEntry ? newValue : v));
            onCreateOption?.(newValue);
            onChange?.(withNewValue);
            return;
        }
        onChange?.(raw);
    }, [onChange, onCreateOption]);
    return {
        inputValue,
        showCreateOption,
        effectiveItems,
        creatableFilter,
        handleInputValueChange,
        handleValueChange,
    };
}

function isOptionGroup(opt) {
    return "options" in opt && Array.isArray(opt.options);
}

/** Flatten grouped options into a flat lookup array. */
function flattenOptions(options) {
    return options.flatMap(opt => (isOptionGroup(opt) ? opt.options : [opt]));
}
/** Check if any option is a group. */
function hasGroups(options) {
    return options.some(isOptionGroup);
}
/** Convert options to base-ui `items` format for filtering support. */
function toBaseUiItems(options) {
    if (hasGroups(options)) {
        return options.filter(isOptionGroup).map(g => ({
            label: g.label,
            items: g.options.map(o => o.value),
        }));
    }
    return options.map(o => o.value);
}
/** Build the effective items array, appending a "Create" entry when needed. */
function computeEffectiveItems(children, baseUiItems, showCreateOption, isGrouped, trimmedInput) {
    if (children)
        return undefined;
    const createValue = showCreateOption
        ? `${CREATE_PREFIX}${trimmedInput}`
        : null;
    if (!baseUiItems && !createValue)
        return undefined;
    const base = baseUiItems ?? [];
    if (!createValue)
        return base;
    if (!isGrouped) {
        return [...base, createValue];
    }
    return [
        ...base,
        { label: "", items: [createValue] },
    ];
}

function useMultiSelectOptions(props) {
    const isAsync = !!props.loadOptions;
    const { asyncOptions, isLoading, handleAsyncInputChange } = useAsyncOptions({
        loadOptions: props.loadOptions,
        defaultOptions: props.defaultOptions ?? false,
        cacheOptions: props.cacheOptions ?? false,
    });
    const resolvedOptions = isAsync
        ? asyncOptions
        : (props.options ?? []);
    const flatOptions = flattenOptions(resolvedOptions);
    const isGrouped = hasGroups(resolvedOptions);
    const baseUiItems = React__default.useMemo(() => resolvedOptions.length > 0 ? toBaseUiItems(resolvedOptions) : undefined, [resolvedOptions]);
    const hasMoreLazy = (props.isAsyncLoadOptionEnabled ?? false) &&
        typeof props.totalOptionsCount === "number" &&
        flatOptions.length < props.totalOptionsCount;
    const loaderCallbackRef = useLazyLoadSentinel({
        fetchMore: props.fetchMore,
        isEnabled: props.isAsyncLoadOptionEnabled ?? false,
    });
    return {
        isAsync,
        resolvedOptions,
        flatOptions,
        isGrouped,
        isLoading,
        handleAsyncInputChange,
        baseUiItems,
        hasMoreLazy,
        loaderCallbackRef,
    };
}

// SIZE_CONFIG is shared by both SelectCombobox (single-select) and
// MultiSelectCombobox (multi-select). Keys mirror the MultiSelect constants
// that previously lived in MultiSelect.constants.ts.
const SIZE_CONFIG = {
    small: {
        chips: "min-h-7 text-xs gap-0.5 px-1 py-0.5",
        input: "text-xs",
        chip: "h-4.5 text-[0.6875rem] px-1",
    },
    medium: {
        chips: "min-h-8 text-sm gap-1 px-2.5 py-1",
        input: "text-sm",
        chip: "h-5.25 text-xs px-1.5",
    },
    large: {
        chips: "min-h-10 text-sm gap-1 px-2.5 py-1.5",
        input: "text-sm",
        chip: "h-6 text-xs px-2",
    },
};

const defaultFormatCreateLabel$1 = (v) => `Create "${v}"`;
function useSelectState(props) {
    const { id: idProp, size = "medium", label = "", error = "", helpText = "", value: valueProp, defaultValue, onChange, dataTestId, isCreatable = false, onCreateOption, formatCreateLabel = defaultFormatCreateLabel$1, isClearable = false, isDisabled = false, required = false, isSearchable = true, autoHighlight = true, onOpenChange, children, } = props;
    const opt = useMultiSelectOptions(props);
    const generatedId = useId();
    const id = idProp ?? generatedId;
    const errorId = `error_${id}`;
    const helpTextId = `helpText_${id}`;
    const sizeConfig = SIZE_CONFIG[size];
    const isControlled = valueProp !== undefined;
    const [internalValue, setInternalValue] = useState(defaultValue ?? "");
    const currentValue = isControlled ? (valueProp ?? "") : internalValue;
    const applyValue = useCallback((next) => {
        if (!isControlled)
            setInternalValue(next);
        onChange?.(next);
    }, [isControlled, onChange]);
    const handleValueChange = useCallback((next) => {
        const raw = next ?? "";
        // Handle the creatable "Create X" option
        if (raw.startsWith(CREATE_PREFIX)) {
            const newValue = raw.slice(CREATE_PREFIX.length);
            onCreateOption?.(newValue);
            applyValue(newValue);
            return;
        }
        applyValue(raw);
    }, [applyValue, onCreateOption]);
    const [inputValue, setInputValueState] = useState("");
    const trimmedInput = inputValue.trim();
    const combinedHandleInputValueChange = useCallback((value) => {
        setInputValueState(value);
        if (opt.isAsync)
            opt.handleAsyncInputChange(value);
    }, [opt.isAsync, opt.handleAsyncInputChange]);
    const handleClear = useCallback(() => {
        applyValue("");
    }, [applyValue]);
    const showCreateOption = useMemo(() => {
        if (!isCreatable ||
            trimmedInput.length === 0 ||
            currentValue === trimmedInput)
            return false;
        const lower = trimmedInput.toLowerCase();
        return !opt.flatOptions.some(o => o.label.toLowerCase() === lower || o.value.toLowerCase() === lower);
    }, [isCreatable, trimmedInput, currentValue, opt.flatOptions]);
    const effectiveItems = useMemo(() => {
        if (children)
            return undefined;
        const base = opt.baseUiItems;
        if (!showCreateOption)
            return base;
        const createValue = `${CREATE_PREFIX}${trimmedInput}`;
        if (!opt.isGrouped) {
            return [...(base ?? []), createValue];
        }
        return [
            ...(base ?? []),
            { label: "", items: [createValue] },
        ];
    }, [
        children,
        opt.baseUiItems,
        opt.isGrouped,
        showCreateOption,
        trimmedInput,
    ]);
    const creatableFilter = useCallback((itemValue, query, itemToString) => {
        if (itemValue.startsWith(CREATE_PREFIX))
            return true;
        const label = itemToString?.(itemValue) ?? itemValue;
        return label.toLowerCase().includes(query.toLowerCase());
    }, []);
    const ariaDescribedBy = buildAriaDescribedBy(error, errorId, helpText, helpTextId);
    const testIdPrefix = buildTestIdPrefix(dataTestId, label);
    const showClearButton = isClearable && !!currentValue && !isDisabled;
    const flatOptionsMap = useMemo(() => new Map(opt.flatOptions.map(o => [o.value, o])), [opt.flatOptions]);
    const labelForValue = useCallback((val) => {
        if (val.startsWith(CREATE_PREFIX)) {
            return formatCreateLabel(val.slice(CREATE_PREFIX.length));
        }
        return flatOptionsMap.get(val)?.label ?? val;
    }, [flatOptionsMap, formatCreateLabel]);
    return {
        ...opt,
        id,
        errorId,
        helpTextId,
        sizeConfig,
        isControlled,
        currentValue,
        effectiveItems,
        creatableFilter,
        handleValueChange,
        handleInputValueChange: combinedHandleInputValueChange,
        handleClear,
        showCreateOption,
        showClearButton,
        ariaDescribedBy,
        testIdPrefix,
        labelForValue,
        flatOptionsMap,
        label,
        error,
        helpText,
        isDisabled,
        required,
        isSearchable,
        autoHighlight,
        onOpenChange,
        isClearable,
    };
}

const defaultFormatCreateLabel = (v) => `Create "${v}"`;
function useMultiSelectState(props) {
    const { id: idProp, size = "medium", label = "", error = "", helpText = "", value: valueProp, defaultValue, onChange, dataTestId, isCreatable = false, onCreateOption, formatCreateLabel = defaultFormatCreateLabel, children, } = props;
    const opt = useMultiSelectOptions(props);
    const generatedId = useId();
    const id = idProp ?? generatedId;
    const errorId = `error_${id}`;
    const helpTextId = `helpText_${id}`;
    const sizeConfig = SIZE_CONFIG[size];
    const isControlled = valueProp !== undefined;
    const [internalValue, setInternalValue] = useState(defaultValue ?? []);
    const selectedValues = isControlled ? valueProp : internalValue;
    const handleChange = useCallback((values) => {
        setInternalValue(values);
        onChange?.(values);
    }, [onChange]);
    const { showCreateOption, effectiveItems, creatableFilter, handleInputValueChange, handleValueChange, } = useCreatableItems({
        isCreatable,
        isGrouped: opt.isGrouped,
        flatOptions: opt.flatOptions,
        selectedValues,
        baseUiItems: opt.baseUiItems,
        onCreateOption,
        onChange: handleChange,
        onAsyncInputChange: opt.isAsync ? opt.handleAsyncInputChange : undefined,
        children,
    });
    const ariaDescribedBy = buildAriaDescribedBy(error, errorId, helpText, helpTextId);
    const testIdPrefix = buildTestIdPrefix(dataTestId, label);
    const flatOptionsMap = useMemo(() => new Map(opt.flatOptions.map(o => [o.value, o])), [opt.flatOptions]);
    const labelForValue = useCallback((val) => {
        if (val.startsWith(CREATE_PREFIX)) {
            return formatCreateLabel(val.slice(CREATE_PREFIX.length));
        }
        return flatOptionsMap.get(val)?.label ?? val;
    }, [flatOptionsMap, formatCreateLabel]);
    return {
        ...opt,
        id,
        errorId,
        helpTextId,
        sizeConfig,
        isControlled,
        selectedValues,
        effectiveItems,
        creatableFilter,
        handleInputValueChange,
        handleValueChange,
        showCreateOption,
        ariaDescribedBy,
        testIdPrefix,
        labelForValue,
        flatOptionsMap,
        label,
        error,
        helpText,
    };
}

/** Shared anchor + non-searchable click-to-focus behaviour for combobox triggers. */
function useComboboxAnchor(isSearchable) {
    const [anchorEl, setAnchorEl] = useState(null);
    const handleClick = useCallback((e) => {
        if (!isSearchable) {
            e.currentTarget.querySelector("input")?.focus();
        }
    }, [isSearchable]);
    return { anchorEl, setAnchorEl, handleClick };
}

function OptionItem({ val, flatOptionsMap, labelForValue, testIdPrefix, }) {
    return (jsx(ComboboxItem, { value: val, disabled: !val.startsWith(CREATE_PREFIX) && flatOptionsMap.get(val)?.disabled, className: val.startsWith(CREATE_PREFIX) ? "text-primary" : undefined, ...(testIdPrefix
            ? { "data-testid": `${testIdPrefix}-select-option` }
            : {}), children: labelForValue(val) }, val));
}

function MultiSelectDropdown({ resolvedOptions, flatOptionsMap, isGrouped, isLoading, loadingMessage, emptyMessage, showCreateOption, labelForValue, testIdPrefix, hasMoreLazy, loaderCallbackRef, children, }) {
    return (jsxs(ComboboxList, { ...(testIdPrefix
            ? { "data-testid": `${testIdPrefix}-select-menu` }
            : {}), children: [isLoading && (jsx("div", { className: "flex w-full justify-center py-2 text-center text-sm text-muted-foreground", children: loadingMessage })), !isLoading && !showCreateOption && (jsx(ComboboxEmpty, { children: emptyMessage })), children ??
                (resolvedOptions.length > 0 || showCreateOption ? (isGrouped ? (jsx(ComboboxCollection, { children: (group) => (jsxs(ComboboxGroup, { items: group.items, children: [group.label && jsx(ComboboxLabel, { children: group.label }), jsx(ComboboxCollection, { children: (val) => (jsx(OptionItem, { val: val, flatOptionsMap: flatOptionsMap, labelForValue: labelForValue, testIdPrefix: testIdPrefix }, val)) })] }, group.label || "__create__")) })) : (jsx(ComboboxCollection, { children: (val) => (jsx(OptionItem, { val: val, flatOptionsMap: flatOptionsMap, labelForValue: labelForValue, testIdPrefix: testIdPrefix }, val)) }))) : null), hasMoreLazy && (jsx("div", { ref: loaderCallbackRef, className: "flex w-full items-center justify-center py-3", "data-testid": testIdPrefix ? `${testIdPrefix}-lazy-loader` : "lazy-loader", children: jsx(Spinner, {}) }))] }));
}

const SelectCombobox = forwardRef((p, ref) => {
    const { anchorEl, setAnchorEl, handleClick } = useComboboxAnchor(p.isSearchable);
    const handleClearClick = useCallback((e) => {
        e.stopPropagation();
        e.preventDefault();
        p.handleClear();
    }, [p.handleClear]);
    return (
    // @ts-expect-error — conditional spread creates a union that TS cannot narrow to the Combobox discriminated-union props
    jsxs(Combobox, { name: p.name, ...(p.effectiveItems && !p.children
            ? {
                items: p.effectiveItems,
                itemToStringLabel: p.labelForValue,
                ...(!p.isSearchable || p.isAsync
                    ? { filter: null }
                    : p.isCreatable
                        ? { filter: p.creatableFilter }
                        : {}),
            }
            : {}), value: p.currentValue, onValueChange: p.handleValueChange, ...(p.isCreatable || p.isAsync
            ? { onInputValueChange: p.handleInputValueChange }
            : {}), onOpenChange: p.onOpenChange, disabled: p.isDisabled, autoHighlight: p.autoHighlight, children: [jsx("div", { ref: setAnchorEl, onClick: handleClick, className: !p.isSearchable ? "cursor-pointer" : undefined, children: jsxs(ComboboxChips, { className: cn(p.sizeConfig.chips, !!p.error &&
                        "border-destructive ring-3 ring-destructive/20 dark:border-destructive/50 dark:ring-destructive/40", p.inputClassName), ...(p.testIdPrefix
                        ? { "data-testid": `${p.testIdPrefix}-select-container` }
                        : {}), children: [!p.isSearchable &&
                            (p.currentValue ? (jsx("span", { className: "flex-1 truncate", children: p.labelForValue(p.currentValue) })) : (jsx("span", { className: "flex-1 truncate text-muted-foreground", children: p.placeholder }))), jsx(ComboboxChipsInput, { ref: ref, id: p.id, placeholder: p.isSearchable && !p.currentValue ? p.placeholder : undefined, "aria-invalid": !!p.error || undefined, "aria-describedby": p.ariaDescribedBy, "aria-required": p.required || undefined, className: cn(p.sizeConfig.input, !p.isSearchable && "w-0 min-w-0 overflow-hidden p-0 opacity-0"), disabled: p.isDisabled, ...(p.testIdPrefix
                                ? { "data-testid": `${p.testIdPrefix}-select-input` }
                                : {}) }), p.showClearButton && (jsx("button", { type: "button", tabIndex: -1, "aria-label": "Clear selection", className: "shrink-0 text-muted-foreground hover:text-foreground", onClick: handleClearClick, children: jsx(X, { className: "size-3.5" }) })), jsx(ChevronDown, { className: "size-4 shrink-0 text-muted-foreground" })] }) }), jsx(ComboboxContent, { anchor: anchorEl, ...p.contentProps, children: jsx(MultiSelectDropdown, { ...p.dropdownProps, labelForValue: p.labelForValue, testIdPrefix: p.testIdPrefix, children: p.children }) })] }));
});
SelectCombobox.displayName = "SelectCombobox";

const MultiSelectCombobox = forwardRef((p, ref) => {
    const { anchorEl, setAnchorEl, handleClick } = useComboboxAnchor(p.isSearchable);
    return (
    // @ts-expect-error — conditional spread creates a union that TS cannot narrow to the Combobox discriminated-union props
    jsxs(Combobox, { multiple: true, name: p.name, ...(p.effectiveItems && !p.children
            ? {
                items: p.effectiveItems,
                itemToStringLabel: p.labelForValue,
                ...(!p.isSearchable || p.isAsync
                    ? { filter: null }
                    : p.isCreatable
                        ? { filter: p.creatableFilter }
                        : {}),
            }
            : {}), ...(p.isControlled
            ? { value: p.valueProp }
            : { defaultValue: p.defaultValue }), onValueChange: p.handleValueChange, ...(p.isCreatable || p.isAsync
            ? { onInputValueChange: p.handleInputValueChange }
            : {}), onOpenChange: p.onOpenChange, disabled: p.isDisabled, autoHighlight: p.autoHighlight, children: [jsx("div", { ref: setAnchorEl, onClick: handleClick, className: !p.isSearchable ? "cursor-pointer" : undefined, children: jsxs(ComboboxChips, { className: cn(p.sizeConfig.chips, !!p.error &&
                        "border-destructive ring-3 ring-destructive/20 dark:border-destructive/50 dark:ring-destructive/40", p.chipsClassName, p.inputClassName), ...(p.testIdPrefix
                        ? { "data-testid": `${p.testIdPrefix}-select-container` }
                        : {}), children: [p.selectedValues.map(val => (jsx(ComboboxChip, { className: p.sizeConfig.chip, showRemove: !p.hideChipRemove, ...(p.testIdPrefix
                                ? { "data-testid": `${p.testIdPrefix}-chip` }
                                : {}), children: p.labelForValue(val) }, val))), jsx(ComboboxChipsInput, { ref: ref, id: p.id, placeholder: p.isSearchable && p.selectedValues.length === 0
                                ? p.placeholder
                                : undefined, "aria-invalid": !!p.error || undefined, "aria-describedby": p.ariaDescribedBy, "aria-required": p.required || undefined, className: cn(p.sizeConfig.input, !p.isSearchable && "w-0 min-w-0 overflow-hidden p-0 opacity-0"), disabled: p.isDisabled, ...(p.testIdPrefix
                                ? { "data-testid": `${p.testIdPrefix}-select-input` }
                                : {}) })] }) }), jsx(ComboboxContent, { anchor: anchorEl, ...p.contentProps, children: jsx(MultiSelectDropdown, { ...p.dropdownProps, labelForValue: p.labelForValue, testIdPrefix: p.testIdPrefix, children: p.children }) })] }));
});
MultiSelectCombobox.displayName = "MultiSelectCombobox";

const SingleSelectInner = forwardRef((props, ref) => {
    const s = useSelectState(props);
    return (jsx(SelectFieldWrapper, { id: s.id, label: s.label, error: s.error, helpText: s.helpText, errorId: s.errorId, helpTextId: s.helpTextId, isDisabled: s.isDisabled, required: s.required, testIdPrefix: s.testIdPrefix, labelProps: props.labelProps, className: props.className, children: jsx(SelectCombobox, { ref: ref, name: props.name, id: s.id, effectiveItems: s.effectiveItems, labelForValue: s.labelForValue, isSearchable: s.isSearchable, isAsync: s.isAsync, isCreatable: props.isCreatable ?? false, creatableFilter: s.creatableFilter, isControlled: s.isControlled, valueProp: props.value, defaultValue: props.defaultValue, currentValue: s.currentValue, handleValueChange: s.handleValueChange, handleInputValueChange: s.handleInputValueChange, handleClear: s.handleClear, onOpenChange: props.onOpenChange, isDisabled: s.isDisabled, autoHighlight: s.autoHighlight, required: s.required, isClearable: props.isClearable ?? false, showClearButton: s.showClearButton, sizeConfig: s.sizeConfig, error: s.error, placeholder: props.placeholder ?? "", ariaDescribedBy: s.ariaDescribedBy, testIdPrefix: s.testIdPrefix, inputClassName: props.inputClassName, contentProps: props.contentProps, dropdownProps: {
                resolvedOptions: s.resolvedOptions,
                flatOptionsMap: s.flatOptionsMap,
                isGrouped: s.isGrouped,
                isLoading: s.isLoading,
                loadingMessage: props.loadingMessage ?? "Loading\u2026",
                emptyMessage: props.emptyMessage ?? "No results found.",
                showCreateOption: s.showCreateOption,
                hasMoreLazy: s.hasMoreLazy,
                loaderCallbackRef: s.loaderCallbackRef,
            }, children: props.children }) }));
});
SingleSelectInner.displayName = "SingleSelectInner";
const MultiSelectInner = forwardRef((props, ref) => {
    const s = useMultiSelectState(props);
    const { isDisabled = false, required = false } = props;
    return (jsx(SelectFieldWrapper, { id: s.id, label: s.label, error: s.error, helpText: s.helpText, errorId: s.errorId, helpTextId: s.helpTextId, isDisabled: isDisabled, required: required, testIdPrefix: s.testIdPrefix, labelProps: props.labelProps, className: props.className, children: jsx(MultiSelectCombobox, { ref: ref, name: props.name, id: s.id, effectiveItems: s.effectiveItems, labelForValue: s.labelForValue, isSearchable: props.isSearchable ?? true, isAsync: s.isAsync, isCreatable: props.isCreatable ?? false, creatableFilter: s.creatableFilter, isControlled: s.isControlled, valueProp: props.value, defaultValue: props.defaultValue, selectedValues: s.selectedValues, handleValueChange: s.handleValueChange, handleInputValueChange: s.handleInputValueChange, onOpenChange: props.onOpenChange, isDisabled: isDisabled, autoHighlight: props.autoHighlight ?? true, sizeConfig: s.sizeConfig, error: s.error, chipsClassName: props.chipsClassName, inputClassName: props.inputClassName, placeholder: props.placeholder ?? "", hideChipRemove: props.hideChipRemove ?? false, ariaDescribedBy: s.ariaDescribedBy, required: required, testIdPrefix: s.testIdPrefix, contentProps: props.contentProps, dropdownProps: {
                resolvedOptions: s.resolvedOptions,
                flatOptionsMap: s.flatOptionsMap,
                isGrouped: s.isGrouped,
                isLoading: s.isLoading,
                loadingMessage: props.loadingMessage ?? "Loading\u2026",
                emptyMessage: props.emptyMessage ?? "No results found.",
                showCreateOption: s.showCreateOption,
                hasMoreLazy: s.hasMoreLazy,
                loaderCallbackRef: s.loaderCallbackRef,
            }, children: props.children }) }));
});
MultiSelectInner.displayName = "MultiSelectInner";
const Select = forwardRef((props, ref) => {
    if (props.isMulti === true) {
        return jsx(MultiSelectInner, { ...props, ref: ref });
    }
    return jsx(SingleSelectInner, { ...props, ref: ref });
});
Select.displayName = "Select";

export { Select as S };
//# sourceMappingURL=Select-BgSz0fve.js.map
