import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2023-2026 GoodData Corporation
import { useCallback, useState } from "react";
import { messages } from "../../../../locales.js";
import { useDashboardSelector } from "../../../../model/react/DashboardStoreProvider.js";
import { selectBackendCapabilities } from "../../../../model/store/backendCapabilities/backendCapabilitiesSelectors.js";
import { ConfigurationCategory } from "../../configuration/ConfigurationCategory.js";
import { ConfigModeSelect } from "../../configuration/ConfigurationModeSelect.js";
import { ConfigurationPanelHeader } from "../../configuration/ConfigurationPanelHeader.js";
import { AttributeTitleRenaming } from "../../configuration/title/AttributeTitleRenaming.js";
import { useDateFilterConfig } from "../useDateFilterConfig.js";
import { DateFilterConfigurationActions } from "./DateFilterConfigurationActions.js";
export function DateFilterConfigurationBody({ onCancelButtonClick, onSaveButtonClick, intl, dateDataSet, defaultDateFilterName, }) {
    const { mode, changeConfigMode, title, titleChanged, onConfigurationClose, onTitleChange, onTitleReset, onTitleUpdate, } = useDateFilterConfig(dateDataSet, defaultDateFilterName);
    const originConfigMode = mode;
    const capabilities = useDashboardSelector(selectBackendCapabilities);
    const [selectedMode, setSelectedMode] = useState(originConfigMode);
    const onConfigurationSave = useCallback(() => {
        onSaveButtonClick();
        if (capabilities.supportsMultipleDateFilters) {
            onTitleChange();
        }
        if (capabilities.supportsHiddenAndLockedFiltersOnUI) {
            changeConfigMode(selectedMode);
        }
    }, [
        selectedMode,
        onTitleChange,
        onSaveButtonClick,
        capabilities.supportsMultipleDateFilters,
        capabilities.supportsHiddenAndLockedFiltersOnUI,
        changeConfigMode,
    ]);
    const onCancel = useCallback(() => {
        onCancelButtonClick();
        onConfigurationClose();
    }, [onCancelButtonClick, onConfigurationClose]);
    const onStateChange = useCallback((opt) => {
        setSelectedMode(opt);
    }, []);
    const modeCategoryTitle = intl.formatMessage(messages.filterConfigurationModeTitle);
    const headerText = intl.formatMessage(messages.dateFilterDropdownConfigurationHeader);
    const cancelText = intl.formatMessage(messages.dateFilterDropdownConfigurationCancelText);
    const saveText = intl.formatMessage(messages.dateFilterDropdownConfigurationSaveText);
    const titleText = intl.formatMessage(messages.filterConfigurationTitleTitle);
    const resetTitleText = intl.formatMessage(messages.filterConfigurationTitleReset);
    const showResetTitle = title !== defaultDateFilterName;
    const isTitleDefined = !!title && title.trim().length > 0;
    const isSaveDisabled = isTitleDefined ? selectedMode === originConfigMode && !titleChanged : true;
    const titleConfig = capabilities.supportsMultipleDateFilters ? (_jsx(AttributeTitleRenaming, { categoryTitle: titleText, resetTitleText: resetTitleText, onClick: onTitleReset, onChange: onTitleUpdate, showResetTitle: showResetTitle, attributeTitle: title ?? defaultDateFilterName })) : null;
    const modeConfig = capabilities.supportsHiddenAndLockedFiltersOnUI ? (_jsxs("div", { children: [
            _jsx("div", { className: "configuration-category-title", children: _jsx(ConfigurationCategory, { categoryTitle: modeCategoryTitle }) }), _jsx(ConfigModeSelect, { intl: intl, selectedMode: selectedMode, onChanged: onStateChange })
        ] })) : null;
    return (_jsx("div", { className: "gd-extended-date-filter-container", children: _jsxs("div", { className: "gd-extended-date-filter-body s-extended-date-filters-body", children: [
                _jsxs("div", { className: "s-date-filter-dropdown-configuration date-filter-dropdown-configuration sdk-edit-mode-on", children: [
                        _jsx(ConfigurationPanelHeader, { headerText: headerText }), titleConfig, modeConfig] }), _jsx(DateFilterConfigurationActions, { cancelText: cancelText, saveText: saveText, onCancelButtonClick: onCancel, onSaveButtonClick: onConfigurationSave, isSaveDisabled: isSaveDisabled })
            ] }) }));
}
//# sourceMappingURL=DateFilterConfigurationBody.js.map