"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StatusBarPopup = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_redux_1 = require("react-redux");
const ModuleManager_1 = require("../../components/DragAndDropContext/ModuleManager");
const EmptyContent_1 = tslib_1.__importDefault(require("../../components/EmptyContent"));
const Types_1 = require("../../AdaptableState/Common/Types");
const StatusBarRedux_1 = require("../../Redux/ActionsReducers/StatusBarRedux");
const AdaptableContext_1 = require("../AdaptableContext");
const PopupPanel_1 = require("../Components/Popups/AdaptablePopup/PopupPanel");
const StatusBarPopup = (props) => {
    const statusPanels = (0, react_redux_1.useSelector)(StatusBarRedux_1.getStatusPanelsSelector);
    const adaptable = (0, AdaptableContext_1.useAdaptable)();
    const tabs = React.useMemo(() => statusPanels.map((statusPanel) => {
        return {
            Name: statusPanel.Key,
            Items: statusPanel.StatusBarPanels,
        };
    }), [statusPanels]);
    const handleTabChange = React.useCallback((tabs) => {
        const newStatusPanels = tabs.map((tab) => {
            const statusPanel = statusPanels.find((sp) => sp.Key === tab.Name);
            return {
                ...statusPanel,
                StatusBarPanels: tab.Items,
            };
        });
        adaptable.api.statusBarApi.setStatusBarPanels(newStatusPanels);
    }, [statusPanels]);
    const availableItems = Types_1.ALL_STATUS_SUB_PANELS.filter((panel) => {
        const module = adaptable.ModuleService.getModuleById(panel);
        return module?.isModuleVisible();
    }).map((panel) => {
        const module = adaptable.ModuleService.getModuleById(panel);
        return { Id: panel, Title: module.moduleInfo.FriendlyName };
    });
    const disabled = props.accessLevel === 'ReadOnly';
    return (React.createElement(PopupPanel_1.PopupPanel, { headerText: props.moduleInfo.FriendlyName, glyphicon: props.moduleInfo.Glyph, infoLink: props.moduleInfo.HelpPage, infoLinkDisabled: !props.api.internalApi.isDocumentationLinksDisplayed() }, statusPanels.length ? (React.createElement(ModuleManager_1.ModuleManager, { permittedActions: {
            createTab: false,
            dragAndDropTab: false,
            deleteTab: false,
            editTabName: false,
        }, onTabsChange: handleTabChange, disabled: disabled, tabs: tabs, availableItems: availableItems, tabsTitle: 'AdapTable Status Bar Panels', unusedPanelTitle: "Available Status Bar Components", dragItemText: "Drag into a Status Bar Panel below" })) : (React.createElement(EmptyContent_1.default, null, "To enable this feature add to Grid Options statusPanels the Adaptable Status Panel."))));
};
exports.StatusBarPopup = StatusBarPopup;
