import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2022-2026 GoodData Corporation
import { useCallback } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { ConfirmDialog, Typography } from "@gooddata/sdk-ui-kit";
import { eagerRemoveNestedLayoutSectionItem } from "../../model/commands/layout.js";
import { useDashboardDispatch, useDashboardSelector } from "../../model/react/DashboardStoreProvider.js";
import { dispatchAndWaitFor } from "../../model/store/_infra/dispatchAndWaitFor.js";
import { uiActions } from "../../model/store/ui/index.js";
import { selectIsKpiDeleteDialogOpen, selectKpiDeleteDialogWidgetLayoutPath, } from "../../model/store/ui/uiSelectors.js";
/**
 * @internal
 */
export function useKpiDeleteDialogProps() {
    const dispatch = useDashboardDispatch();
    const layoutPath = useDashboardSelector(selectKpiDeleteDialogWidgetLayoutPath);
    const onCancel = useCallback(() => dispatch(uiActions.closeKpiDeleteDialog()), [dispatch]);
    const onDelete = useCallback(() => {
        if (layoutPath !== undefined) {
            void dispatchAndWaitFor(dispatch, eagerRemoveNestedLayoutSectionItem(layoutPath)).finally(() => {
                dispatch(uiActions.closeKpiDeleteDialog());
            });
        }
    }, [layoutPath, dispatch]);
    const isVisible = useDashboardSelector(selectIsKpiDeleteDialogOpen);
    return {
        isVisible,
        onCancel,
        onDelete,
    };
}
/**
 * @internal
 */
export function DefaultKpiDeleteDialog({ isVisible, onDelete, onCancel, }) {
    const intl = useIntl();
    if (!isVisible) {
        return null;
    }
    return (_jsx(ConfirmDialog, { onCancel: onCancel, onSubmit: onDelete, isPositive: false, className: "s-dialog", headline: intl.formatMessage({ id: "deleteKpiConfirmationDialog.headline" }), cancelButtonText: intl.formatMessage({ id: "cancel" }), submitButtonText: intl.formatMessage({ id: "deleteKpiConfirmationDialog.submitButtonText" }), children: _jsx(Typography, { tagName: "p", children: _jsx(FormattedMessage, { id: "deleteKpiConfirmationDialog.message" }) }) }));
}
//# sourceMappingURL=DefaultKpiDeleteDialog.js.map