import * as go from './go';

export default class BarLink extends go.Link {
  constructor() {
    super(...arguments);
    go.Link.call(this);
  }
  getLinkPoint(node, port, spot, from, ortho, othernode, otherport) {
    if (node.category === 'HBar') {
      window.οncοntextmenu = function (event) {
        var e = event || window.event;
        document.getElementById('Menu').style.left = e.clientX + 'px';
        document.getElementById('Menu').style.top = e.clientY + 'px';
        document.getElementById('Menu').style.display = 'block';
        return false;
      };
      var op = go.Link.prototype.getLinkPoint.call(
        this,
        othernode,
        otherport,
        this.computeSpot(!from),
        !from,
        ortho,
        node,
        port,
      );
      var r = port.getDocumentBounds();
      // 横向合管
      var r = port.getDocumentBounds();
      var angle = node.angle;
      var spare = (angle / 90) % 2;
      if (!spare) {
        var y = op.y > r.centerY ? r.bottom : r.top;
        if (op.x < r.left) return new go.Point(r.left, y);
        if (op.x > r.right) return new go.Point(r.right, y);
        return new go.Point(op.x, y);
      }
      // 纵向合管
      var x = op.x > r.centerX ? r.right : r.left;
      if (op.y < r.top) return new go.Point(x, r.top);
      if (op.y > r.bottom) return new go.Point(x, r.bottom);
      // return new go.Point(x, op.y - r.width / 2 + 3);
      return new go.Point(x, op.y);
    } else {
      return go.Link.prototype.getLinkPoint.call(
        this,
        node,
        port,
        spot,
        from,
        ortho,
        othernode,
        otherport,
      );
    }
  }
}

// function BarLink() {
//     go.Link.call(this);
// }
// go.Diagram.inherit(BarLink, go.Link);

// BarLink.prototype.getLinkPoint = function(node, port, spot, from, ortho, othernode, otherport) {
//     if (node.category === "HBar") {
//         window.οncοntextmenu = function(event) {
//             var e = event || window.event;
//             document.getElementById("Menu").style.left = e.clientX + "px";
//             document.getElementById("Menu").style.top = e.clientY + "px";
//             document.getElementById("Menu").style.display = "block";
//             return false;
//         }
//         var op = go.Link.prototype.getLinkPoint.call(this, othernode, otherport, this.computeSpot(!from), !from, ortho, node, port);
//         var r = port.getDocumentBounds();
//         // 横向合管
//         var r = port.getDocumentBounds();
//         var angle = node.angle;
//         var spare = (angle / 90) % 2;
//         if (!spare) {
//             var y = (op.y > r.centerY) ? r.bottom : r.top;
//             if (op.x < r.left) return new go.Point(r.left, y);
//             if (op.x > r.right) return new go.Point(r.right, y);
//             return new go.Point(op.x, y);
//         }
//         // 纵向合管
//         var x = (op.x > r.centerX) ? r.right : r.left;
//         if (op.y < r.top) return new go.Point(x, r.top);
//         if (op.y > r.bottom) return new go.Point(x, r.bottom);
//         // return new go.Point(x, op.y - r.width / 2 + 3);
//         return new go.Point(x, op.y);
//     } else {
//         return go.Link.prototype.getLinkPoint.call(this, node, port, spot, from, ortho, othernode, otherport);
//     }
// };
