import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2019-2026 GoodData Corporation
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import cx from "classnames";
import { defineMessage, useIntl } from "react-intl";
import { ValidationContextStore, createInvalidNode, useValidationContextValue } from "@gooddata/sdk-ui";
import { Button, ConfirmDialogBase, ContentDivider, Hyperlink, Message, Overlay, OverlayController, OverlayControllerProvider, RecurrenceForm, ScrollablePanel, UiIcon, UiTabs, isEnterKey, useIdPrefixed, } from "@gooddata/sdk-ui-kit";
import { useDashboardSelector } from "../../../model/react/DashboardStoreProvider.js";
import { useExportTemplates } from "../../../model/react/useExportTemplates.js";
import { selectDateFormat, selectEnableAutomationFilterContext, selectEnableAutomationManagement, selectEnableCustomizableCsvDelimiter, selectEnableNewScheduledExport, selectExternalRecipient, selectIsWhiteLabeled, selectLocale, selectSettings, selectWeekStart, } from "../../../model/store/config/configSelectors.js";
import { selectIsCrossFiltering } from "../../../model/store/drill/drillSelectors.js";
import { selectEntitlementMinimumRecurrenceMinutes, selectMaxAutomationRecipients, } from "../../../model/store/entitlements/entitlementsSelectors.js";
import { selectDashboardTitle } from "../../../model/store/meta/metaSelectors.js";
import { selectIsAutomationDialogSecondaryTitleVisible } from "../../../model/store/topBar/topBarSelectors.js";
import { selectExecutionTimestamp } from "../../../model/store/ui/uiSelectors.js";
import { getWidgetTitle } from "../../../model/utils/dashboardItemUtils.js";
import { ApplyCurrentFiltersConfirmDialog } from "../../automationFilters/components/ApplyLatestFiltersConfirmDialog.js";
import { AutomationFiltersSelect } from "../../automationFilters/components/AutomationFiltersSelect.js";
import { useValidateExistingAutomationFilters } from "../../automationFilters/hooks/useValidateExistingAutomationFilters.js";
import { getAvailableFiltersFromFiltersByTab, useAutomationFiltersSelect, } from "../../automationFilters/useAutomationFiltersSelect.js";
import { validateAllFilterLocalIdentifiers } from "../../automationFilters/utils.js";
import { DASHBOARD_DIALOG_OVERS_Z_INDEX } from "../../constants/zIndex.js";
import { IntlWrapper } from "../../localization/IntlWrapper.js";
import { DeleteScheduleConfirmDialog } from "../DefaultScheduledEmailManagementDialog/components/DeleteScheduleConfirmDialog.js";
import { useScheduleEmailDialogAccessibility } from "../hooks/useScheduleEmailDialogAccessibility.js";
import { getDefaultCronExpression } from "../utils/cron.js";
import { getDefaultPdfPageSize } from "../utils/pdfPageSize.js";
import { isMobileView } from "../utils/responsive.js";
import { TIMEZONE_DEFAULT } from "../utils/timezone.js";
import { DashboardAttachments } from "./components/Attachments/DashboardAttachments.js";
import { WidgetAttachments } from "./components/Attachments/WidgetAttachments.js";
import { DashboardAttachments as DashboardAttachmentsOld } from "./components/AttachmentsOld/DashboardAttachments.js";
import { WidgetAttachments as WidgetAttachmentsOld } from "./components/AttachmentsOld/WidgetAttachments.js";
import { DestinationSelect } from "./components/DestinationSelect/DestinationSelect.js";
import { EvaluationModeCheckbox } from "./components/EvaluationModeCheckbox/EvaluationModeCheckbox.js";
import { ScheduledEmailDialogHeader } from "./components/Header/ScheduleEmailDialogHeader.js";
import { MessageForm } from "./components/MessageForm/MessageForm.js";
import { RecipientsSelect } from "./components/RecipientsSelect/RecipientsSelect.js";
import { SubjectForm } from "./components/SubjectForm/SubjectForm.js";
import { SCHEDULED_EMAIL_DIALOG_ID } from "./constants.js";
import { DefaultLoadingScheduledEmailDialog } from "./DefaultLoadingScheduledEmailDialog.js";
import { useEditScheduledEmail } from "./hooks/useEditScheduledEmail.js";
import { useFiltersForDashboardScheduledExportInfo } from "./hooks/useFiltersForDashboardScheduledExportInfo.js";
import { useSaveScheduledEmailToBackend } from "./hooks/useSaveScheduledEmailToBackend.js";
const DEFAULT_MIN_RECURRENCE_MINUTES = "60";
const OVERLAY_POSITION_TYPE = "sameAsTarget";
const CLOSE_ON_PARENT_SCROLL = true;
const overlayController = OverlayController.getInstance(DASHBOARD_DIALOG_OVERS_Z_INDEX);
function ScheduledEmailDialogFooter({ isWhiteLabeled, helpTextId, scheduledExportToEdit, isSavingScheduledEmail, onDeleteClick, }) {
    const intl = useIntl();
    return (_jsxs("div", { className: "gd-notifications-channels-dialog-footer-link", children: [isWhiteLabeled ? null : (_jsx(Hyperlink, { text: intl.formatMessage({ id: helpTextId }), href: "https://www.gooddata.com/docs/cloud/create-dashboards/automation/scheduled-exports/#ScheduleExportsinDashboards-ScheduleExport", iconClass: "gd-icon-circle-question" })), scheduledExportToEdit ? (_jsx(Button, { className: "gd-button-link-dimmed", value: intl.formatMessage({ id: "delete" }), onClick: onDeleteClick, disabled: isSavingScheduledEmail })) : null] }));
}
export function ScheduledMailDialogRenderer({ scheduledExportToEdit, users, usersError, notificationChannels, insight, widget, dashboardFilters, widgetFilters, onBack, onCancel, onDeleteSuccess, onDeleteError, onError, onSave, onSaveError, onSaveSuccess, onSubmit, onSuccess, }) {
    const intl = useIntl();
    const dialogTitleRef = useRef(null);
    const generalTabContentRef = useRef(null);
    const filtersTabContentRef = useRef(null);
    const [scheduledEmailToDelete, setScheduledEmailToDelete] = useState(null);
    const [selectedTabId, setSelectedTabId] = useState("general");
    const [tabContentHeight, setTabContentHeight] = useState(undefined);
    const isWhiteLabeled = useDashboardSelector(selectIsWhiteLabeled);
    const externalRecipientOverride = useDashboardSelector(selectExternalRecipient);
    const isSecondaryTitleVisible = useDashboardSelector(selectIsAutomationDialogSecondaryTitleVisible);
    const enableAutomationManagement = useDashboardSelector(selectEnableAutomationManagement);
    const exportTemplates = useExportTemplates();
    const handleScheduleDeleteSuccess = () => {
        onDeleteSuccess?.();
        setScheduledEmailToDelete(null);
    };
    const { editedAutomationFilters, setEditedAutomationFilters, storeFilters, setStoreFilters, availableFilters, availableFiltersAsVisibleFilters, filtersForNewAutomation, 
    // filter by tab data
    filtersByTab, editedAutomationFiltersByTab, setEditedAutomationFiltersByTab, availableFiltersAsVisibleFiltersByTab, } = useAutomationFiltersSelect({
        automationToEdit: scheduledExportToEdit,
        widget,
    });
    const { locale, dashboardTitle, dateFormat, weekStart, maxAutomationsRecipients, allowHourlyRecurrence, isCrossFiltering, isExecutionTimestampMode, enableAutomationFilterContext, enableNewScheduledExport, enableCustomizableCsvDelimiter, defaultPdfPageSize, } = useDefaultScheduledEmailDialogData({
        filters: availableFilters ?? [],
        filtersByTab: getAvailableFiltersFromFiltersByTab(filtersByTab),
    });
    const { defaultUser, editedAutomation, originalAutomation, isSubmitDisabled, xlsxSettings, pdfSettings, csvSettings, csvRawSettings, startDate, allowExternalRecipients, allowOnlyLoggedUserRecipients, isDashboardExportSelected, isCsvExportSelected, isXlsxExportSelected, areDashboardFiltersChanged, validationErrorMessage, selectedAttachments, isParentValid, onDashboardAttachmentsChange, onDashboardAttachmentsChangeOld, onWidgetAttachmentsChange, onWidgetAttachmentsChangeOld, onXlsxSettingsChange, onPdfSettingsChange, onCsvSettingsChange, onCsvRawSettingsChange, slidesTemplateIds, onSlidesTemplateIdChange, onDestinationChange, onMessageChange, onRecipientsChange, onRecurrenceChange, onEvaluationModeChange, onSubjectChange, onTitleChange, onFiltersChange, onApplyCurrentFilters, onStoreFiltersChange, onFiltersByTabChange, enableAutomationEvaluationMode, } = useEditScheduledEmail({
        notificationChannels,
        insight,
        widget,
        scheduledExportToEdit,
        storeFilters,
        editedAutomationFilters,
        dashboardFilters,
        widgetFilters,
        maxAutomationsRecipients,
        setEditedAutomationFilters,
        setStoreFilters,
        availableFiltersAsVisibleFilters,
        enableAutomationFilterContext,
        filtersForNewAutomation,
        externalRecipientOverride,
        enableNewScheduledExport,
        filtersDataByTab: filtersByTab,
        editedAutomationFiltersByTab,
        setEditedAutomationFiltersByTab,
        availableFiltersAsVisibleFiltersByTab,
    });
    const { isValid } = useValidateExistingAutomationFilters({
        automationToEdit: scheduledExportToEdit,
        widget,
        insight,
        enableAutomationFilterContext,
    });
    const [isApplyCurrentFiltersDialogOpen, setIsApplyCurrentFiltersDialogOpen] = useState(!isValid);
    const { handleSaveScheduledEmail, isSavingScheduledEmail, savingErrorMessage } = useSaveScheduledEmailToBackend(editedAutomation, {
        onSuccess,
        onError,
        onSubmit,
        onSaveSuccess,
        onSaveError,
        onSave,
    });
    const { returnFocusTo } = useScheduleEmailDialogAccessibility();
    const missingAttachmentsErrorMessage = selectedAttachments.length === 0 &&
        intl.formatMessage({ id: "scheduledEmail.attachments.error.noAttachmentsSelected" });
    const validationContextValue = useValidationContextValue(createInvalidNode({ id: "ScheduledEmailDialog" }));
    const { getInvalidDatapoints } = validationContextValue;
    const errorMessage = savingErrorMessage ?? validationErrorMessage ?? missingAttachmentsErrorMessage;
    const dashboardScheduledExportFiltersInfo = useFiltersForDashboardScheduledExportInfo({
        effectiveFilters: dashboardFilters,
    });
    const helpTextId = isMobileView()
        ? defineMessage({ id: "dialogs.schedule.email.footer.title.short" }).id
        : defineMessage({ id: "dialogs.schedule.email.footer.title" }).id;
    const titleElementId = useIdPrefixed("title");
    const submitDisabled = isSubmitDisabled || isSavingScheduledEmail || isExecutionTimestampMode;
    const handleSubmitForm = useCallback((e) => {
        if (isEnterKey(e) && !submitDisabled) {
            handleSaveScheduledEmail();
        }
    }, [submitDisabled, handleSaveScheduledEmail]);
    const { secondaryTitle, secondaryTitleIcon } = useMemo(() => {
        if (widget) {
            return {
                secondaryTitle: getWidgetTitle(widget),
                secondaryTitleIcon: (_jsx(UiIcon, { type: "visualization", size: 16, color: "complementary-6", accessibilityConfig: {
                        ariaLabel: intl.formatMessage({
                            id: "dialogs.automation.icon.ariaLabel.sourceVisualization",
                        }),
                    } })),
            };
        }
        return {
            secondaryTitle: dashboardTitle,
            secondaryTitleIcon: (_jsx(UiIcon, { type: "dashboard", size: 16, color: "complementary-6", accessibilityConfig: {
                    ariaLabel: intl.formatMessage({
                        id: "dialogs.automation.icon.ariaLabel.sourceDashboard",
                    }),
                } })),
        };
    }, [widget, dashboardTitle, intl]);
    const tabs = useMemo(() => {
        const tabsList = [
            {
                id: "general",
                label: intl.formatMessage({ id: "dialogs.schedule.email.tabs.general" }),
            },
        ];
        // Only show Filters tab when automation filter context is enabled
        if (enableAutomationFilterContext) {
            tabsList.push({
                id: "filters",
                label: intl.formatMessage({ id: "dialogs.schedule.email.tabs.filters" }),
            });
        }
        return tabsList;
    }, [intl, enableAutomationFilterContext]);
    const handleTabSelect = useCallback((tab) => {
        setSelectedTabId(tab.id);
    }, []);
    // Reset to General tab if Filters tab is not available
    useEffect(() => {
        if (!enableAutomationFilterContext && selectedTabId === "filters") {
            setSelectedTabId("general");
        }
    }, [enableAutomationFilterContext, selectedTabId]);
    // Measure General tab content height to maintain consistent dialog size
    useEffect(() => {
        if (enableAutomationFilterContext && generalTabContentRef.current && selectedTabId === "general") {
            // Use requestAnimationFrame to ensure DOM is fully rendered
            requestAnimationFrame(() => {
                if (generalTabContentRef.current) {
                    const height = generalTabContentRef.current.scrollHeight;
                    setTabContentHeight(height);
                }
            });
        }
    }, [enableAutomationFilterContext, selectedTabId]);
    // This should be visible only when enableAutomationFilterContext is true
    if (isApplyCurrentFiltersDialogOpen && enableAutomationFilterContext) {
        return (_jsx(ApplyCurrentFiltersConfirmDialog, { automationType: "schedule", onCancel: () => onCancel?.(), onEdit: () => {
                onApplyCurrentFilters();
                setIsApplyCurrentFiltersDialogOpen(false);
            } }));
    }
    const selectedChannel = notificationChannels.find((channel) => channel.id === editedAutomation.notificationChannel);
    const isInPlatformChannel = selectedChannel?.destinationType === "inPlatform";
    return (_jsxs(_Fragment, { children: [
            _jsx(Overlay, { className: "gd-notifications-channels-dialog-overlay", isModal: true, positionType: "fixed", ensureVisibility: true, children: _jsx(OverlayControllerProvider, { overlayController: overlayController, children: _jsx(ValidationContextStore, { value: validationContextValue, children: _jsxs(ConfirmDialogBase, { className: cx("gd-notifications-channels-dialog s-gd-notifications-channels-dialog", {
                                "gd-dialog--wide gd-notifications-channels-dialog--wide": enableAutomationManagement,
                            }), isPositive: true, cancelButtonText: intl.formatMessage({ id: "cancel" }), submitButtonText: scheduledExportToEdit
                                ? intl.formatMessage({ id: `dialogs.schedule.email.save` })
                                : intl.formatMessage({ id: `dialogs.schedule.email.create` }), accessibilityConfig: {
                                closeButton: {
                                    ariaLabel: intl.formatMessage({
                                        id: "dialogs.schedule.email.closeLabel",
                                    }),
                                },
                                titleElementId,
                                dialogId: SCHEDULED_EMAIL_DIALOG_ID,
                            }, showProgressIndicator: isSavingScheduledEmail, returnFocusTo: returnFocusTo, returnFocusAfterClose: !enableAutomationManagement, footerLeftRenderer: () => (_jsx(ScheduledEmailDialogFooter, { isWhiteLabeled: isWhiteLabeled, helpTextId: helpTextId, scheduledExportToEdit: scheduledExportToEdit, isSavingScheduledEmail: isSavingScheduledEmail, onDeleteClick: () => setScheduledEmailToDelete(editedAutomation) })), isSubmitDisabled: submitDisabled, submitButtonTooltipText: isExecutionTimestampMode
                                ? intl.formatMessage({
                                    id: "dialogs.schedule.email.save.executionTimestampMode",
                                })
                                : undefined, initialFocus: dialogTitleRef, submitOnEnterKey: false, onCancel: onCancel, onSubmit: handleSaveScheduledEmail, headline: undefined, headerLeftButtonRenderer: () => (_jsx(ScheduledEmailDialogHeader, { title: editedAutomation.title ?? "", onChange: onTitleChange, onBack: onBack, placeholder: intl.formatMessage({
                                    id: "dialogs.schedule.email.title.placeholder",
                                }), ref: dialogTitleRef, onKeyDownSubmit: handleSubmitForm, secondaryTitle: secondaryTitle, secondaryTitleIcon: secondaryTitleIcon, isSecondaryTitleVisible: isSecondaryTitleVisible ? isParentValid : undefined })), children: [
                                _jsx("h2", { className: "sr-only", id: titleElementId, children: intl.formatMessage({ id: "dialogs.schedule.email.accessibilityTitle" }) }), tabs.length > 1 ? (_jsx(UiTabs, { tabs: tabs, selectedTabId: selectedTabId, onTabSelect: handleTabSelect, size: "medium", accessibilityConfig: {
                                        role: "tablist",
                                        tabRole: "tab",
                                        ariaLabel: intl.formatMessage({
                                            id: "dialogs.schedule.email.accessibilityTitle",
                                        }),
                                    }, disableBottomBorder: true })) : null, _jsxs(ScrollablePanel, { className: cx("gd-notifications-channel-dialog-content-wrapper", {
                                        "gd-notification-channel-dialog-with-automation-filters": enableAutomationFilterContext,
                                        "gd-notification-channel-dialog-with-tabs": tabs.length > 1,
                                    }), children: [
                                        _jsx("div", { className: "gd-divider-with-margin" }), enableAutomationFilterContext && selectedTabId === "filters" ? (_jsx("div", { ref: filtersTabContentRef, className: "gd-schedule-dialog-tab-content", style: tabContentHeight
                                                ? { minHeight: `${tabContentHeight}px` }
                                                : undefined, children: _jsx(AutomationFiltersSelect, { availableFilters: availableFilters, selectedFilters: editedAutomationFilters, onFiltersChange: onFiltersChange, storeFilters: storeFilters, onStoreFiltersChange: onStoreFiltersChange, isDashboardAutomation: isDashboardExportSelected, overlayPositionType: OVERLAY_POSITION_TYPE, hideTitle: true, showAllFilters: true, filtersByTab: filtersByTab, editedFiltersByTab: editedAutomationFiltersByTab, onFiltersByTabChange: onFiltersByTabChange }) })) : (_jsxs("div", { ref: generalTabContentRef, className: "gd-schedule-dialog-tab-content", children: [enableAutomationFilterContext ? (_jsx(Message, { type: "progress", className: "gd-schedule-dialog-tab-content-info", children: intl.formatMessage({
                                                        id: "dialogs.schedule.email.tabs.info",
                                                    }) })) : null, _jsx(RecurrenceForm, { startDate: startDate, cronExpression: editedAutomation.schedule?.cron ??
                                                        getDefaultCronExpression(startDate), cronDescription: editedAutomation.schedule?.cronDescription, timezone: editedAutomation.schedule?.timezone ??
                                                        TIMEZONE_DEFAULT.identifier, dateFormat: dateFormat ?? "MM/dd/yyyy", locale: locale, weekStart: weekStart, onChange: onRecurrenceChange, allowHourlyRecurrence: allowHourlyRecurrence, isWhiteLabeled: isWhiteLabeled, closeDropdownsOnParentScroll: CLOSE_ON_PARENT_SCROLL, onKeyDownSubmit: handleSubmitForm }), _jsx(ContentDivider, { className: "gd-divider-with-margin" }), _jsx(DestinationSelect, { notificationChannels: notificationChannels, selectedItemId: editedAutomation.notificationChannel, onChange: onDestinationChange, closeOnParentScroll: CLOSE_ON_PARENT_SCROLL, overlayPositionType: OVERLAY_POSITION_TYPE }), _jsx(ContentDivider, { className: "gd-divider-with-margin" }), _jsx(RecipientsSelect, { id: "schedule.email.recipients", loggedUser: defaultUser, users: users, usersError: usersError, value: editedAutomation.recipients ?? [], originalValue: originalAutomation.recipients || [], onChange: onRecipientsChange, allowEmptySelection: true, allowOnlyLoggedUserRecipients: allowOnlyLoggedUserRecipients, allowExternalRecipients: allowExternalRecipients, maxRecipients: maxAutomationsRecipients, notificationChannels: notificationChannels, notificationChannelId: editedAutomation.notificationChannel, onKeyDownSubmit: handleSubmitForm, externalRecipientOverride: externalRecipientOverride }), isInPlatformChannel ? null : (_jsxs(_Fragment, { children: [
                                                        _jsx(SubjectForm, { dashboardTitle: dashboardTitle, editedAutomation: editedAutomation, onChange: onSubjectChange, onKeyDownSubmit: handleSaveScheduledEmail, isSubmitDisabled: isSubmitDisabled }), _jsx(MessageForm, { onChange: onMessageChange, value: editedAutomation.details?.message ?? "" })
                                                    ] })), widget ? (enableNewScheduledExport ? (_jsx(WidgetAttachments, { selectedAttachments: selectedAttachments, onWidgetAttachmentsChange: onWidgetAttachmentsChange, xlsxSettings: xlsxSettings, pdfSettings: pdfSettings, onXlsxSettingsChange: onXlsxSettingsChange, onPdfSettingsChange: onPdfSettingsChange, csvSettings: csvSettings, onCsvSettingsChange: onCsvSettingsChange, csvRawSettings: csvRawSettings, onCsvRawSettingsChange: onCsvRawSettingsChange, isCsvSettingsEnabled: enableCustomizableCsvDelimiter, defaultPdfPageSize: defaultPdfPageSize, exportTemplates: exportTemplates, slidesTemplateIds: slidesTemplateIds, onSlidesTemplateIdChange: onSlidesTemplateIdChange })) : (_jsx(WidgetAttachmentsOld, { widgetFilters: widgetFilters, areDashboardFiltersChanged: areDashboardFiltersChanged, isCrossFiltering: isCrossFiltering, scheduledExportToEdit: scheduledExportToEdit, csvSelected: isCsvExportSelected, xlsxSelected: isXlsxExportSelected, settings: xlsxSettings, onWidgetAttachmentsSelectionChange: onWidgetAttachmentsChangeOld, onAttachmentsSettingsChange: onXlsxSettingsChange, enableAutomationFilterContext: enableAutomationFilterContext, closeOnParentScroll: CLOSE_ON_PARENT_SCROLL, overlayPositionType: OVERLAY_POSITION_TYPE }))) : enableNewScheduledExport ? (_jsx(DashboardAttachments, { selectedAttachments: selectedAttachments, dashboardFilters: dashboardFilters, isCrossFiltering: isCrossFiltering, onDashboardAttachmentsChange: onDashboardAttachmentsChange, xlsxSettings: xlsxSettings, onXlsxSettingsChange: onXlsxSettingsChange, defaultPdfPageSize: defaultPdfPageSize, exportTemplates: exportTemplates, slidesTemplateIds: slidesTemplateIds, onSlidesTemplateIdChange: onSlidesTemplateIdChange })) : (_jsx(DashboardAttachmentsOld, { dashboardSelected: isDashboardExportSelected, scheduledExportToEdit: scheduledExportToEdit, areDashboardFiltersChanged: areDashboardFiltersChanged, dashboardFilters: dashboardFilters, isCrossFiltering: isCrossFiltering, filtersToDisplayInfo: dashboardScheduledExportFiltersInfo, onDashboardAttachmentsSelectionChange: onDashboardAttachmentsChangeOld, enableAutomationFilterContext: enableAutomationFilterContext })), enableAutomationEvaluationMode ? (_jsx(EvaluationModeCheckbox, { isShared: editedAutomation.evaluationMode === "SHARED", onChange: onEvaluationModeChange })) : null, errorMessage ? (_jsx(Message, { type: "error", className: cx("gd-notifications-channels-dialog-error", {
                                                        "gd-notifications-channels-dialog-error-scrollable": enableAutomationFilterContext,
                                                    }), children: errorMessage })) : null, getInvalidDatapoints()
                                                    .filter((invalidDatapoint) => invalidDatapoint.severity === "error")
                                                    .map((invalidDatapoint) => (_jsx(Message, { id: invalidDatapoint.id, type: "error", className: cx("gd-notifications-channels-dialog-error", {
                                                        "gd-notifications-channels-dialog-error-scrollable": enableAutomationFilterContext,
                                                    }), children: invalidDatapoint.message }, invalidDatapoint.id)))] }))] })
                            ] }) }) }) }), scheduledEmailToDelete ? (_jsx(DeleteScheduleConfirmDialog, { scheduledEmail: scheduledEmailToDelete, onCancel: () => setScheduledEmailToDelete(null), onSuccess: handleScheduleDeleteSuccess, onError: onDeleteError })) : null] }));
}
/**
 * @alpha
 */
