import { connectConfig } from "@powerhousedao/connect/config";
import { useSyncExternalStore } from "react";
const namespace = connectConfig.routerBasename;
const ACCEPTED_COOKIES_KEY_STORAGE = `${namespace}:acceptedCookies`;
const listeners = new Set();
let cookies = getInitial();
function getInitial() {
    try {
        const value = localStorage.getItem(ACCEPTED_COOKIES_KEY_STORAGE);
        return value
            ? JSON.parse(value)
            : { analytics: false, marketing: false, functional: false };
    }
    catch {
        return { analytics: false, marketing: false, functional: false };
    }
}
function getCookies() {
    return cookies;
}
function setCookies(setter) {
    cookies = setter(cookies);
    localStorage.setItem(ACCEPTED_COOKIES_KEY_STORAGE, JSON.stringify(cookies));
    listeners.forEach((fn) => fn());
}
function subscribe(fn) {
    listeners.add(fn);
    return () => listeners.delete(fn);
}
export const useAcceptedCookies = () => {
    const cookies = useSyncExternalStore(subscribe, getCookies, getCookies);
    return [cookies, setCookies];
};
//# sourceMappingURL=useAcceptedCookies.js.map