"use client";
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
import { ComboboxItem } from '../../node_modules/.pnpm/@ariakit_react-core@0.4.16_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/@ariakit/react-core/esm/__chunks/JMHAJKUZ.js';
import { cx } from '../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js';
import { forwardRef, useLayoutEffect } from 'react';
import { Checkbox } from '../checkbox/checkbox.js';
import { getMatch } from '../dropdown-menu/utils.js';
import { Text } from '../text/text.js';
import { useSelectContext } from './select-root.js';
import styles from './select.module.css.js';
import { Item } from '../../node_modules/.pnpm/@radix-ui_react-select@2.2.5_@types_react-dom@19.1.7_@types_react@19.1.9__@types_react@19.1.9_irkq3yh3qlkawac7zwq2rwd6bi/node_modules/@radix-ui/react-select/dist/index.js';

const SelectItem = forwardRef(({ className, children, value: providedValue, leadingIcon, disabled, ...props }, ref) => {
    const value = String(providedValue);
    const { registerItem, unregisterItem, autocomplete, searchValue, value: selectValue, shouldFilter, multiple } = useSelectContext();
    const isSelected = multiple
        ? selectValue?.includes(value)
        : value === selectValue;
    const isMatched = getMatch(value, children, searchValue);
    const isHidden = shouldFilter && isSelected && !isMatched;
    const element = typeof children === 'string' ? (jsxs(Fragment, { children: [leadingIcon && jsx("div", { className: styles.itemIcon, children: leadingIcon }), jsx(Text, { children: children })] })) : (children);
    useLayoutEffect(() => {
        registerItem({ leadingIcon, children, value });
        return () => {
            unregisterItem(value);
        };
    }, [value, children, registerItem, unregisterItem, leadingIcon]);
    if (shouldFilter && !isMatched && !isSelected) {
        // Not selected and doesn't match search, so don't render at all
        return null;
    }
    return (jsx(Item, { ref: ref, value: value, className: cx(styles.menuitem, className, isHidden && styles.hidden), "data-hidden": isHidden, disabled: disabled || isHidden, asChild: autocomplete, "aria-selected": isSelected, "data-checked": isSelected, ...props, children: autocomplete ? (jsxs(ComboboxItem, { clickOnEnter: false, clickOnSpace: false, onBlurCapture: event => {
                event.preventDefault();
            }, children: [multiple && jsx(Checkbox, { checked: isSelected }), element] })) : (jsxs(Fragment, { children: [multiple && jsx(Checkbox, { checked: isSelected }), element] })) }));
});
SelectItem.displayName = Item.displayName;

export { SelectItem };
//# sourceMappingURL=select-item.js.map
