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

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
}
var CapacityInterfacePanel = 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, t) {
      t || l.savePropertyToEquipment(), l.setState({
        editProperty: t
      })
    }), _defineProperty(_assertThisInitialized(l), "onAttributeChange", function(t, a) {
      var e = l.state.propertyList;
      void 0 !== e && e.map(function(e) {
        e.id === a && (e.valueStr = t.target.value)
      })
    }), _defineProperty(_assertThisInitialized(l), "getInterfaceData", function(e) {
      void 0 !== e && (e = "".concat(_urlConsts.OltSerUrl.deviceInterfaceByid, "/").concat(e), _processor.AmosFetch.post(e).then(function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！")
      }).then(function(e) {
        l.setState({
          propertyList: e.dataList.content
        })
      }))
    }), _defineProperty(_assertThisInitialized(l), "getCapacityInterfaceContent", function() {
      var e = [],
        t = (l.state.propertyList, l.props);
      t.getCurrentEquipment, t.capacityBasicInfo;
      return e.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
        span: 4,
        offset: 1,
        style: {
          height: "30px",
          "line-height": "30px"
        }
      }, "设备ID", "："), _react.default.createElement(_amosFramework.Col, {
        span: 18,
        offset: 1,
        style: {
          "text-align": "left",
          height: "30px",
          "line-height": "30px"
        }
      }, _react.default.createElement(_amosAntd.Input, {
        style: {
          width: "60%"
        },
        defaultValue: ""
      })))), e.push(_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"
        }
      }, _react.default.createElement(_amosAntd.Input, {
        style: {
          width: "60%"
        },
        defaultValue: "1"
      })))), e
    }), _defineProperty(_assertThisInitialized(l), "getCapacityInterfaceEditContent", function() {
      var a = [],
        e = l.state.propertyList,
        t = l.props,
        r = t.getCurrentEquipment,
        n = t.capacityBasicInfo;
      if (void 0 !== r) {
        var o = r();
        return void 0 !== e && void 0 !== o.cfgParamMap ? e.map(function(t) {
          var e = void 0 === (e = o.cfgParamMap["cpbl_intfc_".concat(n.id, "_").concat(t.id)]) ? t.valueStr : e;
          t.valueStr = e, a.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
            span: 4,
            offset: 1,
            style: {
              height: "30px",
              "line-height": "30px"
            }
          }, t.displayName, "："), _react.default.createElement(_amosFramework.Col, {
            span: 18,
            offset: 1,
            style: {
              "text-align": "left",
              height: "30px",
              "line-height": "30px"
            }
          }, _react.default.createElement(_amosAntd.Input, {
            style: {
              width: "60%"
            },
            onChange: function(e) {
              return l.onAttributeChange(e, t.id)
            },
            defaultValue: e
          }))))
        }) : void 0 !== e && void 0 === o.cfgParamMap && e.map(function(t) {
          a.push(_react.default.createElement(_amosFramework.Row, null, _react.default.createElement(_amosFramework.Col, {
            span: 4,
            offset: 1,
            style: {
              height: "30px",
              "line-height": "30px"
            }
          }, t.displayName, "："), _react.default.createElement(_amosFramework.Col, {
            span: 18,
            offset: 1,
            style: {
              "text-align": "left",
              height: "30px",
              "line-height": "30px"
            }
          }, _react.default.createElement(_amosAntd.Input, {
            style: {
              width: "60%"
            },
            onChange: function(e) {
              return l.onAttributeChange(e, t.id)
            },
            defaultValue: t.valueStr
          }))))
        }), a
      }
    }), _defineProperty(_assertThisInitialized(l), "closedPanel", function() {
      (0, l.props.closeCapacityInterfacePanel)()
    }), _defineProperty(_assertThisInitialized(l), "savePropertyToEquipment", function() {
      var e, t, a, r, n, o = l.props,
        i = o.getCurrentEquipment,
        c = o.capacityBasicInfo;
      void 0 !== i && (e = i(), t = l.state.propertyList, void 0 === e.id ? (o = (a = l.props).updateNodeConfig, i = a.nodeId, r = a.cfgParamJson, void 0 !== t && (t.map(function(e) {
        var t = "cpbl_intfc_".concat(c.id, "_").concat(e.id),
          e = e.valueStr;
        r.hasOwnProperty(t) ? r[t] = e : _extends(r, _defineProperty({}, t, e))
      }), o(i, r))) : (n = e.cfgParamMap, void 0 !== t && (t.map(function(e) {
        var t = "cpbl_intfc_".concat(c.id, "_").concat(e.id),
          e = e.valueStr;
        n.hasOwnProperty(t) ? n[t] = e : _extends(n, _defineProperty({}, t, e))
      }), e.cfgParamJson = JSON.stringify(n), _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 ? _amosAntd.Modal.warning({
          title: "系统提示",
          content: "编辑成功！",
          okText: "确定"
        }) : _amosAntd.Modal.error({
          title: "系统提示",
          content: "编辑失败！",
          okText: "确定"
        })
      }))))
    }), l.state = {
      propertyList: [],
      editProperty: !1
    }, l
  }
  return _createClass(a, [{
    key: "componentDidMount",
    value: function() {
      var e = this.props.interfaceBasicInfo;
      this.getInterfaceData(e.intfcId)
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      var t = this.props,
        a = t.interfaceBasicInfo,
        t = t.nodeId;
      e.capacityBasicInfo.id === a.id && t === e.nodeId || this.getInterfaceData(e.interfaceBasicInfo.intfcId)
    }
  }, {
    key: "render",
    value: function() {
      var e = this.props.interfaceBasicInfo,
        t = this.state.editProperty;
      return _react.default.createElement("div", {
        className: "capacity-interface-panel-content"
      }, _react.default.createElement("div", {
        className: "head-one"
      }, "设备接口"), _react.default.createElement(_amosAntd.Icon, {
        type: "close",
        onClick: this.closedPanel,
        style: {
          position: "absolute",
          top: "8px",
          right: "5px"
        }
      }), _react.default.createElement("div", {
        className: "head-two"
      }, _react.default.createElement("div", {
        className: "head-two-one"
      }), _react.default.createElement("div", {
        className: "head-two-two"
      }, "删除"), _react.default.createElement("div", {
        className: "head-two-three"
      }, "取消"), _react.default.createElement("div", {
        className: "head-two-four"
      }, "完成")), _react.default.createElement("div", {
        className: "capacity-interface-basic"
      }, _react.default.createElement("div", {
        className: "capacity-interface-basic-label"
      }, _react.default.createElement("label", null, "基本信息"), _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/topo/u2074.png"),
        alt: "",
        className: "img-line"
      }), _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/topo/expand.png"),
        alt: "",
        className: "img-last-temp"
      })), _react.default.createElement("div", null, _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"
        }
      }, _react.default.createElement(_amosAntd.Input, {
        style: {
          width: "60%"
        },
        value: e
      }))))), _react.default.createElement("div", {
        className: "capacity-interface-property"
      }, _react.default.createElement("div", {
        className: "capacity-interface-property-label"
      }, _react.default.createElement("label", null, "接口属性"), _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/topo/u2074.png"),
        alt: "",
        className: "img-line"
      }), _react.default.createElement("img", {
        src: require("./../../../../../assets/iot/topo/expand.png"),
        alt: "",
        className: "img-last-temp"
      })), t ? this.getCapacityInterfaceEditContent() : this.getCapacityInterfaceContent()))
    }
  }]), a
}();
CapacityInterfacePanel.displayName = "CapacityInterfacePanel", CapacityInterfacePanel.propTypes = {
  closeCapacityInterfacePanel: _propTypes.default.func,
  interfaceBasicInfo: _propTypes.default.object,
  capacityBasicInfo: _propTypes.default.object,
  getCurrentEquipment: _propTypes.default.func,
  updateNodeConfig: _propTypes.default.func,
  cfgParamJson: _propTypes.default.object,
  nodeId: _propTypes.default.string
}, CapacityInterfacePanel.defaultProps = {
  interfaceBasicInfo: {},
  capacityBasicInfo: {}
};
var _default = CapacityInterfacePanel;
exports.default = CapacityInterfacePanel, module.exports = exports.default;
