"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"), _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")), _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"), _DevicePropertyCell = _interopRequireDefault(require("./DevicePropertyCell")), _AddDeviceProperty = _interopRequireDefault(require("./../deviceAddEdit/AddDeviceProperty"));

function _createSuper(e) {
    var r = _isNativeReflectConstruct();
    return function() {
        var t, i = (0, _getPrototypeOf2.default)(e);
        if (r) {
            var o = (0, _getPrototypeOf2.default)(this).constructor;
            t = Reflect.construct(i, arguments, o);
        } else t = i.apply(this, arguments);
        return (0, _possibleConstructorReturn2.default)(this, t);
    };
}

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 DeviceProperty = function(e) {
    (0, _inherits2.default)(t, e);
    var r = _createSuper(t);
    function t(e) {
        var i;
        return (0, _classCallCheck2.default)(this, t), i = r.call(this, e), (0, _defineProperty2.default)((0, 
        _assertThisInitialized2.default)(i), "fetchDeviceProperty", (function(e) {
            var r = i.props.device, t = r.id, o = r.attributes, a = r.visibility, l = [];
            if (void 0 !== o) for (var n = 0; n < o.length; n++) {
                var u = o[n];
                l.push(_react.default.createElement(_DevicePropertyCell.default, (0, _extends2.default)({
                    key: n,
                    propertyInfo: u,
                    deleteDeviceProperty: i.deleteDeviceProperty,
                    deviceId: t,
                    visibility: a
                }, i.props)));
            }
            return l;
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "deleteDeviceProperty", (function(e) {
            var r = i.delProperty;
            _amosAntd.Modal.confirm({
                title: "删除",
                content: "是否删除所选属性？",
                okText: "确定",
                cancelText: "取消",
                onOk: function() {
                    r(e);
                },
                onCancel: function() {}
            });
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "delProperty", (function(e) {
            var r = i.props.device.id, t = "".concat(_urlConsts.OltSerUrl.deleteDeviceProperty, "/").concat(e);
            _processor.AmosFetch.del(t).then((function(e) {
                if (e.ok) return e.text();
                throw new Error("从服务端获取数据失败！");
            })).then((function(e) {
                _amosFramework.message.success("删除成功！"), i.props.getDeviceInfoById(r);
            }));
        })), i.state = {}, i;
    }
    return (0, _createClass2.default)(t, [ {
        key: "componentDidMount",
        value: function() {}
    }, {
        key: "render",
        value: function() {
            var e = this.props, r = e.device, t = e.getDeviceInfoById;
            return _react.default.createElement("div", {
                className: "device-property"
            }, _react.default.createElement("div", {
                className: "device-detail-property"
            }, _react.default.createElement("label", null, "基本属性"), 1 === r.visibility ? _react.default.createElement(_AddDeviceProperty.default, (0, 
            _extends2.default)({
                deviceId: r.id,
                getDeviceInfoById: t
            }, this.props)) : null), _react.default.createElement("div", {
                className: "device-detail-property-content"
            }, this.fetchDeviceProperty()));
        }
    } ]), t;
}(_react.Component);

DeviceProperty.displayName = "DeviceProperty", DeviceProperty.propTypes = {
    device: _propTypes.default.object,
    getDeviceInfoById: _propTypes.default.func
};

var _default = DeviceProperty;

exports.default = _default;