"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _react = _interopRequireWildcard(require("react")),
  _propTypes = _interopRequireDefault(require("prop-types")),
  _urlConsts = require("../../../consts/urlConsts"),
  _amosAntd = require("amos-antd"),
  _processor = require("../../../utils/processor"),
  _amosFramework = require("amos-framework"),
  _dt2react = _interopRequireDefault(require("dt2react")),
  _DeviceEnum = require("./../../deviceManage/common/DeviceEnum"),
  _DeviceLang = require("./../../deviceManage/common/DeviceLang");

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 a, r, n = {},
    o = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (a in e) Object.prototype.hasOwnProperty.call(e, a) && ((r = o ? Object.getOwnPropertyDescriptor(e, a) : null) && (r.get || r.set) ? Object.defineProperty(n, a, r) : n[a] = e[a]);
  return n.default = e, t && t.set(e, n), n
}

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 _extends() {
  return (_extends = Object.assign || function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var a, r = arguments[t];
      for (a in r) Object.prototype.hasOwnProperty.call(r, a) && (e[a] = r[a])
    }
    return e
  }).apply(this, arguments)
}

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

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

function _createClass(e, t, a) {
  return t && _defineProperties(e.prototype, t), a && _defineProperties(e, a), 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(a) {
  var r = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(a);
    return _possibleConstructorReturn(this, r ? (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, a) {
  return t in e ? Object.defineProperty(e, t, {
    value: a,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = a, e
}
require("./topo.scss");
var createForm = _amosAntd.Form.create(),
  Panel = _amosFramework.Collapse.Panel,
  collapseHeadHeight = 95,
  DevicePropertyPanel = function() {
    _inherits(a, _react.Component);
    var t = _createSuper(a);

    function a(e) {
      var l;
      return _classCallCheck(this, a), _defineProperty(_assertThisInitialized(l = t.call(this, e)), "onClickProperty", function(e) {
        l.savePropertyToEquipment()
      }), _defineProperty(_assertThisInitialized(l), "onClickCapacity", function(e, t) {
        var a = l.props,
          r = a.showDeviceCapacityPanel,
          a = a.closeCapacityInterfacePanel;
        r(t, l.getCurrentEquipment), a()
      }), _defineProperty(_assertThisInitialized(l), "onAttributeChange", function(t, a) {
        var e = l.state.attributes;
        void 0 !== e && (e.map(function(e) {
          e.id === a && (e.valueStr = t.target.value)
        }), l.setState({
          attributes: e
        }))
      }), _defineProperty(_assertThisInitialized(l), "getPropertyData", function(e, a) {
        void 0 === e || (e = l.props.config) && e.data && (e = e.data.eqpTmplId, e = "".concat(_urlConsts.OltSerUrl.fetchDeviceById, "/").concat(e), _processor.AmosFetch.get(e).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          var t;
          "SUCCESS" !== e.result || void 0 !== (t = e.dataList) && (e = t.capabilities || [], l.getEquipmentData(a, t.attributes || [], e))
        }))
      }), _defineProperty(_assertThisInitialized(l), "getInterfaceData", function(e) {
        void 0 === e || (e = l.props.config) && e.data && (e = e.data.eqpTmplId, e = "".concat(_urlConsts.OltSerUrl.fetchDeviceInterfaceById, "/").concat(e), _processor.AmosFetch.get(e).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          "SUCCESS" === e.result && (e = e.dataList, l.setState({
            intfcList: e || []
          }))
        }))
      }), _defineProperty(_assertThisInitialized(l), "getEquipmentData", function(e, n, o) {
        void 0 !== e ? (e = "".concat(_urlConsts.OltSerUrl.getEquipmentData, "/").concat(e), _processor.AmosFetch.get(e).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          var t, a, r;
          "SUCCESS" === e.result && (t = e.dataList, a = t.cfgParamMap.selCpblIds, r = [], a && o.map(function(e) {
            a.includes(String(e.id)) && r.push(e)
          }), n.map(function(e) {
            e.valueStr = t.cfgParamMap["equip_".concat(e.id)]
          }), l.setState({
            equipment: t,
            attributes: n,
            capabilities: r
          }))
        })) : l.setState({
          equipment: {}
        })
      }), _defineProperty(_assertThisInitialized(l), "getAttributesEditContent", function() {
        var e = l.state,
          t = e.attributes,
          e = e.equipment,
          a = [];
        return void 0 !== e.cfgParamMap ? t.map(function(t) {
          var e = t.valueStr;
          a.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
            title: t.displayName,
            span: 8,
            offset: 1,
            style: {
              "text-align": "right",
              height: "30px",
              "line-height": "30px",
              "text-overflow": "ellipsis",
              "white-space": "nowrap",
              overflow: "hidden"
            }
          }, t.displayName, "："), _react.default.createElement(_amosFramework.Col, {
            span: 14,
            offset: 1,
            style: {
              "text-align": "left",
              height: "30px",
              "line-height": "30px"
            }
          }, _react.default.createElement(_amosAntd.Input, {
            style: {
              width: "90%"
            },
            onChange: function(e) {
              return l.onAttributeChange(e, t.id)
            },
            value: e
          }))))
        }) : t.map(function(t) {
          a.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
            title: t.displayName,
            span: 8,
            offset: 1,
            style: {
              "text-align": "right",
              height: "30px",
              "line-height": "30px",
              "text-overflow": "ellipsis",
              "white-space": "nowrap",
              overflow: "hidden"
            }
          }, t.displayName, "："), _react.default.createElement(_amosFramework.Col, {
            span: 14,
            offset: 1,
            style: {
              "text-align": "left",
              height: "30px",
              "line-height": "30px"
            }
          }, _react.default.createElement(_amosAntd.Input, {
            style: {
              width: "90%"
            },
            onChange: function(e) {
              return l.onAttributeChange(e, t.id)
            },
            value: t.valueStr
          }))))
        }), a
      }), _defineProperty(_assertThisInitialized(l), "getCapacitysContent", function() {
        var e = l.state.capabilities,
          a = [];
        return e.map(function(t) {
          a.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
            span: 21,
            offset: 1,
            style: {
              height: "30px",
              "line-height": "30px",
              "text-overflow": "ellipsis",
              "white-space": "nowrap",
              overflow: "hidden",
              "text-align": "left"
            }
          }, t.name), _react.default.createElement(_amosFramework.Col, {
            span: 2,
            style: {
              height: "30px",
              "line-height": "30px"
            }
          }, _react.default.createElement("div", {
            onClick: function(e) {
              return l.onClickCapacity(e, t)
            },
            className: "edit-interface-img"
          }, _react.default.createElement("img", {
            src: require("./../../../assets/iot/img/list_nlsx.png"),
            alt: "",
            style: {
              position: "relative",
              top: "5px"
            }
          })))))
        }), a
      }), _defineProperty(_assertThisInitialized(l), "getCurrentEquipment", function() {
        return l.state.equipment
      }), _defineProperty(_assertThisInitialized(l), "getCollapseHead", function(e, t) {
        var a = l.getImgPath(t),
          r = [],
          t = 4 < e.length ? "img-line" : "img-short-line";
        return r.push(_react.default.createElement("div", {
          className: "img-line-root"
        }, _react.default.createElement("label", null, e), _react.default.createElement("img", {
          src: require("./../../../assets/iot/topo/u2074.png"),
          alt: "",
          className: t
        }), a)), r
      }), _defineProperty(_assertThisInitialized(l), "getImgPath", function(e) {
        e = l.state.collapseKey.includes(e) ? _react.default.createElement("img", {
          src: require("./../../../assets/iot/topo/expand.png"),
          alt: "",
          className: "img-last"
        }) : _react.default.createElement("img", {
          src: require("./../../../assets/iot/topo/shrink.png"),
          alt: "",
          className: "img-last"
        });
        return e
      }), _defineProperty(_assertThisInitialized(l), "savePropertyToEquipment", function() {
        var e = l.state,
          t = e.attributes,
          e = e.equipment,
          r = e.cfgParamMap;
        void 0 !== t && (t.map(function(e) {
          var t = "equip_".concat(e.id),
            a = e.valueStr;
          r.hasOwnProperty(t) ? r[t] = a : _extends(r, _defineProperty({}, t, a)), "sourceId" === e.name && (r.hasOwnProperty("sid") ? r.sid = a : _extends(r, {
            sid: a
          }))
        }), r.hasOwnProperty("sid") || _extends(r, {
          sid: ""
        }), e.cfgParamJson = JSON.stringify(r), _processor.AmosFetch.post(_urlConsts.OltSerUrl.addEquipmentAttribute, {
          data: e
        }).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          "SUCCESS" === e.result ? _amosFramework.message.success("编辑成功！") : _amosFramework.message.danger("编辑失败！")
        }))
      }), _defineProperty(_assertThisInitialized(l), "updateName", function(e) {
        var t = l.state.equipment,
          a = l.props,
          r = a.config,
          n = a.getSubgraphData,
          o = a.subviewId,
          i = a.nodeId,
          s = l.name;
        l.name = e, void 0 !== t.id && (t = r.data, r = {
          label: e,
          type: r.type,
          data: t,
          style: r.style
        }, e = {
          id: t.id,
          name: e,
          nodeId: i,
          config: JSON.stringify(r)
        }, r = "".concat(_urlConsts.OltSerUrl.updateNodeName), _processor.AmosFetch.post(r, {
          data: e
        }).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          "SUCCESS" === e.result ? -1 === e.dataList ? (_amosFramework.message.danger("设备名称重复！"), l.name = s, l.setState({
            attributes: l.state.attributes
          })) : n(o, i) : _amosFramework.message.danger("编辑失败！")
        }))
      }), _defineProperty(_assertThisInitialized(l), "changeCollapseSize", function(e) {
        var t = l.collapsepanel,
          a = _dt2react.default.getOffsetParent(t).clientHeight - collapseHeadHeight;
        _dt2react.default.addStyle(t, "height", "".concat(a, "px")), void 0 !== e && void 0 !== e.length && l.setState({
          collapseKey: e
        })
      }), l.state = {
        attributes: [],
        intfcList: [],
        capabilities: [],
        equipment: {},
        collapseKey: ["1", "2", "3"]
      }, l
    }
    return _createClass(a, [{
      key: "componentDidMount",
      value: function() {
        var e = this.props,
          t = e.config,
          e = e.equipmentId,
          t = t.data || {};
        this.getPropertyData(t.id, e), this.getInterfaceData(t.id), this.changeCollapseSize()
      }
    }, {
      key: "componentWillReceiveProps",
      value: function(e) {
        var t = this.props,
          a = t.nodeId,
          r = t.cfgParamJson,
          t = e.config.data || {};
        a === e.nodeId && r === e.cfgParamJson || (this.getPropertyData(t.id, e.equipmentId), this.getInterfaceData(t.id))
      }
    }, {
      key: "render",
      value: function() {
        var e, t, a = this,
          r = this.props,
          n = r.config,
          o = r.deleteNode,
          i = r.nodeId,
          s = r.doHiddenProperty,
          r = this.state.collapseKey;
        return void 0 !== n && (e = n.data || {}, t = void 0 === n.label ? this.name : n.label), _react.default.createElement("div", {
          className: "device-property-panel"
        }, _react.default.createElement("div", {
          className: "head-one"
        }, "设备信息"), _react.default.createElement("div", {
          className: "head-two"
        }, _react.default.createElement("div", {
          className: "head-two-one"
        }), _react.default.createElement("div", {
          className: "head-two-two",
          onClick: function() {
            return o(i)
          }
        }, "移出"), _react.default.createElement("div", {
          className: "head-two-three",
          onClick: function(e) {
            return s(e)
          }
        }, "取消"), _react.default.createElement("div", {
          className: "head-two-four",
          onClick: function(e) {
            return a.onClickProperty(e)
          }
        }, "完成")), _react.default.createElement("div", {
          className: "amos-collapse-panel",
          ref: function(e) {
            return a.collapsepanel = e
          }
        }, _react.default.createElement(_amosFramework.Collapse, {
          activeKey: r,
          onChange: function(e) {
            return a.changeCollapseSize(e)
          }
        }, _react.default.createElement(Panel, {
          showArrow: !1,
          header: this.getCollapseHead("基本信息", "1"),
          key: "1"
        }, _react.default.createElement("div", {
          className: "property-basic-info"
        }, _react.default.createElement("div", {
          style: {
            height: "100%"
          }
        }, _react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
          span: 4,
          offset: 1,
          style: {
            height: "30px",
            "line-height": "30px"
          }
        }, "名称："), _react.default.createElement(_amosFramework.Col, {
          span: 18,
          offset: 1,
          style: {
            "text-align": "left"
          }
        }, _react.default.createElement(_amosFramework.Editable, {
          value: t,
          onChange: this.updateName,
          showOkCancel: !1
        }))), _react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
          span: 4,
          offset: 1,
          style: {
            height: "30px",
            "line-height": "30px"
          }
        }, "型号："), _react.default.createElement(_amosFramework.Col, {
          span: 18,
          offset: 1,
          style: {
            "text-align": "left",
            height: "30px",
            "line-height": "30px"
          }
        }, e.model)), _react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
          span: 4,
          offset: 1,
          style: {
            height: "30px",
            "line-height": "30px"
          }
        }, "类别："), _react.default.createElement(_amosFramework.Col, {
          span: 18,
          offset: 1,
          style: {
            "text-align": "left",
            height: "30px",
            "line-height": "30px"
          }
        }, e ? (0, _DeviceLang.stringUtil)(_DeviceEnum.deviceCategoryEnum, parseInt(e.type)) : "")), _react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
          span: 4,
          offset: 1,
          style: {
            height: "30px",
            "line-height": "30px"
          }
        }, "备注："), _react.default.createElement(_amosFramework.Col, {
          span: 18,
          offset: 1,
          style: {
            "text-align": "left",
            height: "30px",
            "line-height": "30px"
          }
        }, e.descr))))), _react.default.createElement(Panel, {
          showArrow: !1,
          header: this.getCollapseHead("基本属性", "2"),
          key: "2"
        }, _react.default.createElement("div", {
          className: "property-property-info"
        }, this.getAttributesEditContent())), _react.default.createElement(Panel, {
          showArrow: !1,
          header: this.getCollapseHead("数据采集", "3"),
          key: "3"
        }, _react.default.createElement("div", {
          className: "property-interface-info"
        }, this.getCapacitysContent())))))
      }
    }]), a
  }();
DevicePropertyPanel.displayName = "DevicePropertyPanel", DevicePropertyPanel.propTypes = {
  config: _propTypes.default.object,
  form: _propTypes.default.any,
  getSubgraphData: _propTypes.default,
  subviewId: _propTypes.default.string,
  nodeId: _propTypes.default.string,
  showDeviceCapacityPanel: _propTypes.default.func,
  equipmentId: _propTypes.default.number,
  updateNodeConfig: _propTypes.default.func,
  cfgParamJson: _propTypes.default.object,
  deviceLabel: _propTypes.default.string,
  deleteNode: _propTypes.default.func,
  doHiddenProperty: _propTypes.default.func,
  closeCapacityInterfacePanel: _propTypes.default.func
};
var _default = createForm(DevicePropertyPanel);
exports.default = _default, module.exports = exports.default;
