"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CellSummaryStatusPanel = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_redux_1 = require("react-redux");
const AdaptableContext_1 = require("../AdaptableContext");
const StatusBarPanel_1 = require("../StatusBar/StatusBarPanel");
const ModuleConstants = tslib_1.__importStar(require("../../Utilities/Constants/ModuleConstants"));
const InternalRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/InternalRedux"));
const CellSummaryStatusBarSubPanelPopover_1 = require("./CellSummaryStatusBarSubPanelPopover");
const CellSummaryStatusPanel = () => {
    const adaptable = (0, AdaptableContext_1.useAdaptable)();
    const dispatch = (0, react_redux_1.useDispatch)();
    const cellSummaryApi = adaptable.api.cellSummaryApi;
    const module = adaptable.ModuleService.getModuleById(ModuleConstants.CellSummaryModuleId);
    const text = `${cellSummaryApi.getCurrentCellSummaryOperation()}: ${cellSummaryApi.getCurrentCellSummaryOperationValue() ?? 'N/A'}`;
    const onAction = () => {
        adaptable.api.cellSummaryApi.openCellSummaryPopupSettingsPanel();
    };
    React.useEffect(() => {
        let cleanupEvent = () => null;
        const checkSelectedCells = () => {
            dispatch(InternalRedux.CreateCellSummaryInfo());
        };
        if (adaptable) {
            cleanupEvent = adaptable._on('CellsSelected', () => {
                checkSelectedCells();
            });
        }
        checkSelectedCells();
        return () => cleanupEvent?.();
    }, []);
    return (React.createElement(StatusBarPanel_1.StatusBarPanel, { tooltip: module.moduleInfo.ModuleName, "data-name": module.moduleInfo.ModuleName, icon: module.moduleInfo.Glyph, onAction: onAction, content: text, popover: CellSummaryStatusBarSubPanelPopover_1.CellSummaryStatusBarSubPanelPopover, popoverMinWidth: 360 }));
};
exports.CellSummaryStatusPanel = CellSummaryStatusPanel;
