"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = _default;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")), _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")), _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")), _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")), _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), React = _interopRequireWildcard(require("react")), _amosJsplumb = require("amos-jsplumb"), _rayEventpool = require("ray-eventpool"), _classnames = _interopRequireDefault(require("classnames")), _stageConst = require("./../../modelConf/stageConst"), _nodeConf = require("./../../modelConf/nodeConf"), _ElementEditor = _interopRequireDefault(require("./ElementEditor"));

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : t;
  })(e);
}

function _interopRequireWildcard(e, t) {
  if (!t && e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var n = {}, o = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var a in e) if ("default" !== a && Object.prototype.hasOwnProperty.call(e, a)) {
    var i = o ? Object.getOwnPropertyDescriptor(e, a) : null;
    i && (i.get || i.set) ? Object.defineProperty(n, a, i) : n[a] = e[a];
  }
  return n.default = e, r && r.set(e, n), n;
}

function ownKeys(e, t) {
  var r = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var n = Object.getOwnPropertySymbols(e);
    t && (n = n.filter((function(t) {
      return Object.getOwnPropertyDescriptor(e, t).enumerable;
    }))), r.push.apply(r, n);
  }
  return r;
}

function _objectSpread(e) {
  for (var t = 1; t < arguments.length; t++) {
    var r = null != arguments[t] ? arguments[t] : {};
    t % 2 ? ownKeys(Object(r), !0).forEach((function(t) {
      (0, _defineProperty2.default)(e, t, r[t]);
    })) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : ownKeys(Object(r)).forEach((function(t) {
      Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(r, t));
    }));
  }
  return e;
}

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, n = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var o = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(n, arguments, o);
    } else r = n.apply(this, arguments);
    return (0, _possibleConstructorReturn2.default)(this, r);
  };
}

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), 
    !0;
  } catch (e) {
    return !1;
  }
}

var DefaultNode = _amosJsplumb.PlumbEleNode.DefaultNode, Anchors = _amosJsplumb.placement.Anchors;

function _default(e) {
  var t = e.type, r = e.nodeIcon, n = (0, _stageConst.completeItemTypeIcon)(r);
  return function(e) {
    (0, _inherits2.default)(a, e);
    var o = _createSuper(a);
    function a(e) {
      var r;
      return (0, _classCallCheck2.default)(this, a), r = o.call(this, e), (0, _defineProperty2.default)((0, 
      _assertThisInitialized2.default)(r), "dbClickTrigger", (function(e) {
        var r = e.id, n = e.config, o = e.parentConfig;
        _rayEventpool.PubSub.publish(_stageConst.DB_CLICK_ELE, {
          id: r,
          config: n,
          parentConfig: o,
          type: t
        });
      })), r.state = {
        active: !1
      }, r;
    }
    return (0, _createClass2.default)(a, [ {
      key: "componentDidMount",
      value: function() {
        var e = this.props, t = e.id;
        (0, e.initNode)({
          endPointParams: [ {
            element: this.container,
            params: _nodeConf.sourceEndPoint,
            referenceParams: {
              anchor: Anchors.RightMiddle,
              uuid: "obj-ep-".concat(Anchors.RightMiddle, "-").concat(t)
            }
          }, {
            element: this.container,
            params: _nodeConf.targetEndpoint,
            referenceParams: {
              anchor: Anchors.LeftMiddle,
              uuid: "obj-ep-".concat(Anchors.LeftMiddle, "-").concat(t)
            }
          } ],
          makeTargetParams: {
            allowLoopback: !1,
            anchor: Anchors.ContinuousLeft,
            dropOptions: {
              hoverClass: "drag-hover"
            },
            isTarget: !0
          },
          makeSourceParams: {
            filter: ".ele-source-bar",
            allowLoopback: !1,
            anchor: Anchors.Right,
            dropOptions: {
              hoverClass: "drag-hover"
            }
          },
          nodeId: t
        });
      }
    }, {
      key: "render",
      value: function() {
        var e = this, t = this.state.active, o = this.props, a = o.id, i = o.config, u = o.parentConfig, l = i.style, c = i.label, s = (0, 
        _classnames.default)({
          "node-wrapper": !0,
          "node-wrapper-active": t
        }), f = (0, _classnames.default)("fire-node-ele", r), p = _objectSpread(_objectSpread({}, l), {}, {
          background: 'url("'.concat(n, '") no-repeat')
        });
        return React.createElement("div", {
          id: a,
          className: f,
          style: p,
          ref: function(t) {
            return e.container = t;
          },
          onDoubleClick: function() {
            return e.dbClickTrigger({
              id: a,
              config: i,
              parentConfig: u
            });
          }
        }, React.createElement("div", {
          className: s
        }, React.createElement("div", {
          className: "ele-node-content"
        }, React.createElement(_ElementEditor.default, {
          label: c,
          eleId: a
        }))));
      }
    } ]), a;
  }(DefaultNode);
}