"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = _default;
var 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 _interopRequireDefault(e) {
  return e && e.__esModule ? e : {
    default: e
  }
}

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

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

function _typeof(e) {
  return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e
  } : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  })(e)
}

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

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

function _classCallCheck(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}

function _defineProperties(e, t) {
  for (var r = 0; r < t.length; r++) {
    var n = t[r];
    n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, n.key, n)
  }
}

function _createClass(e, t, r) {
  return t && _defineProperties(e.prototype, t), r && _defineProperties(e, r), e
}

function _inherits(e, t) {
  if ("function" != typeof t && null !== t) throw new TypeError("Super expression must either be null or a function");
  e.prototype = Object.create(t && t.prototype, {
    constructor: {
      value: e,
      writable: !0,
      configurable: !0
    }
  }), t && _setPrototypeOf(e, t)
}

function _setPrototypeOf(e, t) {
  return (_setPrototypeOf = Object.setPrototypeOf || function(e, t) {
    return e.__proto__ = t, e
  })(e, t)
}

function _createSuper(r) {
  var n = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, n ? (e = _getPrototypeOf(this).constructor, Reflect.construct(t, arguments, e)) : t.apply(this, arguments))
  }
}

function _possibleConstructorReturn(e, t) {
  return !t || "object" !== _typeof(t) && "function" != typeof t ? _assertThisInitialized(e) : t
}

function _assertThisInitialized(e) {
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  return e
}

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

function _getPrototypeOf(e) {
  return (_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function(e) {
    return e.__proto__ || Object.getPrototypeOf(e)
  })(e)
}

function _defineProperty(e, t, r) {
  return t in e ? Object.defineProperty(e, t, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = r, e
}
var DefaultNode = _amosJsplumb.PlumbEleNode.DefaultNode,
  Anchors = _amosJsplumb.placement.Anchors;

function _default(e) {
  var n = e.type,
    u = e.nodeIcon,
    s = (0, _stageConst.completeItemTypeIcon)(u);
  return function() {
    _inherits(r, DefaultNode);
    var t = _createSuper(r);

    function r(e) {
      return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(e = t.call(this, e)), "dbClickTrigger", function(e) {
        var t = e.id,
          r = e.config,
          e = e.parentConfig;
        _rayEventpool.PubSub.publish(_stageConst.DB_CLICK_ELE, {
          id: t,
          config: r,
          parentConfig: e,
          type: n
        })
      }), e.state = {
        active: !1
      }, e
    }
    return _createClass(r, [{
      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 t = this,
          e = this.state.active,
          r = this.props,
          n = r.id,
          o = r.config,
          i = r.parentConfig,
          c = o.style,
          a = o.label,
          r = (0, _classnames.default)({
            "node-wrapper": !0,
            "node-wrapper-active": e
          }),
          e = (0, _classnames.default)("fire-node-ele", u),
          c = _objectSpread(_objectSpread({}, c), {}, {
            background: 'url("'.concat(s, '") no-repeat')
          });
        return React.createElement("div", {
          id: n,
          className: e,
          style: c,
          ref: function(e) {
            return t.container = e
          },
          onDoubleClick: function() {
            return t.dbClickTrigger({
              id: n,
              config: o,
              parentConfig: i
            })
          }
        }, React.createElement("div", {
          className: r
        }, React.createElement("div", {
          className: "ele-node-content"
        }, React.createElement(_ElementEditor.default, {
          label: a,
          eleId: n
        }))))
      }
    }]), r
  }()
}
module.exports = exports.default;
