import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2025-2026 GoodData Corporation
import { useCallback, useMemo } from "react";
import { compressForUrl } from "@gooddata/sdk-ui";
import { Input } from "../../../Form/Input.js";
import { Typography } from "../../../Typography/Typography.js";
import { isCopyKey } from "../../../utils/events.js";
import { SHARE_LINK_HEADLINE_ID, SHARE_LINK_HELPER_TEXT_ID } from "./utils.js";
/**
 * @internal
 */
export function ShareLink({ dashboardFilters, dashboardParameters, dashboardLinkBasePath, headline, helperText, buttonLabel, onShareLinkCopy, }) {
    const shareLink = useMemo(() => {
        const queryParams = {
            filters: compressForUrl(dashboardFilters ?? []),
        };
        if (dashboardParameters?.length) {
            queryParams["parameters"] = compressForUrl(dashboardParameters);
        }
        const url = window.location.origin;
        const hashLocation = window.location.hash.split("?")[0];
        return url
            .concat(dashboardLinkBasePath ?? "/dashboards/")
            .concat(hashLocation)
            .concat(`?${new URLSearchParams(queryParams).toString()}`);
    }, [dashboardFilters, dashboardParameters, dashboardLinkBasePath]);
    const onIconButtonClick = useCallback(() => {
        onShareLinkCopy?.(shareLink);
    }, [shareLink, onShareLinkCopy]);
    const onKeyDown = useCallback((e) => {
        if (isCopyKey(e)) {
            onShareLinkCopy?.(shareLink);
        }
    }, [shareLink, onShareLinkCopy]);
    return (_jsxs(_Fragment, { children: [
            _jsx("div", { className: "gd-share-dialog-grantee-content-header", children: _jsx(Typography, { id: SHARE_LINK_HEADLINE_ID, tagName: "h3", children: headline }) }), _jsx(Input, { value: shareLink, type: "url", readonly: true, iconButton: "copy", onIconButtonClick: onIconButtonClick, iconButtonLabel: buttonLabel, onKeyDown: onKeyDown, accessibilityConfig: {
                    ariaDescribedBy: SHARE_LINK_HELPER_TEXT_ID,
                    ariaLabelledBy: SHARE_LINK_HEADLINE_ID,
                } }), _jsx("div", { id: SHARE_LINK_HELPER_TEXT_ID, className: "gd-share-dialog-share-link-helper-text", children: helperText })
        ] }));
}
