import { assign } from "../../../min-dash/dist/index.esm.mjs";
import e from "../../../inherits-browser/dist/index.es.mjs";
import Refs from "../../../../_virtual/index.mjs";
var parentRefs = new Refs({ name: "children", enumerable: true, collection: true }, { name: "parent" }), labelRefs = new Refs({ name: "labels", enumerable: true, collection: true }, { name: "labelTarget" }), attacherRefs = new Refs({ name: "attachers", collection: true }, { name: "host" }), outgoingRefs = new Refs({ name: "outgoing", collection: true }, { name: "source" }), incomingRefs = new Refs({ name: "incoming", collection: true }, { name: "target" });
function Base() {
  Object.defineProperty(this, "businessObject", {
    writable: true
  });
  Object.defineProperty(this, "label", {
    get: function() {
      return this.labels[0];
    },
    set: function(newLabel) {
      var label = this.label, labels = this.labels;
      if (!newLabel && label) {
        labels.remove(label);
      } else {
        labels.add(newLabel, 0);
      }
    }
  });
  parentRefs.bind(this, "parent");
  labelRefs.bind(this, "labels");
  outgoingRefs.bind(this, "outgoing");
  incomingRefs.bind(this, "incoming");
}
function Shape() {
  Base.call(this);
  parentRefs.bind(this, "children");
  attacherRefs.bind(this, "host");
  attacherRefs.bind(this, "attachers");
}
e(Shape, Base);
function Root() {
  Shape.call(this);
}
e(Root, Shape);
function Label() {
  Shape.call(this);
  labelRefs.bind(this, "labelTarget");
}
e(Label, Shape);
function Connection() {
  Base.call(this);
  outgoingRefs.bind(this, "source");
  incomingRefs.bind(this, "target");
}
e(Connection, Base);
var types = {
  connection: Connection,
  shape: Shape,
  label: Label,
  root: Root
};
function create(type, attrs) {
  var Type = types[type];
  if (!Type) {
    throw new Error("unknown type: <" + type + ">");
  }
  return assign(new Type(), attrs);
}
export {
  Base,
  Connection,
  Label,
  Root,
  Shape,
  create
};
