"use strict";

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

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

var _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 = _interopRequireWildcard(require("react")), _propTypes = _interopRequireDefault(require("prop-types")), _amosAntd = require("amos-antd"), _processor = require("../../../../utils/processor"), _urlConsts = require("../../../../consts/urlConsts"), _amosFramework = require("amos-framework"), _CapacityPropertyCell = _interopRequireDefault(require("./CapacityPropertyCell")), _AddCapacityProperty = _interopRequireDefault(require("./../deviceAddEdit/AddCapacityProperty"));

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : t;
  })(e);
}

function _interopRequireWildcard(e, t) {
  if (!t && e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var a = {}, i = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var o in e) if ("default" !== o && Object.prototype.hasOwnProperty.call(e, o)) {
    var n = i ? Object.getOwnPropertyDescriptor(e, o) : null;
    n && (n.get || n.set) ? Object.defineProperty(a, o, n) : a[o] = e[o];
  }
  return a.default = e, r && r.set(e, a), a;
}

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;
  }
}

require("./../device-detail.scss");

var CapacityProperty = 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), "fetchCapacityProperty", (function(e) {
      var t = a.props, r = t.propertyInfo, i = t.deviceId, o = t.getDeviceInfoById, n = t.visibility, u = [];
      if (void 0 !== r) for (var c = 0; c < r.length; c++) {
        var p = r[c];
        u.push(_react.default.createElement(_CapacityPropertyCell.default, {
          key: c,
          propertyInfo: p,
          deleteCapacityProperty: a.deleteCapacityProperty,
          deviceId: i,
          visibility: n,
          getDeviceInfoById: o
        }));
      }
      return u;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "deleteCapacityProperty", (function(e) {
      var t = a.delProperty;
      _amosAntd.Modal.confirm({
        title: "删除",
        content: "是否删除所选属性？",
        okText: "确定",
        cancelText: "取消",
        onOk: function() {
          t(e);
        },
        onCancel: function() {}
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "delProperty", (function(e) {
      var t = a.props.deviceId, r = "".concat(_urlConsts.OltSerUrl.deleteCapacityProperty, "/").concat(e);
      _processor.AmosFetch.del(r).then((function(e) {
        if (e.ok) return e.text();
        throw new Error("从服务端获取数据失败！");
      })).then((function(e) {
        _amosFramework.message.success("删除成功！"), a.props.getDeviceInfoById(t);
      }));
    })), a.state = {}, a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentDidMount",
    value: function() {}
  }, {
    key: "render",
    value: function() {
      var e = this.props, t = e.deviceId, r = e.getDeviceInfoById, a = e.capacityId, i = e.visibility, o = e.addCapacityProperty;
      return _react.default.createElement("div", {
        className: "capacity-property"
      }, _react.default.createElement("div", {
        className: "capacity-detail-property"
      }, _react.default.createElement("label", null, "采集指标"), 1 === i ? _react.default.createElement(_AddCapacityProperty.default, {
        addCapacityProperty: o,
        capacityId: a,
        getDeviceInfoById: r,
        deviceId: t
      }) : null), _react.default.createElement("div", {
        className: "capacity-detail-property-content"
      }, this.fetchCapacityProperty()));
    }
  } ]), r;
}(_react.Component);

CapacityProperty.displayName = "CapacityProperty", CapacityProperty.propTypes = {
  propertyInfo: _propTypes.default.array,
  deviceId: _propTypes.default.number,
  capacityId: _propTypes.default.number,
  addCapacityProperty: _propTypes.default.func,
  getDeviceInfoById: _propTypes.default.func
};

var _default = CapacityProperty;

exports.default = _default;