define(["require", "exports", "../next_flow_node_info", "./gateway_handler"], function (require, exports, next_flow_node_info_1, gateway_handler_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    class ExclusiveGatewayHandler extends gateway_handler_1.GatewayHandler {
        async executeIntern(flowNode, processToken, context) {
            const processDefinition = await flowNode.getProcessDef(context);
            const incomingSequenceFlows = this.getIncomingSequenceFlowsFor(flowNode.id, processDefinition);
            const outgoingSequenceFlows = this.getOutgoingSequenceFlowsFor(flowNode.id, processDefinition);
            if (incomingSequenceFlows.length > outgoingSequenceFlows.length) {
                return new next_flow_node_info_1.NextFlowNodeInfo(this.getFlowNodeById(outgoingSequenceFlows[0].target.id, processDefinition), processToken);
            }
            else {
                const sequenceFlow = outgoingSequenceFlows.find(sequenceFlow => {
                    return this.executeCondition(sequenceFlow.condition, processToken);
                });
                return new next_flow_node_info_1.NextFlowNodeInfo(this.getFlowNodeById(sequenceFlow.target.id, processDefinition), processToken);
            }
        }
        executeCondition(condition, processToken) {
            const tokenData = processToken.data || {};
            try {
                const functionString = 'return ' + condition;
                const evaluateFunction = new Function('token', functionString);
                return evaluateFunction.call(tokenData, tokenData);
            }
            catch (err) {
                return false;
            }
        }
    }
    exports.ExclusiveGatewayHandler = ExclusiveGatewayHandler;
});

//# sourceMappingURL=exlusive_gateway_handler.js.map
