import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2019-2026 GoodData Corporation
import { useState } from "react";
import { FormattedMessage } from "react-intl";
import { Message } from "@gooddata/sdk-ui-kit";
import { getAutomationDashboardFilters } from "../../../../../_staging/automation/index.js";
import { AttachmentFilters } from "./AttachmentFilters.js";
import { AttachmentDashboard } from "./AttachmentItems.js";
import { AttachmentsWrapper } from "./AttachmentsWrapper.js";
export function DashboardAttachments({ dashboardSelected, scheduledExportToEdit, areDashboardFiltersChanged, dashboardFilters, isCrossFiltering, filtersToDisplayInfo, onDashboardAttachmentsSelectionChange, enableAutomationFilterContext, overlayPositionType, }) {
    /**
     * When editing a schedule, we need to get the filters from the export definition and we don't care
     * about the actual filters on the dashboard.
     */
    const savedFilters = getAutomationDashboardFilters(scheduledExportToEdit);
    const isEditing = !!scheduledExportToEdit;
    const [attachmentFilterType, setAttachmentFilterType] = useState(
    /**
     * We use "edited" by default when creating a new schedule or editing
     * an existing schedule with filters.
     * "default" is used when editing without filters.
     */
    !isEditing || savedFilters ? "edited" : "default");
    const showAttachmentFilters = enableAutomationFilterContext
        ? false
        : isEditing
            ? attachmentFilterType !== "default"
            : areDashboardFiltersChanged && dashboardSelected;
    const includeFilters = attachmentFilterType === "edited" && areDashboardFiltersChanged;
    const handleAttachmentFilterTypeChange = (type) => {
        const includeFilters = type === "edited" && areDashboardFiltersChanged;
        setAttachmentFilterType(type);
        onDashboardAttachmentsSelectionChange(dashboardSelected, includeFilters ? dashboardFilters : undefined);
    };
    const handleDashboardAttachmentSelectionChange = () => {
        onDashboardAttachmentsSelectionChange(!dashboardSelected, includeFilters ? dashboardFilters : undefined);
    };
    return (_jsx(AttachmentsWrapper, { children: _jsxs("div", { className: "gd-attachment-list-old", children: [
                _jsx(AttachmentDashboard, { disabled: true, pdfSelected: dashboardSelected, onSelectionChange: handleDashboardAttachmentSelectionChange }), _jsx(AttachmentFilters, { filterType: attachmentFilterType, onChange: handleAttachmentFilterTypeChange, hidden: !showAttachmentFilters, disabled: isEditing, filters: filtersToDisplayInfo, overlayPositionType: overlayPositionType }), isCrossFiltering && dashboardSelected ? (_jsx(Message, { type: "progress", className: "gd-attachment-list-message", children: _jsx(FormattedMessage, { id: "dialogs.schedule.management.attachments.message", values: {
                            strong: (chunks) => _jsx("strong", { children: chunks }),
                        } }) })) : null] }) }));
}
//# sourceMappingURL=DashboardAttachments.js.map