import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import * as styles from "./styles";
import Logo from "~/assets/images/logo.svg";
export const Attribution = ({ sdkName, locale, onClick, isTransparent = false, isHidden = false, }) => {
    const { t } = useTranslation(["common"]);
    const href = useMemo(() => {
        const baseUrl = `https://locallogic.co/${typeof locale !== "undefined" && locale !== "en" ? `${locale}/` : ""}`;
        let baseParams = {};
        try {
            baseParams = {
                utm_source: (document === null || document === void 0 ? void 0 : document.referrer) || "unknown",
                utm_medium: "referral",
                utm_campaign: sdkName || "unknown-sdk",
            };
        }
        catch (_error) {
            return baseUrl; // Fallback to base URL if there's an error
        }
        const params = new URLSearchParams(baseParams).toString();
        return params ? `${baseUrl}?${params}` : baseUrl;
    }, [sdkName, locale]);
    if (isHidden) {
        return null;
    }
    return (React.createElement("a", { "data-testid": "attribution-link", onClick: onClick, className: styles.container, href: href, target: "_blank", rel: "noreferrer", "data-is-transparent": isTransparent },
        t("common:attribution"),
        React.createElement("div", { className: styles.logoContainer },
            React.createElement(Logo, null))));
};
/**
 * @deprecated Use Attribution instead unless you're on the old design system
 *
 * @param param0
 * @returns
 */
export const AttributionDeprecated = ({ sdkName, locale, onClick, }) => {
    const { t } = useTranslation(["common"]);
    const href = useMemo(() => {
        const baseUrl = `https://locallogic.co/${typeof locale !== "undefined" && locale !== "en" ? `${locale}/` : ""}`;
        let baseParams = {};
        try {
            baseParams = {
                utm_source: (document === null || document === void 0 ? void 0 : document.referrer) || "unknown",
                utm_medium: "referral",
                utm_campaign: sdkName || "unknown-sdk",
            };
        }
        catch (_error) {
            return baseUrl; // Fallback to base URL if there's an error
        }
        const params = new URLSearchParams(baseParams).toString();
        return params ? `${baseUrl}?${params}` : baseUrl;
    }, [sdkName, locale]);
    return (React.createElement("a", { onClick: onClick, className: styles.containerDeprecated, href: href, target: "_blank", rel: "noreferrer" },
        t("common:attribution"),
        React.createElement("div", { className: styles.logoContainerDeprecated },
            React.createElement(Logo, null))));
};
//# sourceMappingURL=index.js.map