export function DefaultScheduledEmailDialog(props) {
    const { isLoading, onCancel, scheduledExportToEdit } = props;
    const locale = useDashboardSelector(selectLocale);
    if (isLoading) {
        return (_jsx(DefaultLoadingScheduledEmailDialog, { onCancel: onCancel, scheduledExportToEdit: scheduledExportToEdit }));
    }
    return (_jsx(IntlWrapper, { locale: locale, children: _jsx(ScheduledMailDialogRenderer, { ...props }) }));
}
function useDefaultScheduledEmailDialogData({ filters, filtersByTab, }) {
    const locale = useDashboardSelector(selectLocale);
    const dashboardTitle = useDashboardSelector(selectDashboardTitle);
    const dateFormat = useDashboardSelector(selectDateFormat);
    const settings = useDashboardSelector(selectSettings);
    const formatLocale = settings?.formatLocale;
    const weekStart = useDashboardSelector(selectWeekStart);
    const maxAutomationsRecipients = useDashboardSelector(selectMaxAutomationRecipients);
    const minimumRecurrenceMinutesEntitlement = useDashboardSelector(selectEntitlementMinimumRecurrenceMinutes);
    const allowHourlyRecurrence = parseInt(minimumRecurrenceMinutesEntitlement?.value ?? DEFAULT_MIN_RECURRENCE_MINUTES, 10) === 60;
    const isCrossFiltering = useDashboardSelector(selectIsCrossFiltering);
    const isExecutionTimestampMode = !!useDashboardSelector(selectExecutionTimestamp);
    const enableAutomationFilterContextFlag = useDashboardSelector(selectEnableAutomationFilterContext);
    const enableAutomationFilterContext = useMemo(() => {
        const doAllDashboardFiltersHaveLocalIdentifiers = validateAllFilterLocalIdentifiers(filters);
        const doAllDashboardFiltersByTabHaveLocalIdentifiers = Object.values(filtersByTab).every((tabFilters) => validateAllFilterLocalIdentifiers(tabFilters));
        return (enableAutomationFilterContextFlag &&
            doAllDashboardFiltersHaveLocalIdentifiers &&
            doAllDashboardFiltersByTabHaveLocalIdentifiers);
    }, [filters, filtersByTab, enableAutomationFilterContextFlag]);
    const enableNewScheduledExport = useDashboardSelector(selectEnableNewScheduledExport);
    const enableCustomizableCsvDelimiter = useDashboardSelector(selectEnableCustomizableCsvDelimiter);
    const defaultPdfPageSize = getDefaultPdfPageSize(formatLocale);
    return {
        locale,
        dashboardTitle,
        dateFormat,
        weekStart,
        maxAutomationsRecipients,
        allowHourlyRecurrence,
        isCrossFiltering,
        isExecutionTimestampMode,
        enableAutomationFilterContext,
        enableNewScheduledExport,
        enableCustomizableCsvDelimiter,
        defaultPdfPageSize,
    };
}
//# sourceMappingURL=DefaultScheduledEmailDialog.js.map