import '../../../../node_modules/preact/compat/dist/compat.module.mjs';
import { useState as h, useCallback as T } from '../../../../node_modules/preact/hooks/dist/hooks.module.mjs';

const tryParseJson = (value)=>{
    try {
        if (value) {
            return JSON.parse(value);
        }
    } catch  {
    // no-op; assume data was malformed
    }
    return undefined;
};
/**
 * Low level wrapper around browser Storage (localStorage/sessionStorage). Do not use this hook directly, use
 * one of the useLocalStorage/useSessionStorage hook from inside ui and adminPortal instead.
 */ const useInternalStorage = (storage, publicToken, key, defaultValue)=>{
    const [cachedValue, setCachedValue] = h(()=>{
        const storedValue = storage.getItem(publicToken, key);
        return storedValue ? tryParseJson(storedValue) : defaultValue;
    });
    const setValue = T((value)=>{
        setCachedValue(value);
        storage.setItem(publicToken, key, JSON.stringify(value));
    }, [
        publicToken,
        key,
        storage
    ]);
    return [
        cachedValue,
        setValue
    ];
};

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