"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Elements = require("../../util/Elements.js");
const index_esm$1 = require("../../../../tiny-svg/dist/index.esm.js");
const index_esm = require("../../../../min-dom/dist/index.esm.js");
const index_esm$2 = require("../../../../min-dash/dist/index.esm.js");
var LOW_PRIORITY = 500;
function Outline(eventBus, styles, elementRegistry) {
  this.offset = 6;
  var OUTLINE_STYLE = styles.cls("djs-outline", ["no-fill"]);
  var self = this;
  function createOutline(gfx, bounds) {
    var outline = index_esm$1.create("rect");
    index_esm$1.attr(outline, index_esm$2.assign({
      x: 10,
      y: 10,
      rx: 3,
      width: 100,
      height: 100
    }, OUTLINE_STYLE));
    index_esm$1.append(gfx, outline);
    return outline;
  }
  eventBus.on(["shape.added", "shape.changed"], LOW_PRIORITY, function(event) {
    var element = event.element, gfx = event.gfx;
    var outline = index_esm.query(".djs-outline", gfx);
    if (!outline) {
      outline = createOutline(gfx);
    }
    self.updateShapeOutline(outline, element);
  });
  eventBus.on(["connection.added", "connection.changed"], function(event) {
    var element = event.element, gfx = event.gfx;
    var outline = index_esm.query(".djs-outline", gfx);
    if (!outline) {
      outline = createOutline(gfx);
    }
    self.updateConnectionOutline(outline, element);
  });
}
Outline.prototype.updateShapeOutline = function(outline, element) {
  index_esm$1.attr(outline, {
    x: -this.offset,
    y: -this.offset,
    width: element.width + this.offset * 2,
    height: element.height + this.offset * 2
  });
};
Outline.prototype.updateConnectionOutline = function(outline, connection) {
  var bbox = Elements.getBBox(connection);
  index_esm$1.attr(outline, {
    x: bbox.x - this.offset,
    y: bbox.y - this.offset,
    width: bbox.width + this.offset * 2,
    height: bbox.height + this.offset * 2
  });
};
Outline.$inject = ["eventBus", "styles", "elementRegistry"];
exports.default = Outline;
