import '../../../../../node_modules/preact/compat/dist/compat.module.mjs';
import { useSessionStorage } from './useSessionStorage.mjs';
import { useCallback as T, useMemo as F } from '../../../../../node_modules/preact/hooks/dist/hooks.module.mjs';

const serialize = (value)=>Array.from(value);
const usePersistentFilter = ({ viewId, fieldId, defaultValue, permittedValues })=>{
    const deserialize = T((value)=>{
        if (!value) {
            return new Set(defaultValue);
        }
        return new Set(value.filter((v)=>permittedValues.has(v)));
    }, [
        defaultValue,
        permittedValues
    ]);
    const [serializedValue, setSerializedValue] = useSessionStorage(`${viewId}_filter_${fieldId}`, serialize(defaultValue));
    const value = F(()=>deserialize(serializedValue), [
        deserialize,
        serializedValue
    ]);
    const setValue = T((newValue)=>setSerializedValue(serialize(newValue)), [
        setSerializedValue
    ]);
    return [
        value,
        setValue
    ];
};

export { usePersistentFilter };
//# sourceMappingURL=usePersistentFilter.mjs.map
