"use strict";

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

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

var _dec, _class, _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 = _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")), _rayEventpool = require("ray-eventpool"), _dt2react = require("dt2react"), _urlConsts = require("../../../../consts/urlConsts"), _processor = require("../../../../utils/processor"), _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 _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, a = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var i = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(a, arguments, i);
    } else r = a.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 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 = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var a;
    return (0, _classCallCheck2.default)(this, r), a = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(a), "clickNode", (function(e, t) {
      a.singleClickTrigger({
        e: e,
        id: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "showNodeProperty", (function(e, t) {
      a.dbClickTrigger({
        e: e,
        id: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "gotoAlarm", (function() {
      !0 === a.state.isWarning && _amosReactRouter.browserHistory.push("/main/monitor/alarmManage/recentAlarm?param=".concat(a.props.config.equipmentId));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "dbClickTrigger", (function(e) {
      var t = e.id;
      _rayEventpool.PubSub.publish(_stageConst.TOPO_SHOW_PROPERTY_TOPIC.trigger, {
        id: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "singleClickTrigger", (function(e) {
      var t = e.id;
      _rayEventpool.PubSub.publish(_stageConst.TOPO_ENABLE_CLICK_TOPIC.trigger, {
        id: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "keyboardTrigger", (function(e) {
      var t = e.id, r = e.e;
      r && r.keyCode === keyDelete && _rayEventpool.PubSub.publish(_stageConst.TOPO_ELE_DEL_TOPIC.trigger, {
        id: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "remove", (function(e, t) {
      var r = t.id;
      _rayEventpool.PubSub.publish(_stageConst.TOPO_ELE_DEL_TOPIC.trigger, {
        id: r
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getAlarmImg", (function() {
      var e = [];
      if (!0 === a.state.isWarning) {
        a.lampStyle = "twinkle-img-style";
        var t = a.alarmLevel;
        1 === t ? e.push(_react.default.createElement("img", {
          src: require("./../../../../assets/iot/topo/dot/red.png"),
          onClick: a.gotoAlarm,
          alt: ""
        })) : 2 === t ? e.push(_react.default.createElement("img", {
          src: require("./../../../../assets/iot/topo/dot/orange.png"),
          onClick: a.gotoAlarm,
          alt: ""
        })) : 3 === t && e.push(_react.default.createElement("img", {
          src: require("./../../../../assets/iot/topo/dot/yellow.png"),
          onClick: a.gotoAlarm,
          alt: ""
        }));
      } else a.lampStyle = "img-style", e.push(_react.default.createElement("img", {
        src: require("./../../../../assets/iot/topo/dot/green.png"),
        onClick: a.gotoAlarm,
        alt: ""
      }));
      return e;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "getView", (function() {
      var e = [], t = a.state.dataList;
      if (void 0 !== t) return t.map((function(t, r) {
        var a = "dpn-".concat(r);
        if (t.metricDataMap && "{}" !== JSON.stringify(t.metricDataMap)) {
          var i = t.metricDataMap;
          for (var n in i) {
            console.log(n);
            var o = "".concat(n, "：").concat(i[n]);
            e.push(_react.default.createElement("div", {
              title: o,
              className: "quota-".concat(a)
            }, o));
          }
        } else e.push(_react.default.createElement("div", {
          className: "quota-".concat(a)
        }, "无数据"));
      })), e;
    })), a.state = {
      dataList: [],
      isWarning: !1
    }, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentWillMount",
    value: function() {
      var e = this, t = this.props.config, r = "".concat(_urlConsts.OltSerUrl.getRealDataByDeviceId, "/").concat(t.equipmentId);
      _processor.AmosFetch.get(r).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(t) {
        "SUCCESS" === t.result && (t.dataList.isWarning && (e.alarmLevel = t.dataList.maxLevel), 
        e.setState({
          dataList: t.dataList.realTimeMetricDataVoList,
          isWarning: t.dataList.isWarning
        }));
      }));
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      if (e.config && e.config.realTimeData) {
        var t = e.config.realTimeData, r = this.state.dataList;
        if (0 === r.length) r.push(t); else {
          var a = !1;
          r.map((function(e) {
            e.cpblId === t.cpblId && (e.metricDataMap = t.metricDataMap, a = !0);
          })), a || r.push(t);
        }
        this.setState({
          dataList: r
        });
      }
    }
  }, {
    key: "render",
    value: function() {
      var e, t, r, a = this, i = this.props.config, n = (this.state.dataList, this.getAlarmImg());
      if (void 0 !== i && void 0 !== i.data) {
        var o = i.data, s = o.viewPath;
        ({
          color: "green"
        }), !0 === this.state.isWarning && {
          color: "red"
        }, e = void 0 === i.label ? o.name : i.label, t = "" === s || null === s ? "".concat(_urlConsts.OltSerUrl.fetchDeviceImg, "/default.png") : "".concat(_urlConsts.OltSerUrl.fetchDeviceImg, "/").concat(s), 
        r = i.id;
      }
      var l = this.lampStyle;
      return _react.default.createElement("div", {
        className: "node-content-wrapper",
        onClick: function(e) {
          return a.clickNode(e, r);
        },
        onKeyDown: function(e) {
          return a.keyboardTrigger({
            e: e,
            id: 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: l
      }, 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 a.remove(e, {
            id: r
          });
        },
        tip: "点击删除元素节点"
      }))));
    }
  } ]), r;
}(_react.default.Component)) || _class;

NingHuaNode.displayName = "NingHuaNode", NingHuaNode.propTypes = {
  config: _propTypes.default.object
};

var _default = NingHuaNode;

exports.default = _default;