"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdaptablePopupBody = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const UIHelper_1 = require("../../../UIHelper");
const AdaptableViewFactory_1 = require("../../../AdaptableViewFactory");
const AdaptablePopupModuleView_1 = require("./AdaptablePopupModuleView");
const AdaptablePopupBody = (props) => {
    const modalContainer = UIHelper_1.UIHelper.getModalContainer(props.api.optionsApi.getAdaptableOptions(), document);
    const moduleName = props.module.moduleInfo.ModuleName;
    const accessLevel = props.api.entitlementApi.getEntitlementAccessLevelForModule(moduleName);
    const moduleInfo = props.api.internalApi.getModuleService().getModuleInfoByModule(moduleName);
    const moduleProps = {
        popupParams: props.moduleParams,
        onClearPopupParams: () => (props.onClearParams ? props.onClearParams() : null),
        onClosePopup: () => {
            if (props.onHide) {
                props.onHide();
            }
        },
        // show share button if TeamSharing is active & user has edit rights
        teamSharingActivated: props.api.teamSharingApi.isTeamSharingAvailable() &&
            props.api.teamSharingApi.hasTeamSharingFullRights(),
        modalContainer: modalContainer,
        accessLevel: accessLevel,
        api: props.api,
        moduleInfo,
    };
    const BodyComponent = AdaptableViewFactory_1.AdaptableViewFactory?.[props?.componentName ?? moduleInfo.Popup] || AdaptablePopupModuleView_1.AdaptablePopupModuleView;
    // key is to make sure state is reset between views
    // most of the views use the `AdaptablePopupModuleView` component
    return React.createElement(BodyComponent, { key: props?.componentName, module: props.module, ...moduleProps });
};
exports.AdaptablePopupBody = AdaptablePopupBody;
