import { getCurrentInstance } from "vue";
import t from "../../../../../node_modules/diagram-js/lib/draw/BaseRenderer.mjs";
import Pe from "../component/NodeItem.vue.mjs";
import c$1 from "./renderComponent.mjs";
import { getRoundRectPath as T$1 } from "../../../../../node_modules/bpmn-js/lib/draw/BpmnRenderUtil.mjs";
import { isAny as c, is as u } from "../../../../../node_modules/bpmn-js/lib/util/ModelUtil.mjs";
const A = 1500, S = 2;
class T extends t {
  constructor(t2, i) {
    super(t2, A), this.bpmnRenderer = i;
  }
  canRender(t2) {
    return c(t2, [
      "bpmn:Task",
      "bpmn:Event",
      "bpmn:Gateway",
      "bpmn:CallActivity",
      "bpmn:Transaction"
    ]);
  }
  drawShape(t2, 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(t2, i), t2.remove();
  }
  getShapePath(t2) {
    return u(t2, "bpmn:Task") ? T$1(t2, S) : this.bpmnRenderer.getShapePath(t2);
  }
}
T.$inject = ["eventBus", "bpmnRenderer"];
const C = (f, t2) => {
  let i = document.querySelector(
    ".djs-element[data-element-id='" + t2.id + "']"
  );
  if (i) {
    let e = i.querySelector("foreignObject");
    e && e.remove();
  }
  let a = "node-item-" + t2.id, s = document.createElementNS(
    "http://www.w3.org/2000/svg",
    "foreignObject"
  ), r = t2.businessObject.$attrs["normal:nodeType"];
  if (!r)
    if (t2.type == "bpmn:StartEvent")
      r = "start", t2.width = 32, t2.height = 32;
    else if (t2.type == "bpmn:EndEvent")
      r = "end", t2.width = 32, t2.height = 32;
    else if (t2.type == "bpmn:ExclusiveGateway")
      r = "gateway";
    else if (t2.type == "bpmn:ParallelGateway")
      r = "parallelGateway", t2.id.endsWith("mergeGateway") && (r = "mergeGateway");
    else if (t2.type == "bpmn:InclusiveGateway")
      r = "inclusiveGateway";
    else if (t2.type == "bpmn:ServiceTask") {
      r = "service";
      let e = t2.businessObject.$attrs["flowable:delegateExpression"];
      e && e == "${flowRuleListener}" && (r = "rde");
    } else
      t2.type == "bpmn:ReceiveTask" ? r = "wait" : t2.type == "bpmn:CallActivity" && (r = "childProcess");
  s.setAttribute("id", a), s.setAttribute("width", t2.width), s.setAttribute("height", t2.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 c2 = window.flowChartData, o = c2.timeLineData, u2 = o.task, b = o.hisTask, l = false;
  c2.activeActivityIds.find((e) => e === t2.id) && (l = true);
  let n = false, p = u2.find((e) => e.taskDefinitionKey == t2.id);
  p ? n = true : (p = b.find((e) => e.taskDefinitionKey == t2.id), p && (n = true)), (!o.isEnd && t2.type == "bpmn:StartEvent" || o.isEnd && (t2.type == "bpmn:StartEvent" || t2.type == "bpmn:EndEvent")) && (n = true);
  let h = [];
  b.forEach((e) => {
    e.taskDefinitionKey == t2.id && h.push(e);
  });
  let y = [];
  u2.forEach((e) => {
    e.taskDefinitionKey == t2.id && y.push(e);
  }), c$1({
    el: d,
    //  组件要插入的那个dom
    component: Pe,
    // 要插入的组件
    props: {
      // 传入 props
      nodeType: r,
      isHighlight: n,
      hisTaskList: h,
      taskList: y,
      isCurrent: l
    },
    appContext: getCurrentInstance()
    // 获取组件实例的
  });
};
export {
  T as default
};
