"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")),
  _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,
  NingHuaNode = (_dec = (0, _amosJsplumb.plumbNodeConnect)({
    className: "custom-ele",
    targetParams: {
      allowLoopback: !1,
      anchor: Anchors.TopCenter,
      dropOptions: {
        hoverClass: "drag-hover"
      },
      isTarget: !0
    },
    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) {
        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
      }), _defineProperty(_assertThisInitialized(r), "getView", function() {
        var i = [],
          e = r.state.dataList;
        if (void 0 !== e) return e.map(function(e, t) {
          var r = "dpn-".concat(t);
          if (e.metricDataMap && "{}" !== JSON.stringify(e.metricDataMap)) {
            var o, a = e.metricDataMap;
            for (o in a) {
              console.log(o);
              var n = "".concat(o, "：").concat(a[o]);
              i.push(_react.default.createElement("div", {
                title: n,
                className: "quota-".concat(r)
              }, n))
            }
          } else i.push(_react.default.createElement("div", {
            className: "quota-".concat(r)
          }, "无数据"))
        }), i
      }), r.state = {
        dataList: [],
        isWarning: !1
      }, r
    }
    return _createClass(o, [{
      key: "componentWillMount",
      value: function() {
        var t = 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) {
          "SUCCESS" === e.result && (e.dataList.isWarning && (t.alarmLevel = e.dataList.maxLevel), t.setState({
            dataList: e.dataList.realTimeMetricDataVoList,
            isWarning: e.dataList.isWarning
          }))
        })
      }
    }, {
      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, r = !0)
        }), r || e.push(t)), this.setState({
          dataList: e
        }))
      }
    }, {
      key: "render",
      value: function() {
        var t, e, r, o = this,
          a = this.props.config,
          n = (this.state.dataList, this.getAlarmImg());
        void 0 !== a && void 0 !== a.data && (r = (e = a.data).viewPath, this.state.isWarning, e = void 0 === a.label ? e.name : a.label, r = "" === r || null === r ? "".concat(_urlConsts.OltSerUrl.fetchDeviceImg, "/default.png") : "".concat(_urlConsts.OltSerUrl.fetchDeviceImg, "/").concat(r), t = a.id);
        a = this.lampStyle;
        return _react.default.createElement("div", {
          className: "node-content-wrapper",
          onClick: function(e) {
            return o.clickNode(e, t)
          },
          onKeyDown: function(e) {
            return o.keyboardTrigger({
              e: e,
              id: t
            })
          },
          title: e
        }, _react.default.createElement("div", {
          className: "custom-node-img"
        }, _react.default.createElement("img", {
          src: r,
          alt: "device"
        })), _react.default.createElement("div", {
          className: "text-info"
        }, _react.default.createElement("div", {
          className: a
        }, n), _react.default.createElement("p", {
          className: "text-style"
        }, e), _react.default.createElement("div", {
          className: "quota-data"
        }, this.getView())), _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: t
            })
          },
          tip: "点击删除元素节点"
        }))))
      }
    }]), o
  }()) || _class;
NingHuaNode.displayName = "NingHuaNode", NingHuaNode.propTypes = {
  config: _propTypes.default.object
};
var _default = NingHuaNode;
exports.default = NingHuaNode, module.exports = exports.default;
