"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PinnedToolbarsSelector = 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 DashboardRedux_1 = require("../../Redux/ActionsReducers/DashboardRedux");
const AdaptableContext_1 = require("../AdaptableContext");
const PinnedToolbarsSelector = (props) => {
    const { api } = (0, AdaptableContext_1.useAdaptable)();
    const dashboardAccessLevel = api.entitlementApi.getEntitlementAccessLevelForModule('Dashboard');
    const isDashboardDisabled = dashboardAccessLevel === 'ReadOnly';
    const dashboardState = (0, react_redux_1.useSelector)((state) => state.Dashboard);
    const dispatch = (0, react_redux_1.useDispatch)();
    const pinnedToolbars = dashboardState.PinnedToolbars;
    const toolbars = React.useMemo(() => {
        const systemToolbars = api.dashboardApi.internalApi.getModuleToolbars().map((mt) => ({
            Id: mt.id,
            Title: mt.friendlyName,
        }));
        const customToolbars = api.dashboardApi.getCustomToolbars().map((ct) => ({
            Id: ct.name,
            Title: ct.title ? ct.title : ct.name,
        }));
        return [...systemToolbars, ...customToolbars];
    }, []);
    const tabs = React.useMemo(() => {
        return [
            {
                Name: 'Pinned Toolbars',
                Items: pinnedToolbars ?? [],
            },
        ];
    }, [pinnedToolbars]);
    return (React.createElement(ModuleManager_1.ModuleManager, { permittedActions: {
            createTab: false,
            dragAndDropTab: false,
            deleteTab: false,
            editTabName: false,
        }, onTabsChange: (tabs) => {
            dispatch((0, DashboardRedux_1.DashboardSetPinnedToolbars)(tabs[0].Items));
        }, disabled: isDashboardDisabled, tabs: tabs, availableItems: toolbars, tabsTitle: 'Pinned Toolbars', unusedPanelTitle: "Available Pinned Toolbars", dragItemText: "Drag into the Panel below" }));
};
exports.PinnedToolbarsSelector = PinnedToolbarsSelector;
