import { j as jsxRuntimeExports } from '../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js';
import { cx } from '../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js';
import { forwardRef, useMemo } from 'react';
import { SelectMultipleValue } from './select-multiple-value.js';
import { useSelectContext } from './select-root.js';
import styles from './select.module.css.js';
import { Value } from '../../node_modules/.pnpm/@radix-ui_react-select@2.2.5_@types_react-dom@18.0.11_@types_react@18.2.12_react-dom@18.3.1_react@18.2.0__react@18.2.0/node_modules/@radix-ui/react-select/dist/index.js';

const SelectValue = forwardRef(({ children, ...props }, ref) => {
    const { value, items, multiple } = useSelectContext();
    const item = useMemo(() => {
        if (!value)
            return undefined;
        if (multiple && Array.isArray(value)) {
            const itemValues = value.map(v => items[v]);
            if (itemValues.length === 1)
                return itemValues[0];
            return itemValues;
        }
        return items[value];
    }, [value, items, multiple]);
    if (children) {
        return (jsxRuntimeExports.jsx(Value, { ref: ref, ...props, children: typeof children === 'function' ? children(item) : children }));
    }
    if (Array.isArray(item))
        return jsxRuntimeExports.jsx(SelectMultipleValue, { data: item, ref: ref, ...props });
    return (jsxRuntimeExports.jsx(Value, { ref: ref, ...props, children: jsxRuntimeExports.jsxs("div", { className: cx(styles.valueContent), children: [typeof item?.children === 'string' && item?.leadingIcon && (jsxRuntimeExports.jsx("div", { className: styles.itemIcon, children: item.leadingIcon })), item?.children ?? value] }) }));
});
SelectValue.displayName = Value.displayName;

export { SelectValue };
//# sourceMappingURL=select-value.js.map
