"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _react = _interopRequireWildcard(require("react")),
  _propTypes = _interopRequireDefault(require("prop-types")),
  _amosFramework = require("amos-framework"),
  _urlConsts = _interopRequireDefault(require("../../../../consts/urlConsts")),
  _TopoUpLoadIcon = _interopRequireDefault(require("./TopoUpLoadIcon")),
  _DeviceEnum = require("./../../../deviceManage/common/DeviceEnum"),
  _DeviceLang = require("./../../../deviceManage/common/DeviceLang"),
  _topoService = require("./../../../../services/topoService");

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 r, a, n = {},
    o = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((a = o ? Object.getOwnPropertyDescriptor(e, r) : null) && (a.get || a.set) ? Object.defineProperty(n, r, a) : n[r] = e[r]);
  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 _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 a = t[r];
    a.enumerable = a.enumerable || !1, a.configurable = !0, "value" in a && (a.writable = !0), Object.defineProperty(e, a.key, a)
  }
}

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 a = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, a ? (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 Panel = _amosFramework.Collapse.Panel,
  DeviceBasicInfoConfig = function() {
    _inherits(r, _react.Component);
    var t = _createSuper(r);

    function r(e) {
      var s;
      return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(s = t.call(this, e)), "onChangeCollapseSize", function(e) {
        void 0 !== e && void 0 !== e.length && s.setState({
          collapseKey: e
        })
      }), _defineProperty(_assertThisInitialized(s), "onAttributeChange", function(t, r) {
        var e = s.props,
          a = e.equipmentId,
          n = e.nodeId,
          o = e.showProperty,
          i = {
            id: a
          };
        s.props.currentDeviceConfig.device.attributes.map(function(e) {
          e = e.name;
          e && "sourceId" === e && (i.sid = r)
        }), i[t] = r, (0, _topoService.updateEquipmentConfigAction)(i).then(function(e) {
          s.deviceConfigParam[t] = r, o(n)
        })
      }), _defineProperty(_assertThisInitialized(s), "setImgFile", function(e) {
        var t = new FileReader;
        t.addEventListener("load", function() {
          return s.saveImgFileAction(t.result, e.name)
        }), "{}" === JSON.stringify(e) ? s.saveEquipmnet({
          binaryImg: null,
          imgName: null
        }) : t.readAsBinaryString(e)
      }), _defineProperty(_assertThisInitialized(s), "getCollapseHead", function(e, t) {
        var r = s.props.getImgPath(t, s.state.collapseKey),
          t = [];
        return t.push(_react.default.createElement("div", {
          className: "config-collapse-head"
        }, _react.default.createElement("label", {
          className: "config-collapse-text"
        }, e), r)), t
      }), _defineProperty(_assertThisInitialized(s), "getDeviceConfigInfo", function() {
        var e = s.props.currentDeviceConfig,
          a = e ? e.eqp : void 0,
          e = e ? e.eqpProperty : void 0,
          n = s.deviceConfigParam,
          o = [];
        return e && e.map(function(t) {
          var e, r = n["equip_".concat(t.id)];
          void 0 === r && (r = (e = a.cfgParamMap)["equip_".concat(t.id)] ? e["equip_".concat(t.id)] : r), n["equip_".concat(t.id)] = r, o.push(_react.default.createElement("div", {
            key: t.id,
            className: "topo-property-common"
          }, _react.default.createElement("div", {
            className: "property-label-name",
            title: t.displayName
          }, t.displayName, "："), _react.default.createElement(_amosFramework.Editable, {
            value: r,
            onChange: function(e) {
              return s.onAttributeChange("equip_".concat(t.id), e)
            },
            showOkCancel: !1,
            style: {
              width: "126px",
              marginLeft: "10px"
            },
            innerValueStyle: {
              width: "126px"
            },
            placeholder: "请输入"
          })))
        }), o
      }), _defineProperty(_assertThisInitialized(s), "saveImgFileAction", function(e, t) {
        t = {
          id: s.props.equipmentId,
          binaryImg: e,
          imgName: t
        };
        (0, _topoService.addeEditEqpImgAction)(t).then(function(e) {})
      }), _defineProperty(_assertThisInitialized(s), "updateEquipmentName", function(e, t) {
        var r, a, n, o, i = s.props,
          c = i.currentDeviceConfig,
          l = i.showProperty;
        (c ? c.eqp : void 0) && (c = (i = s.props).config, r = i.getSubgraphData, a = i.subviewId, n = i.nodeId, o = s.name, s.name = t, i = c.data, c = {
          label: t,
          type: c.type,
          data: i,
          style: c.style
        }, c = {
          id: i.id,
          name: t,
          nodeId: n,
          config: JSON.stringify(c)
        }, (0, _topoService.updateEquipmentNameAction)(c).then(function(e) {
          -1 === e ? (_amosFramework.message.danger("设备名称重复！"), s.name = o) : (r(a, n), l(n))
        }))
      }), s.deviceConfigParam = {}, s.state = {
        collapseKey: ["1", "2"]
      }, s
    }
    return _createClass(r, [{
      key: "componentWillMount",
      value: function() {}
    }, {
      key: "componentDidMount",
      value: function() {}
    }, {
      key: "componentWillReceiveProps",
      value: function() {}
    }, {
      key: "componentWillUnmount",
      value: function() {}
    }, {
      key: "render",
      value: function() {
        var t = this,
          e = this.state.collapseKey,
          r = this.props.currentDeviceConfig,
          a = r ? r.eqp : void 0,
          n = r ? r.device : void 0,
          r = a && a.logo ? "".concat(_urlConsts.default.fetchDeviceImg, "/icon/").concat(a.logo) : void 0;
        return _react.default.createElement("div", {
          className: "topo-config-basic-root"
        }, _react.default.createElement(_amosFramework.Collapse, {
          activeKey: e,
          onChange: function(e) {
            return t.onChangeCollapseSize(e)
          }
        }, _react.default.createElement(Panel, {
          showArrow: !1,
          header: this.getCollapseHead("设备信息", "1"),
          key: "1"
        }, _react.default.createElement("div", {
          className: "device-basic-info"
        }, _react.default.createElement("div", {
          className: "topo-basic-name"
        }, _react.default.createElement("div", {
          className: "property-label-name"
        }, "设备名称："), _react.default.createElement(_amosFramework.Editable, {
          value: a && a.name,
          onChange: function(e) {
            return t.updateEquipmentName("name", e)
          },
          showOkCancel: !1,
          style: {
            width: "140px",
            marginLeft: "10px"
          },
          innerValueStyle: {
            width: "140px"
          },
          placeholder: "请输入"
        })), _react.default.createElement("div", {
          className: "topo-basic-descr"
        }, _react.default.createElement("div", {
          className: "property-label-name"
        }, "设备描述："), _react.default.createElement("div", {
          className: "property-normal-label",
          title: a && a.descr
        }, a && a.descr)), _react.default.createElement("div", {
          className: "topo-basic-icon"
        }, _react.default.createElement(_TopoUpLoadIcon.default, {
          enable: !0,
          style: {
            top: "-18px",
            "max-width": "130px",
            "max-height": "130px"
          },
          setImgFile: this.setImgFile,
          defaultImg: r
        })), _react.default.createElement("div", {
          className: "topo-basic-catalog"
        }, _react.default.createElement("div", {
          className: "property-label-name"
        }, "设备类别："), _react.default.createElement("div", {
          className: "property-normal-label",
          title: (0, _DeviceLang.stringUtil)(_DeviceEnum.deviceCategoryEnum, n && n.type)
        }, (0, _DeviceLang.stringUtil)(_DeviceEnum.deviceCategoryEnum, n && n.type))), _react.default.createElement("div", {
          className: "topo-basic-industry"
        }, _react.default.createElement("div", {
          className: "property-label-name"
        }, "所属行业："), _react.default.createElement("div", {
          className: "property-normal-label",
          title: n && n.equipTemplateIndustry.name
        }, n && n.equipTemplateIndustry.name)), _react.default.createElement("div", {
          className: "topo-type-name"
        }, _react.default.createElement("div", {
          className: "property-label-name"
        }, "设备类型："), _react.default.createElement("div", {
          className: "property-normal-label",
          title: n && n.name
        }, n && n.name)), _react.default.createElement("div", {
          className: "topo-basic-model"
        }, _react.default.createElement("div", {
          className: "property-label-name"
        }, "备注："), _react.default.createElement("div", {
          className: "property-normal-label",
          title: n && n.model
        }, n && n.model)))), _react.default.createElement(Panel, {
          showArrow: !1,
          header: this.getCollapseHead("设备属性", "2"),
          key: "2"
        }, _react.default.createElement("div", {
          className: "device-basic-property"
        }, this.getDeviceConfigInfo()))))
      }
    }]), r
  }();
DeviceBasicInfoConfig.displayName = "DeviceBasicInfoConfig", DeviceBasicInfoConfig.propTypes = {
  getImgPath: _propTypes.default.func,
  currentDeviceConfig: _propTypes.default.object,
  getSubgraphData: _propTypes.default.func,
  subviewId: _propTypes.default.string,
  nodeId: _propTypes.default.string,
  equipmentId: _propTypes.default.number,
  config: _propTypes.default.object,
  showProperty: _propTypes.default.func
};
var _default = DeviceBasicInfoConfig;
exports.default = DeviceBasicInfoConfig, module.exports = exports.default;
