var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
import NavigatedViewer from "../../../../../../node_modules/bpmn-js/lib/NavigatedViewer.mjs";
import customRendererModule from "./bpmnjs/renderer/index.mjs";
import customImporterModule from "./bpmnjs/importer/index.mjs";
/* empty css           */
class FlowChart {
  constructor(container) {
    __publicField(this, "addTestMarker", function() {
      if (document.querySelector("#testMarker")) {
        return;
      }
      let testMarker = document.createElementNS(
        "http://www.w3.org/2000/svg",
        "marker"
      );
      testMarker.setAttribute("id", "testMarker");
      testMarker.setAttribute("viewBox", "0 0 20 20");
      testMarker.setAttribute("refX", "11");
      testMarker.setAttribute("refY", "10");
      testMarker.setAttribute("markerWidth", "10");
      testMarker.setAttribute("markerHeight", "10");
      testMarker.setAttribute("orient", "auto");
      let path = document.createElementNS("http://www.w3.org/2000/svg", "path");
      path.setAttribute("d", "M 1 5 L 11 10 L 1 15 Z");
      path.setAttribute(
        "style",
        "fill: black; stroke-width: 1px; stroke-linecap: round; stroke-dasharray: 10000, 1; stroke: black;"
      );
      testMarker.appendChild(path);
      try {
        if (typeof this.container === "object") {
          this.container.querySelector("defs").appendChild(testMarker);
        } else {
          let dom = document.querySelector(this.container);
          dom.querySelector("defs").appendChild(testMarker);
        }
      } catch (e) {
        document.querySelector("defs").appendChild(testMarker);
      }
    });
    this.container = container;
    this.refresh();
    if (this.bpmnViewer) {
      this.bpmnViewer.destroy();
    }
    this.bpmnViewer = new NavigatedViewer({
      container: this.container,
      additionalModules: [
        customRendererModule,
        customImporterModule,
        {
          // zoomScroll: ["value", ''],//禁用滚动
          // moveCanvas: ['value', ''],//禁用拖动整个流程图
          move: ["value", ""]
          //禁用单个图形拖动
        }
      ]
      // keyboard: {
      //   bindTo: document, // 或者window，注意与外部表单的键盘监听事件是否冲突
      // },
    });
  }
  refresh() {
    if (this.container) {
      if (typeof this.container === "object") {
        this.container.innerHTML = "";
      } else {
        let dom = document.querySelector(this.container);
        if (dom) {
          dom.innerHTML = "";
        }
      }
    }
  }
  import(data) {
    this.data = data;
    window.flowChartData = data;
    this.bpmnViewer.importXML(data.modelXml).then(() => {
      this.bpmnViewer.get("canvas").zoom("fit-viewport", "auto");
    });
  }
  colorToFlow(flowList) {
    this.addTestMarker();
    if (flowList.length > 0) {
      for (var i in flowList) {
        var flowId = flowList[i].id || flowList[i];
        let element = document.querySelector(`g[data-element-id=${flowId}]`);
        if (element) {
          if (element.classList.contains("djs-connection")) {
            element.setAttribute("state", "highlight");
          }
        }
      }
    }
  }
}
export {
  FlowChart as default
};
