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