"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"),
  _processor = require("../../../utils/processor"),
  _urlFormat = _interopRequireDefault(require("amos-processor/lib/utils/urlFormat")),
  _DateUtil = require("../../../utils/DateUtil"),
  _urlConsts = _interopRequireDefault(require("../../../consts/urlConsts")),
  _amosFramework = require("amos-framework"),
  _amosTool = require("amos-tool");
require("./protocol-detail.scss");
var _validate = require("./../../common/utils/validate");

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, l = {},
    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(l, a, r) : l[a] = e[a]);
  return l.default = e, t && t.set(e, l), l
}

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 maxDescLength = 250,
  RadioGroup = _amosAntd.Radio.Group,
  FormItem = _amosAntd.Form.Item,
  createForm = _amosAntd.Form.create(),
  TextArea = _amosAntd.Input.TextArea,
  textAreaStyle = {
    minRows: 12,
    maxRows: 16
  },
  PrivateProtocolDetail = function() {
    _inherits(a, _react.Component);
    var t = _createSuper(a);

    function a(e) {
      var o;
      return _classCallCheck(this, a), _defineProperty(_assertThisInitialized(o = t.call(this, e)), "requestProtocolDetail", function(e) {
        _processor.AmosFetch.get((0, _urlFormat.default)(_urlConsts.default.protocolDetail, {
          id: e
        })).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          "SUCCESS" === e.result && null !== e.dataList && o.setState({
            detailData: e.dataList
          })
        })
      }), _defineProperty(_assertThisInitialized(o), "handleEditParam", function(e) {
        var a = o.props.form.getFieldValue("protocolName"),
          r = o.props.form.getFieldValue("protocolVersion"),
          l = o.props.form.getFieldValue("descr");
        o.props.form.getFieldValue("time");
        o.setState({
          textEdit: !o.state.textEdit
        }), o.state.textEdit && o.props.form.validateFields(function(e, t) {
          e ? o.setState({
            textEdit: !0
          }) : (e = _extends(o.state.detailData, {
            name: a,
            version: r,
            descr: l,
            dicIdScriptLang: null,
            scriptLang: null
          }), o.submitBasicData(e))
        })
      }), _defineProperty(_assertThisInitialized(o), "submitBasicData", function(e) {
        _processor.AmosFetch.post(_urlConsts.default.protocolSave, {
          data: e
        }).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          "SUCCESS" === e.result ? _amosFramework.message.success("编辑成功！") : (o.setState({
            textEdit: !0
          }), _amosFramework.message.danger("编辑失败！"))
        })
      }), _defineProperty(_assertThisInitialized(o), "handleEditCode", function(e) {
        var r = o.props.form.getFieldValue("realization"),
          l = (0, _amosTool.trim)(o.props.form.getFieldValue("code"));
        l && "" !== l ? (o.setState({
          scriptEdit: !o.state.scriptEdit
        }), o.state.scriptEdit && o.props.form.validateFields(function(e, t) {
          var a;
          e ? o.setState({
            textEdit: !0
          }) : (e = {
            id: (a = o.state.detailData).id,
            dicIdScriptLang: r,
            scriptCode: l
          }, o.submitBasicData(e), o.setState({
            detailData: _extends(a, e)
          }))
        })) : _amosAntd.Modal.info({
          title: "提示",
          content: "代码不能为空！",
          okText: "确定"
        })
      }), _defineProperty(_assertThisInitialized(o), "handleAddProperty", function(e) {}), _defineProperty(_assertThisInitialized(o), "handleDebug", function(e) {
        _amosFramework.message.success("测试成功！")
      }), _defineProperty(_assertThisInitialized(o), "delProperty", function(e) {}), o.state = {
        textEdit: !1,
        scriptEdit: !1,
        detailData: {}
      }, o
    }
    return _createClass(a, [{
      key: "componentWillMount",
      value: function() {}
    }, {
      key: "componentDidMount",
      value: function() {
        var e = this.props.selected;
        e && e.id && this.requestProtocolDetail(e.id)
      }
    }, {
      key: "render",
      value: function() {
        var e = this.props.form.getFieldProps,
          t = this.state,
          a = t.textEdit,
          r = t.scriptEdit,
          l = t.detailData,
          o = !1 === a ? "protocol-detail-title-button" : "protocol-detail-title-button-hidden",
          n = !1 === a ? "protocol-detail-title-button-hidden" : "protocol-detail-title-button",
          i = !1 === a ? "protocol-detail-title-content" : "protocol-detail-title-content-hidden",
          c = !1 === a ? "protocol-detail-title-content-hidden" : "protocol-detail-title-content",
          s = !1 === r ? "protocol-detail-property-button" : "protocol-detail-property-button-hidden",
          u = !1 === r ? "protocol-detail-property-button-hidden" : "protocol-detail-property-button",
          d = !1 === r ? "protocol-detail-property-content" : "protocol-detail-property-content-hidden",
          p = !1 === r ? "protocol-detail-property-content-hidden" : "protocol-detail-property-content",
          f = l.visibility,
          m = this.props.scriptLangOptions.map(function(e) {
            return e.value === l.dicIdScriptLang ? "Groovy" === e.label ? _react.default.createElement(_amosAntd.Radio, {
              checked: !0,
              key: e.value,
              value: "".concat(e.value)
            }, e.label) : _react.default.createElement(_amosAntd.Radio, {
              checked: !0,
              key: e.value,
              value: "".concat(e.value),
              disabled: !0
            }, e.label) : "Groovy" === e.label ? _react.default.createElement(_amosAntd.Radio, {
              key: e.value,
              value: "".concat(e.value)
            }, e.label) : _react.default.createElement(_amosAntd.Radio, {
              key: e.value,
              value: "".concat(e.value),
              disabled: !0
            }, e.label)
          }),
          _ = e("protocolName", {
            initialValue: l.name || "",
            rules: [{
              required: !0,
              message: "名称不能为空！"
            }, {
              validator: (0, _validate.noSpaceLengthValidate)(50, !0, "名称不能为空！")
            }]
          }),
          y = e("protocolVersion", {
            initialValue: l.version || "",
            rules: [{
              required: !0,
              message: "版本不能为空！"
            }, {
              validator: (0, _validate.noSpaceLengthValidate)(20, !0, "版本不能为空！")
            }]
          }),
          t = e("realization", {
            initialValue: "".concat(l.dicIdScriptLang) || "1",
            rules: [{
              required: !1,
              message: "实现方式不能为空！"
            }]
          }),
          r = e("code", {
            initialValue: l.scriptCode || "",
            rules: [{
              required: !1,
              message: "代码不能为空！"
            }]
          }),
          e = e("descr", {
            initialValue: l.descr || "",
            rules: [{
              validator: (0, _validate.noSpaceLengthValidate)(maxDescLength, !1, null)
            }]
          });
        return console.log(l), _react.default.createElement("div", {
          className: "protocol-detail"
        }, _react.default.createElement("div", {
          className: "protocol-detail-title"
        }, _react.default.createElement("label", null, "基本信息"), 1 === f ? _react.default.createElement("span", null, _react.default.createElement("div", {
          onClick: this.handleEditParam,
          className: o
        }, _react.default.createElement("img", {
          src: require("./../../../assets/iot/img/list_edit.png"),
          alt: ""
        }), _react.default.createElement("label", null, "编辑")), _react.default.createElement("div", {
          onClick: this.handleEditParam,
          className: n
        }, _react.default.createElement("img", {
          src: require("./../../../assets/iot/img/list_edit.png"),
          alt: ""
        }), _react.default.createElement("label", null, "确认"))) : null), _react.default.createElement("div", {
          className: i
        }, _react.default.createElement("span", null, _react.default.createElement("label", {
          className: "protocol-title-name"
        }, "协议名称： ", l.name || "")), _react.default.createElement("span", null, _react.default.createElement("label", {
          className: "protocol-title-name"
        }, "版  本： ", l.version || "")), _react.default.createElement("span", null, _react.default.createElement("label", {
          className: "protocol-title-name"
        }, "时  间： ", l.createTime ? (0, _DateUtil.dateToStr)(l.createTime) : "")), _react.default.createElement("span", {
          style: {
            height: "70px",
            "overflow-y": "auto",
            padding: "5px"
          }
        }, _react.default.createElement("label", {
          className: "protocol-title-name"
        }, "说  明： ", l.descr || ""))), _react.default.createElement("div", {
          className: c
        }, _react.default.createElement(_amosAntd.Form, {
          horizontal: !0,
          onSubmit: this.handleSubmit
        }, _react.default.createElement(FormItem, {
          label: "名称: ",
          labelCol: {
            span: 2
          },
          wrapperCol: {
            span: 22
          }
        }, _react.default.createElement(_amosAntd.Input, _extends({
          disabled: !a
        }, _, {
          style: {
            width: 250
          }
        }))), _react.default.createElement(FormItem, {
          label: "版本: ",
          labelCol: {
            span: 2
          },
          wrapperCol: {
            span: 22
          }
        }, _react.default.createElement(_amosAntd.Input, _extends({
          disabled: !a
        }, y, {
          style: {
            width: 250
          }
        }))), _react.default.createElement(FormItem, {
          label: "说明: ",
          labelCol: {
            span: 2
          },
          wrapperCol: {
            span: 22
          }
        }, _react.default.createElement(_amosAntd.Input, _extends({
          disabled: !a
        }, e, {
          style: {
            width: 250
          }
        }))))), _react.default.createElement("div", {
          className: "protocol-detail-property"
        }, _react.default.createElement("label", null, "脚本信息"), 1 === f ? _react.default.createElement("span", null, _react.default.createElement("div", {
          onClick: this.handleEditCode,
          className: s
        }, _react.default.createElement("img", {
          src: require("./../../../assets/iot/img/list_edit.png"),
          alt: ""
        }), _react.default.createElement("label", null, "编辑")), _react.default.createElement("div", {
          onClick: this.handleEditCode,
          className: u
        }, _react.default.createElement("img", {
          src: require("./../../../assets/iot/img/list_edit.png"),
          alt: ""
        }), _react.default.createElement("label", null, "确认"))) : null), _react.default.createElement("div", {
          className: d
        }, _react.default.createElement("span", null, _react.default.createElement("label", {
          className: "protocol-content-name"
        }, "实现方式： "), _react.default.createElement("div", {
          className: "protocol-content-value"
        }, _react.default.createElement(RadioGroup, null, m))), _react.default.createElement("span", {
          style: {
            height: "calc(100% - 50px)"
          }
        }, _react.default.createElement("label", {
          className: "protocol-content-name"
        }, "代  码： "), _react.default.createElement("div", {
          className: "protocol-content-code"
        }, _react.default.createElement(TextArea, {
          value: l.scriptCode || ""
        })))), _react.default.createElement("div", {
          className: p
        }, _react.default.createElement(_amosAntd.Form, {
          horizontal: !0,
          onSubmit: this.handleSubmit
        }, _react.default.createElement(FormItem, {
          label: "实现方式: ",
          labelCol: {
            span: 2
          },
          wrapperCol: {
            span: 22,
            offset: 0
          }
        }, _react.default.createElement(RadioGroup, t, m)), _react.default.createElement(FormItem, {
          label: "代码: ",
          labelCol: {
            span: 2
          },
          wrapperCol: {
            span: 12
          }
        }, _react.default.createElement(TextArea, r)))))
      }
    }]), a
  }();
PrivateProtocolDetail.displayName = "PrivateProtocolDetail", PrivateProtocolDetail.propTypes = {
  form: _propTypes.default.any,
  callBack: _propTypes.default.func
};
var _default = createForm(PrivateProtocolDetail);
exports.default = _default, module.exports = exports.default;
