"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DashboardToolbarFactory = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_redux_1 = require("react-redux");
const Types_1 = require("../../AdaptableState/Common/Types");
const AdaptableContext_1 = require("../AdaptableContext");
const AdaptableViewFactory_1 = require("../AdaptableViewFactory");
const CustomToolbar_1 = require("./CustomToolbar");
const SystemDashboardToolbarFactory = (props) => {
    const adaptable = (0, AdaptableContext_1.useAdaptable)();
    const moduleInfo = adaptable.api.internalApi
        .getModuleService()
        .getModuleInfoByModule(props.toolbarName);
    const accessLevel = adaptable.api.entitlementApi.getEntitlementAccessLevelForModule(props.toolbarName);
    const moduleToolbarView = AdaptableViewFactory_1.AdaptableViewPanelFactory.get(props.toolbarName);
    if (!moduleToolbarView) {
        return React.createElement(React.Fragment, null);
    }
    const moduleToolbarElement = React.createElement(moduleToolbarView, {
        viewType: 'Toolbar',
        api: adaptable.api,
        accessLevel,
        moduleInfo,
    });
    return moduleToolbarElement;
};
const CustomDashboardToolbarFactory = (props) => {
    const revision = (0, react_redux_1.useSelector)((state) => state.Internal.Dashboard.DashboardRevision);
    const adaptable = (0, AdaptableContext_1.useAdaptable)();
    const customToolbars = adaptable.api.dashboardApi.getCustomToolbars();
    const customToolbar = customToolbars && customToolbars.find((ct) => ct.name == props.toolbarName);
    if (customToolbar) {
        return React.createElement(CustomToolbar_1.CustomToolbarCmp, { customToolbar: customToolbar, dashboardRevision: revision });
    }
    return React.createElement(React.Fragment, null);
};
const DashboardToolbarFactory = (props) => {
    if (Types_1.ALL_MODULES.includes(props.toolbarName)) {
        return React.createElement(SystemDashboardToolbarFactory, { toolbarName: props.toolbarName });
    }
    else {
        return React.createElement(CustomDashboardToolbarFactory, { toolbarName: props.toolbarName });
    }
};
exports.DashboardToolbarFactory = DashboardToolbarFactory;
