"use client";
import { createContext, useContext, useMemo } from "react";
const context = createContext(null);
/**
 * **Client Component**
 *
 * @internal
 * @since 6.0.0
 */ export const { Provider: ListboxProvider } = context;
/**
 * @internal
 * @since 6.0.0
 */ export function useListboxContext() {
    const value = useContext(context);
    if (!value) {
        throw new Error("The `ListboxProvider` must be a parent component");
    }
    return value;
}
/**
 * @since 6.3.0
 */ export function useListboxProvider(options) {
    const { value, setValue, selectedIconAfter, selectedIcon, unselectedIcon, disableSelectedIcon } = options;
    const values = useMemo(()=>{
        if (Array.isArray(value)) {
            return new Set(value);
        }
        return new Set([
            value
        ]);
    }, [
        value
    ]);
    return useMemo(()=>({
            selectOption: setValue,
            isOptionSelected (option) {
                return values.has(option);
            },
            selectedIcon,
            unselectedIcon,
            selectedIconAfter,
            disableSelectedIcon
        }), [
        disableSelectedIcon,
        selectedIcon,
        selectedIconAfter,
        setValue,
        unselectedIcon,
        values
    ]);
}

//# sourceMappingURL=ListboxProvider.js.map