import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2024-2025 GoodData Corporation
import { useRef, useState } from "react";
import { defineMessages, useIntl } from "react-intl";
import { Overlay, UiButton, alignConfigToAlignPoint } from "@gooddata/sdk-ui-kit";
import { NotificationTriggersDetailDialog } from "./NotificationTriggersDetailDialog.js";
const ALIGN_POINTS = [
    alignConfigToAlignPoint({
        triggerAlignPoint: "bottom-right",
        overlayAlignPoint: "top-right",
        offset: { x: 2, y: 3 },
    }),
    alignConfigToAlignPoint({
        triggerAlignPoint: "bottom-left",
        overlayAlignPoint: "top-left",
        offset: { x: 2, y: 3 },
    }),
];
const messages = defineMessages({
    triggersTitle: {
        id: "notifications.panel.triggers.title",
    },
});
/**
 * @internal
 */
export function NotificationTriggerDetail({ notification }) {
    const [isTriggersDialogOpen, setIsTriggersDialogOpen] = useState(false);
    const closeTriggersDialog = () => setIsTriggersDialogOpen(false);
    const toggleTriggersDialog = () => setIsTriggersDialogOpen((x) => !x);
    const intl = useIntl();
    const ref = useRef(null);
    const isSliced = notification.details.data.alert.attribute;
    const triggersTitle = isSliced ? getTriggersTitle(intl, notification.details.data.alert) : "";
    return (_jsxs(_Fragment, { children: [
            _jsx(UiButton, { ref: ref, onClick: (e) => {
                    e.stopPropagation();
                    toggleTriggersDialog();
                }, onKeyDown: (e) => {
                    e.stopPropagation();
                }, variant: "tertiary", size: "small", label: triggersTitle, dataId: "notification-detail" }), isTriggersDialogOpen ? (_jsx(Overlay, { isModal: false, alignTo: ref.current, alignPoints: ALIGN_POINTS, closeOnEscape: true, closeOnOutsideClick: true, closeOnParentScroll: false, closeOnMouseDrag: false, onClose: closeTriggersDialog, children: _jsx(NotificationTriggersDetailDialog, { notification: notification, onClose: closeTriggersDialog }) })) : null] }));
}
function getTriggersTitle(intl, alertDescription) {
    return intl.formatMessage(messages.triggersTitle, {
        triggeredCount: alertDescription.triggeredCount,
        totalCount: alertDescription.totalValueCount,
    });
}
//# sourceMappingURL=NotificationTriggersDetail.js.map