import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { i18n, useAcceptedCookies, useCookieBanner, } from "@powerhousedao/connect";
import { CookieBanner as PHCookieBanner } from "@powerhousedao/design-system";
import { showPHModal } from "@powerhousedao/reactor-browser";
import { Trans, useTranslation } from "react-i18next";
const isCookieAccepted = (cookies, id) => {
    return cookies.some((cookie) => cookie.id === id && cookie.value);
};
export const CookieBanner = () => {
    const { t } = useTranslation(undefined, {
        useSuspense: true,
        i18n,
    });
    const [showBanner, setShowBanner] = useCookieBanner();
    const [, setAcceptedCookies] = useAcceptedCookies();
    const cookiesInput = [
        {
            id: "analytics-cookie",
            label: t("cookieBanner.cookies.analytics"),
            value: true,
        },
    ];
    const handleAccept = (cookies) => {
        setShowBanner(false);
        if (isCookieAccepted(cookies, "analytics-cookie")) {
            setAcceptedCookies((acceptedCookies) => ({
                ...acceptedCookies,
                analytics: true,
            }));
        }
    };
    const handleReject = () => {
        setShowBanner(false);
        setAcceptedCookies(() => ({
            analytics: false,
            functional: false,
            marketing: false,
        }));
    };
    if (!showBanner) {
        return null;
    }
    return (_jsxs("div", { className: "absolute inset-0 z-[10000] backdrop-blur-sm", children: [_jsx("div", { className: "absolute inset-0 bg-black opacity-15" }), _jsx("div", { className: "absolute inset-x-0 bottom-0 flex justify-center bg-white px-10 pb-16 pt-10 shadow-lg", children: _jsx(PHCookieBanner, { className: "max-w-[1024px]", cookies: cookiesInput, onSubmit: handleAccept, onReject: handleReject, submitLabel: t("cookieBanner.accept"), rejectLabel: t("cookieBanner.reject"), children: _jsx("p", { className: "font-semibold text-gray-500", children: _jsx(Trans, { i18nKey: "cookieBanner.message", components: {
                                a: (_jsx("a", { onClick: () => showPHModal({ type: "cookiesPolicy" }), className: "cursor-pointer text-gray-900 hover:underline" }, "cookieBanner.message-link")),
                            } }, "cookieBanner.message") }) }) })] }));
};
//# sourceMappingURL=cookie-banner.js.map