import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2021-2026 GoodData Corporation
import { useCallback } from "react";
import cx from "classnames";
import { useIntl } from "react-intl";
import { Button, UiTooltip } from "@gooddata/sdk-ui-kit";
import { useDashboardDispatch, useDashboardSelector, } from "../../../../../model/react/DashboardStoreProvider.js";
import { selectIsShareButtonVisible } from "../../../../../model/store/topBar/topBarSelectors.js";
import { uiActions } from "../../../../../model/store/ui/index.js";
import { selectDashboardDensity } from "../../../../../model/store/ui/uiSelectors.js";
import { HiddenShareButton } from "./HiddenShareButton.js";
/**
 * @internal
 */
export function useShareButtonProps() {
    const dispatch = useDashboardDispatch();
    const onShareButtonClick = useCallback(() => dispatch(uiActions.openShareDialog()), [dispatch]);
    const isVisible = useDashboardSelector(selectIsShareButtonVisible);
    return {
        isVisible,
        onShareButtonClick,
    };
}
/**
 * @alpha
 */
export function DefaultShareButton({ isVisible, onShareButtonClick, }) {
    const density = useDashboardSelector(selectDashboardDensity);
    const intl = useIntl();
    const tooltipText = intl.formatMessage({ id: "share.button.tooltip" });
    if (!isVisible) {
        return _jsx(HiddenShareButton, {});
    }
    return (_jsx(UiTooltip, { arrowPlacement: "top-end", content: tooltipText, anchor: _jsx(Button, { onClick: () => onShareButtonClick(), value: intl.formatMessage({ id: "share.button.text" }), className: cx("gd-button-secondary dash-header-share-button s-header-share-button gd-button gd-icon-users", {
                "gd-button-small": density === "compact",
            }), accessibilityConfig: {
                ariaLabel: tooltipText,
                popupType: "dialog",
                popupId: "share-dialog",
            } }), triggerBy: ["hover", "focus"] }));
}
