"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const index_esm = require("../../../../min-dom/dist/index.esm.js");
const index_esm$1 = require("../../../../min-dash/dist/index.esm.js");
const EscapeUtil = require("../../../../diagram-js/lib/util/EscapeUtil.js");
const ModelUtil = require("../../util/ModelUtil.js");
const DrilldownUtil = require("../../util/DrilldownUtil.js");
var L = "bjs-breadcrumbs-shown";
function S(o, t, a, r) {
  var f = index_esm.domify('<ul class="bjs-breadcrumbs"></ul>'), p = r.getContainer(), P = index_esm.classes(p);
  p.appendChild(f);
  var c = [];
  o.on("element.changed", function(n) {
    var i = n.element, u = ModelUtil.getBusinessObject(i), e = index_esm$1.find(c, function(s) {
      return s === u;
    });
    e && v();
  });
  function v(n) {
    n && (c = $(n));
    var i = c.map(function(e) {
      var s = EscapeUtil.escapeHTML(e.name || e.id), h = index_esm.domify('<li><span class="bjs-crumb"><a title="' + s + '">' + s + "</a></span></li>"), d = r.findRoot(DrilldownUtil.getPlaneIdFromShape(e)) || r.findRoot(e.id);
      if (!d && ModelUtil.is(e, "bpmn:Process")) {
        var R = t.find(function(C) {
          var l = ModelUtil.getBusinessObject(C);
          return l && l.processRef && l.processRef === e;
        });
        d = r.findRoot(R.id);
      }
      return h.addEventListener("click", function() {
        r.setRootElement(d);
      }), h;
    });
    f.innerHTML = "";
    var u = i.length > 1;
    P.toggle(L, u), i.forEach(function(e) {
      f.appendChild(e);
    });
  }
  o.on("root.set", function(n) {
    v(n.element);
  });
}
S.$inject = ["eventBus", "elementRegistry", "overlays", "canvas"];
function $(o) {
  for (var t = ModelUtil.getBusinessObject(o), a = [], r = t; r; r = r.$parent)
    (ModelUtil.is(r, "bpmn:SubProcess") || ModelUtil.is(r, "bpmn:Process")) && a.push(r);
  return a.reverse();
}
exports.default = S;
