import React, { useMemo } from 'react';
import { useAxiosGet } from '../utilities/useAxiosGet';
import { makeStyles } from '@material-ui/core';
import { PageContainer } from '../page/PageContainer';
import { useUser } from '../utilities/auth/useUser';
import { APP_RIBBON_SPACE, useBuildEnvironment } from '../shell/ui/useBuildEnvironment';
import { UnitTypeEnums } from '../enums/workflowEnums';
import { WorkflowUiInterruptContent } from './WorkflowUiInterruptContent';
import { SmsDisplay } from '../UI/components/dataDisplay/SmsDisplay';
import { EmailDisplay } from '../UI/components/dataDisplay/EmailDisplay';
import { ConfigService } from '../configService';
const useStyles = makeStyles((theme) => ({
    root: {
        height: '100%'
    }
}));
export const WorkflowContent = (props) => {
    var _a, _b, _c, _d;
    const { selectedNode, workflow, reloadWorkflow, users, groups, handleClose, inquiryPageParams = {} } = props;
    const buildEnv = useBuildEnvironment();
    const classes = useStyles(Object.assign(Object.assign({}, props), { appRibbonSpace: buildEnv ? APP_RIBBON_SPACE : 0 }));
    const user = useUser();
    const [{ data: pageData, loading: pageLoading, error: pageError }] = useAxiosGet(ConfigService.tenantV1ApiUrl, `page/${(_b = (_a = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _a === void 0 ? void 0 : _a.page) === null || _b === void 0 ? void 0 : _b.id}`, {}, !!!((_d = (_c = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _c === void 0 ? void 0 : _c.page) === null || _d === void 0 ? void 0 : _d.id), false);
    const content = useMemo(() => {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
        let res = null;
        if (((_a = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _a === void 0 ? void 0 : _a.type) === UnitTypeEnums.Scene) {
            res = (React.createElement(WorkflowUiInterruptContent, { key: selectedNode.id, selectedNode: selectedNode, workflow: workflow, reloadWorkflow: reloadWorkflow, users: users, groups: groups, handleClose: handleClose, inquiryPageParams: inquiryPageParams }));
        }
        else if (((_b = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _b === void 0 ? void 0 : _b.type) === UnitTypeEnums.Sms) {
            res = (React.createElement(SmsDisplay, { messages: [((_d = (_c = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _c === void 0 ? void 0 : _c.sms) === null || _d === void 0 ? void 0 : _d.body) || ''], to: ((_f = (_e = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _e === void 0 ? void 0 : _e.sms) === null || _f === void 0 ? void 0 : _f.to) || '', from: ((_h = (_g = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _g === void 0 ? void 0 : _g.sms) === null || _h === void 0 ? void 0 : _h.from) || '', title: ((_j = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _j === void 0 ? void 0 : _j.nodeLabel) || '', handleClose: handleClose }));
        }
        else if (((_k = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _k === void 0 ? void 0 : _k.type) === UnitTypeEnums.Mail) {
            res = (React.createElement(EmailDisplay, { html: ((_m = (_l = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _l === void 0 ? void 0 : _l.email) === null || _m === void 0 ? void 0 : _m.html) ||
                    ((_p = (_o = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _o === void 0 ? void 0 : _o.email) === null || _p === void 0 ? void 0 : _p.text) ||
                    '', to: ((_r = (_q = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _q === void 0 ? void 0 : _q.email) === null || _r === void 0 ? void 0 : _r.to) || '', from: ((_t = (_s = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _s === void 0 ? void 0 : _s.email) === null || _t === void 0 ? void 0 : _t.from) || '', title: ((_u = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _u === void 0 ? void 0 : _u.nodeLabel) || '', handleClose: handleClose }));
        }
        else if ((_w = (_v = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _v === void 0 ? void 0 : _v.page) === null || _w === void 0 ? void 0 : _w.id) {
            res = (React.createElement(PageContainer, { user: user, key: selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.id, pageData: pageData, pageLoading: pageLoading, widgetParams: {
                    pageId: pageData === null || pageData === void 0 ? void 0 : pageData.pageId,
                    entityName: (_z = (_y = (_x = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _x === void 0 ? void 0 : _x.page) === null || _y === void 0 ? void 0 : _y.entity) === null || _z === void 0 ? void 0 : _z.entityName,
                    pbiReportCode: (_1 = (_0 = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _0 === void 0 ? void 0 : _0.page) === null || _1 === void 0 ? void 0 : _1.pbiReportCode,
                    requiredFieldsMap: (_3 = (_2 = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _2 === void 0 ? void 0 : _2.page) === null || _3 === void 0 ? void 0 : _3.requiredFieldMapping,
                    udpTagId: (_5 = (_4 = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _4 === void 0 ? void 0 : _4.page) === null || _5 === void 0 ? void 0 : _5.udpTagId,
                    queryId: (_7 = (_6 = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _6 === void 0 ? void 0 : _6.page) === null || _7 === void 0 ? void 0 : _7.queryId,
                    inquiryTreeId: (_9 = (_8 = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.properties) === null || _8 === void 0 ? void 0 : _8.page) === null || _9 === void 0 ? void 0 : _9.inquiryTreeId
                }, disableMargins: true, fromMenu: true }));
        }
        return res;
    }, [
        groups,
        pageData,
        pageLoading,
        reloadWorkflow,
        selectedNode,
        user,
        users,
        workflow,
        handleClose
    ]);
    return React.createElement("div", { className: classes.root }, content);
};
//# sourceMappingURL=WorkflowContent.js.map