"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _dec, _class, _temp, _react = _interopRequireDefault(require("react")),
  _propTypes = _interopRequireDefault(require("prop-types")),
  _amosJsplumb = require("amos-jsplumb"),
  _amosAntd = require("amos-antd"),
  _amosReactRouter = require("amos-react-router"),
  _amosIcon = _interopRequireDefault(require("amos-icon")),
  _urlConsts = require("../../../../consts/urlConsts"),
  _processor = require("../../../../utils/processor"),
  _rayEventpool = require("ray-eventpool"),
  _dt2react = _interopRequireDefault(require("dt2react")),
  _classnames = _interopRequireDefault(require("classnames")),
  _stageConst = require("./../modelConf/stageConst"),
  _nodeConf = require("./../modelConf/nodeConf"),
  _DeviceProNode = _interopRequireDefault(require("./DeviceProNode")),
  _DeviceEnum = require("./../../../deviceManage/common/DeviceEnum"),
  _DeviceLang = require("./../../../deviceManage/common/DeviceLang"),
  _ActionItem = _interopRequireDefault(require("./../../../ruleDesign/ruleStatge/extra/ActionItem"));

function _interopRequireDefault(e) {
  return e && e.__esModule ? e : {
    default: e
  }
}

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 _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 o = t[r];
    o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, o.key, o)
  }
}

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 o = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, o ? (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 keyDelete = 46,
  Anchors = _amosJsplumb.placement.Anchors,
  CustomNode = (_dec = (0, _amosJsplumb.plumbNodeConnect)({
    className: "custom-ele",
    targetParams: {
      allowLoopback: !1,
      anchor: Anchors.TopCenter,
      dropOptions: {
        hoverClass: "drag-hover"
      },
      isTarget: !0
    },
    sourceParams: {
      allowLoopback: !1,
      anchor: Anchors.Continuous,
      isTarget: !1,
      dropOptions: {
        hoverClass: "drag-hover"
      }
    },
    endPointParams: [{
      params: _nodeConf.sourceEndPoint,
      referenceParams: {
        anchor: Anchors.TopCenter
      }
    }]
  }))(_class = _temp = function() {
    _inherits(o, _react["default"].Component);
    var t = _createSuper(o);

    function o(e) {
      var r;
      return _classCallCheck(this, o), _defineProperty(_assertThisInitialized(r = t.call(this, e)), "clickNode", function(e, t) {
        window.topoNodefocus = !0, r.singleClickTrigger({
          e: e,
          id: t
        })
      }), _defineProperty(_assertThisInitialized(r), "showNodeProperty", function(e, t) {
        r.dbClickTrigger({
          e: e,
          id: t
        })
      }), _defineProperty(_assertThisInitialized(r), "gotoAlarm", function() {
        !0 === r.state.isWarning && _amosReactRouter.browserHistory.push("/main/monitor/alarmManage/recentAlarm?param=".concat(r.props.config.equipmentId))
      }), _defineProperty(_assertThisInitialized(r), "dbClickTrigger", function(e) {
        e = e.id;
        _rayEventpool.PubSub.publish(_stageConst.TOPO_SHOW_PROPERTY_TOPIC.trigger, {
          id: e
        })
      }), _defineProperty(_assertThisInitialized(r), "singleClickTrigger", function(e) {
        e = e.id;
        _rayEventpool.PubSub.publish(_stageConst.TOPO_ENABLE_CLICK_TOPIC.trigger, {
          id: e
        })
      }), _defineProperty(_assertThisInitialized(r), "keyboardTrigger", function(e) {
        var t = e.id,
          e = e.e;
        e && e.keyCode === keyDelete && _rayEventpool.PubSub.publish(_stageConst.TOPO_ELE_DEL_TOPIC.trigger, {
          id: t
        })
      }), _defineProperty(_assertThisInitialized(r), "remove", function(e, t) {
        t = t.id;
        _rayEventpool.PubSub.publish(_stageConst.TOPO_ELE_DEL_TOPIC.trigger, {
          id: t
        })
      }), _defineProperty(_assertThisInitialized(r), "getAlarmImg", function() {
        var e, t = [];
        return !0 === r.state.isWarning ? (r.lampStyle = "twinkle-img-style", 1 === (e = r.alarmLevel) ? t.push(_react.default.createElement("img", {
          src: require("./../../../../assets/iot/topo/dot/red.png"),
          onClick: r.gotoAlarm,
          alt: ""
        })) : 2 === e ? t.push(_react.default.createElement("img", {
          src: require("./../../../../assets/iot/topo/dot/orange.png"),
          onClick: r.gotoAlarm,
          alt: ""
        })) : 3 === e && t.push(_react.default.createElement("img", {
          src: require("./../../../../assets/iot/topo/dot/yellow.png"),
          onClick: r.gotoAlarm,
          alt: ""
        }))) : (r.lampStyle = "img-style", t.push(_react.default.createElement("img", {
          src: require("./../../../../assets/iot/topo/dot/green.png"),
          onClick: r.gotoAlarm,
          alt: ""
        }))), t
      }), r.state = {
        dataList: [],
        isWarning: !1
      }, r
    }
    return _createClass(o, [{
      key: "componentWillMount",
      value: function() {
        var r = this,
          e = this.props.config,
          e = "".concat(_urlConsts.OltSerUrl.getRealDataByDeviceId, "/").concat(e.equipmentId);
        _processor.AmosFetch.get(e).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          var t;
          "SUCCESS" === e.result && ((t = e.dataList.isWarning) && (r.alarmLevel = e.dataList.maxLevel), r.setState({
            dataList: e.dataList.realTimeMetricDataVoList,
            isWarning: t
          }))
        })
      }
    }, {
      key: "componentWillReceiveProps",
      value: function(e) {
        var t, r;
        e.config && e.config.realTimeData && (t = e.config.realTimeData, 0 === (e = this.state.dataList).length ? e.push(t) : (r = !1, e.map(function(e) {
          e.cpblId === t.cpblId && (e.metricDataMap = t.metricDataMap, e.time = t.time, r = !0)
        }), r || e.push(t)), this.setState({
          dataList: e
        }))
      }
    }, {
      key: "render",
      value: function() {
        var e, t, r, o = this,
          n = this.props.config,
          a = this.state.dataList,
          i = this.getAlarmImg();
        void 0 !== n && void 0 !== n.data && (t = (e = n.data).viewPath, e = void 0 === n.label ? e.name : n.label, t = "" === t || null === t ? "".concat(_urlConsts.OltSerUrl.fetchDeviceImg, "/default.png") : "".concat(_urlConsts.OltSerUrl.fetchDeviceImg, "/").concat(t), r = n.id);
        n = this.lampStyle;
        return _react.default.createElement(_amosAntd.Popover, {
          overlayClassName: "custom-node-popover",
          placement: "right",
          title: "实时监测数据",
          content: _react.default.createElement(_DeviceProNode.default, {
            dataList: a
          })
        }, _react.default.createElement("div", {
          className: "node-content-wrapper",
          onClick: function(e) {
            return o.clickNode(e, r)
          },
          title: e
        }, _react.default.createElement("div", {
          className: "custom-node-img"
        }, _react.default.createElement("img", {
          src: t,
          alt: "device"
        })), _react.default.createElement("div", {
          className: "text-info"
        }, _react.default.createElement("div", {
          className: n
        }, i), _react.default.createElement("p", {
          className: "text-style"
        }, e)), _react.default.createElement("div", {
          className: "ele-node-action"
        }, _react.default.createElement("div", {
          className: "action-extra-item"
        }, _react.default.createElement(_ActionItem.default, {
          icon: "delete",
          onClick: function(e) {
            return o.remove(e, {
              id: r
            })
          },
          tip: "点击删除元素节点"
        })))))
      }
    }]), o
  }()) || _class;
CustomNode.displayName = "CustomNode", CustomNode.propTypes = {
  config: _propTypes.default.object
};
var _default = CustomNode;
exports.default = CustomNode, module.exports = exports.default;
