"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolbarNotification = ToolbarNotification;
const i18n_1 = __importDefault(require("../../../../locales/i18n.js"));
const react_1 = __importStar(require("react"));
const classnames_1 = __importDefault(require("classnames"));
const cn_ui_1 = require("@cainiaofe/cn-ui");
require("./toolbar-notification.scss");
const notificationConfig = {
    filter: {
        icon: 'filter',
        message: i18n_1.default.get({
            id: 'YouAdjustedTheFilterConfiguratio_268414510',
            dm: '你调整了筛选配置',
        }),
    },
    sort: {
        icon: 'sort',
        message: i18n_1.default.get({ id: 'YouAdjustedTheSortConfiguration', dm: '你调整了排序配置' }),
    },
    group: {
        icon: 'group',
        message: i18n_1.default.get({
            id: 'YouAdjustedTheGroupingConfigurat_1141569657',
            dm: '你调整了分组配置',
        }),
    },
    colorFill: {
        icon: 'color-fill',
        message: i18n_1.default.get({ id: 'YouAdjustedTheFillConfiguration', dm: '你调整了填色配置' }),
    },
};
const savedMessageMap = {
    filter: i18n_1.default.get({ id: 'FilterConfigurationSaved', dm: '筛选配置已保存' }),
    sort: i18n_1.default.get({ id: 'SortConfigurationSaved', dm: '排序配置已保存' }),
    group: i18n_1.default.get({ id: 'GroupingConfigurationSaved', dm: '分组配置已保存' }),
    colorFill: i18n_1.default.get({ id: 'FillConfigurationSaved', dm: '填色配置已保存' }),
};
function ToolbarNotification({ type, visible, closing = false, onCancel, onSave, saveDisabled = false, isCancelled: externalIsCancelled = false, changedCount = 1, }) {
    const config = notificationConfig[type];
    const [isSaved, setIsSaved] = (0, react_1.useState)(false);
    const [internalIsCancelled, setInternalIsCancelled] = (0, react_1.useState)(false);
    // 使用外部传入的 isCancelled 或内部状态
    const isCancelled = externalIsCancelled || internalIsCancelled;
    // 当 visible 变化时重置状态
    (0, react_1.useEffect)(() => {
        if (visible) {
            setIsSaved(false);
            setInternalIsCancelled(false);
        }
    }, [visible]);
    // 当外部 isCancelled 变化时，同步内部状态
    (0, react_1.useEffect)(() => {
        if (externalIsCancelled) {
            setInternalIsCancelled(true);
        }
    }, [externalIsCancelled]);
    const handleSave = () => {
        onSave();
        setIsSaved(true);
        // 保存成功状态由父组件控制隐藏时机
    };
    const handleCancel = () => {
        onCancel();
        setInternalIsCancelled(true);
        // 取消状态由父组件控制隐藏时机
    };
    const showActions = !isSaved && !isCancelled;
    // 多种配置变化时的文案
    const isMultipleChanged = changedCount > 1;
    const multipleChangedMessage = i18n_1.default.get({
        id: 'YouAdjustedMultipleViewConfigura_769060377',
        dm: '你调整了多个视图配置',
    });
    const multipleSavedMessage = i18n_1.default.get({
        id: 'MultipleConfigurationsSaved',
        dm: '多个配置已保存',
    });
    // 计算显示文案
    let displayMessage;
    if (isSaved) {
        displayMessage = isMultipleChanged ? multipleSavedMessage : savedMessageMap[type];
    }
    else {
        displayMessage = isMultipleChanged ? multipleChangedMessage : config.message;
    }
    const wrapperCls = (0, classnames_1.default)('toolbar-notification', {
        'toolbar-notification-visible': visible,
        'toolbar-notification-closing': closing,
        'toolbar-notification-saved': isSaved,
    });
    const messageCls = (0, classnames_1.default)('toolbar-notification-message', {
        'toolbar-notification-message-saved': isSaved,
    });
    return (react_1.default.createElement("div", { className: wrapperCls },
        react_1.default.createElement("div", { className: messageCls },
            isSaved && (react_1.default.createElement(cn_ui_1.CnIcon, { type: "complete", size: 14, className: "toolbar-notification-saved-icon" })),
            displayMessage),
        showActions && (react_1.default.createElement("div", { className: "toolbar-notification-actions" },
            react_1.default.createElement(cn_ui_1.CnButton, { text: true, className: "toolbar-notification-cancel", onClick: handleCancel }, i18n_1.default.get({ id: 'Cancel', dm: '取消' })),
            react_1.default.createElement("div", { className: "toolbar-notification-divider" }),
            react_1.default.createElement(cn_ui_1.CnButton, { text: true, className: "toolbar-notification-save", disabled: saveDisabled, onClick: handleSave }, i18n_1.default.get({ id: 'Save', dm: '保存' }))))));
}
