"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"),
  _CommonDeviceCell = _interopRequireDefault(require("./CommonDeviceCell")),
  _CreateDeviceSearch = _interopRequireDefault(require("./CreateDeviceSearch")),
  _CreateDeviceLeft = _interopRequireDefault(require("./CreateDeviceLeft"));
require("./createDeviceHost.scss");
var _deviceService = require("./../../../services/deviceService");

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

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

  function r(e) {
    var i;
    return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(i = t.call(this, e)), "componentDidMount", function() {
      i.questStatistiscData()
    }), _defineProperty(_assertThisInitialized(i), "getTemplateContent", function() {
      var e = i.state.statisticsData,
        r = [];
      return e && e.map(function(e) {
        var t = e.eqpTemplate;
        t && r.push(_react.default.createElement(_CommonDeviceCell.default, _extends({
          key: t.id,
          deleteTemplate: i.questdeleteNode,
          clickDeviceTemplate: i.clickDeviceTemplate,
          type: 2,
          deviceInfo: t,
          imgUrl: t.img,
          deviceNum: e.count
        }, i.props)))
      }), r
    }), _defineProperty(_assertThisInitialized(i), "setSearchParam", function(e) {
      i.setState({
        searchParam: e
      }), i.questStatistiscData(e)
    }), _defineProperty(_assertThisInitialized(i), "clickDeviceTemplate", function(t) {
      (0, _deviceService.fetchTemplatOrEqpIntfcAction)(t.id).then(function(e) {
        _extends(t, {
          intfcList: e
        }), i.setState({
          device: t
        })
      }), (0, _deviceService.fetchTemplatOrEqpQuotaAction)(t.id).then(function(e) {
        _extends(t, {
          quotaList: e
        }), i.setState({
          device: t
        })
      })
    }), _defineProperty(_assertThisInitialized(i), "clickMask", function() {
      i.setState({
        device: void 0
      })
    }), _defineProperty(_assertThisInitialized(i), "questStatistiscData", function(e) {
      var t = i.state.searchParam;
      e = void 0 === e ? t : e, (0, _deviceService.fetchTemplateStatisticsAction)(e).then(function(e) {
        var t = e.data,
          e = e.totalCount;
        i.setState({
          statisticsData: t,
          totalCount: e
        })
      })
    }), _defineProperty(_assertThisInitialized(i), "questdeleteNode", function(e) {
      var t;
      void 0 !== e && (t = i.deleteTemplate, _amosFramework.Modal.confirm({
        title: "确认删除",
        content: "是否删除所选信息？",
        okText: "确定",
        cancelText: "取消",
        onOk: function() {
          t(e)
        },
        onCancel: function() {}
      }))
    }), _defineProperty(_assertThisInitialized(i), "deleteTemplate", function(e) {
      (0, _deviceService.deleteEquipmentTemplateAction)(e).then(function(e) {
        i.questStatistiscData(), _amosFramework.message.success("删除成功"), i.clickMask()
      })
    }), i.state = {
      searchParam: {},
      statisticsData: [],
      totalCount: 0
    }, i
  }
  return _createClass(r, [{
    key: "render",
    value: function() {
      var e = this.state,
        t = e.device,
        r = e.statisticsData,
        e = e.totalCount;
      return _react.default.createElement("div", {
        className: "create-device-root"
      }, _react.default.createElement("div", {
        className: "create-device-host-top"
      }, _react.default.createElement(_CreateDeviceSearch.default, {
        setSearchParam: this.setSearchParam
      })), _react.default.createElement("div", {
        className: "create-device-host-bottom",
        onClick: this.clickMask
      }, _react.default.createElement("div", {
        className: "create-device-host-left"
      }, _react.default.createElement(_CreateDeviceLeft.default, {
        device: t,
        statisticsData: r,
        totalCount: e
      })), _react.default.createElement("div", {
        className: "create-device-host-right"
      }, this.getTemplateContent())))
    }
  }]), r
}();
DeviceTypePanel.displayName = "DeviceTypePanel", DeviceTypePanel.propTypes = {
  updateMainView: _propTypes.default.func
};
var _default = DeviceTypePanel;
exports.default = DeviceTypePanel, module.exports = exports.default;
