"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const BaseRenderer = require("../../../../../node_modules/diagram-js/lib/draw/BaseRenderer.js");
const NodeItem_vue = require("../component/NodeItem.vue.js");
const renderComponent = require("./renderComponent.js");
const BpmnRenderUtil = require("../../../../../node_modules/bpmn-js/lib/draw/BpmnRenderUtil.js");
const ModelUtil = require("../../../../../node_modules/bpmn-js/lib/util/ModelUtil.js");
const A = 1500, S = 2;
class T extends BaseRenderer.default {
  constructor(t, i) {
    super(t, A), this.bpmnRenderer = i;
  }
  canRender(t) {
    return ModelUtil.isAny(t, [
      "bpmn:Task",
      "bpmn:Event",
      "bpmn:Gateway",
      "bpmn:CallActivity",
      "bpmn:Transaction"
    ]);
  }
  drawShape(t, i) {
    if (i.isReResize) {
      delete i.isReResize;
      return;
    }
    if (i.labelTarget) {
      i.y += 10;
      return;
    }
    let a = i.businessObject.$attrs["normal:name"];
    if (a) {
      try {
        a = JSON.parse(a).zh_CN;
      } catch {
      }
      i.businessObject.name = a;
    }
    C(t, i), t.remove();
  }
  getShapePath(t) {
    return ModelUtil.is(t, "bpmn:Task") ? BpmnRenderUtil.getRoundRectPath(t, S) : this.bpmnRenderer.getShapePath(t);
  }
}
T.$inject = ["eventBus", "bpmnRenderer"];
const C = (f, t) => {
  let i = document.querySelector(
    ".djs-element[data-element-id='" + t.id + "']"
  );
  if (i) {
    let e = i.querySelector("foreignObject");
    e && e.remove();
  }
  let a = "node-item-" + t.id, s = document.createElementNS(
    "http://www.w3.org/2000/svg",
    "foreignObject"
  ), r = t.businessObject.$attrs["normal:nodeType"];
  if (!r)
    if (t.type == "bpmn:StartEvent")
      r = "start", t.width = 32, t.height = 32;
    else if (t.type == "bpmn:EndEvent")
      r = "end", t.width = 32, t.height = 32;
    else if (t.type == "bpmn:ExclusiveGateway")
      r = "gateway";
    else if (t.type == "bpmn:ParallelGateway")
      r = "parallelGateway", t.id.endsWith("mergeGateway") && (r = "mergeGateway");
    else if (t.type == "bpmn:InclusiveGateway")
      r = "inclusiveGateway";
    else if (t.type == "bpmn:ServiceTask") {
      r = "service";
      let e = t.businessObject.$attrs["flowable:delegateExpression"];
      e && e == "${flowRuleListener}" && (r = "rde");
    } else
      t.type == "bpmn:ReceiveTask" ? r = "wait" : t.type == "bpmn:CallActivity" && (r = "childProcess");
  s.setAttribute("id", a), s.setAttribute("width", t.width), s.setAttribute("height", t.height), s.setAttribute("class", "custom-foreignObject");
  let d = document.createElement("div");
  d.setAttribute("class", "custom-node-item "), f.parentNode.appendChild(s), s.appendChild(d);
  let c = window.flowChartData, o = c.timeLineData, u = o.task, b = o.hisTask, l = false;
  c.activeActivityIds.find((e) => e === t.id) && (l = true);
  let n = false, p = u.find((e) => e.taskDefinitionKey == t.id);
  p ? n = true : (p = b.find((e) => e.taskDefinitionKey == t.id), p && (n = true)), (!o.isEnd && t.type == "bpmn:StartEvent" || o.isEnd && (t.type == "bpmn:StartEvent" || t.type == "bpmn:EndEvent")) && (n = true);
  let h = [];
  b.forEach((e) => {
    e.taskDefinitionKey == t.id && h.push(e);
  });
  let y = [];
  u.forEach((e) => {
    e.taskDefinitionKey == t.id && y.push(e);
  }), renderComponent.default({
    el: d,
    //  组件要插入的那个dom
    component: NodeItem_vue.default,
    // 要插入的组件
    props: {
      // 传入 props
      nodeType: r,
      isHighlight: n,
      hisTaskList: h,
      taskList: y,
      isCurrent: l
    },
    appContext: Vue.getCurrentInstance()
    // 获取组件实例的
  });
};
exports.default = T;
