"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 _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"), _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 _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, a = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? a : 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 a = _getRequireWildcardCache(t);
  if (a && a.has(e)) return a.get(e);
  var r = {}, l = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var o in e) if ("default" !== o && Object.prototype.hasOwnProperty.call(e, o)) {
    var i = l ? Object.getOwnPropertyDescriptor(e, o) : null;
    i && (i.get || i.set) ? Object.defineProperty(r, o, i) : r[o] = e[o];
  }
  return r.default = e, a && a.set(e, r), r;
}

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

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

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(e) {
  (0, _inherits2.default)(a, e);
  var t = _createSuper(a);
  function a(e) {
    var r;
    return (0, _classCallCheck2.default)(this, a), r = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(r), "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 && r.setState({
          detailData: e.dataList
        });
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "handleEditParam", (function(e) {
      var t = r.props.form.getFieldValue("protocolName"), a = r.props.form.getFieldValue("protocolVersion"), l = r.props.form.getFieldValue("descr");
      r.props.form.getFieldValue("time");
      r.setState({
        textEdit: !r.state.textEdit
      }), r.state.textEdit && r.props.form.validateFields((function(e, o) {
        if (e) r.setState({
          textEdit: !0
        }); else {
          var i = r.state.detailData, n = (0, _extends2.default)(i, {
            name: t,
            version: a,
            descr: l,
            dicIdScriptLang: null,
            scriptLang: null
          });
          r.submitBasicData(n);
        }
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "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("编辑成功！") : (r.setState({
          textEdit: !0
        }), _amosFramework.message.danger("编辑失败！"));
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "handleEditCode", (function(e) {
      var t = r.props.form.getFieldValue("realization"), a = (0, _amosTool.trim)(r.props.form.getFieldValue("code"));
      a && "" !== a ? (r.setState({
        scriptEdit: !r.state.scriptEdit
      }), r.state.scriptEdit && r.props.form.validateFields((function(e, l) {
        if (e) r.setState({
          textEdit: !0
        }); else {
          var o = r.state.detailData, i = {
            id: o.id,
            dicIdScriptLang: t,
            scriptCode: a
          };
          r.submitBasicData(i), r.setState({
            detailData: (0, _extends2.default)(o, i)
          });
        }
      }))) : _amosAntd.Modal.info({
        title: "提示",
        content: "代码不能为空！",
        okText: "确定"
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "handleAddProperty", (function(e) {})), 
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "handleDebug", (function(e) {
      _amosFramework.message.success("测试成功！");
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "delProperty", (function(e) {})), 
    r.state = {
      textEdit: !1,
      scriptEdit: !1,
      detailData: {}
    }, r;
  }
  return (0, _createClass2.default)(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", i = !1 === a ? "protocol-detail-title-button-hidden" : "protocol-detail-title-button", n = !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", m = l.visibility, f = 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, "名称不能为空！")
        } ]
      }), h = e("protocolVersion", {
        initialValue: l.version || "",
        rules: [ {
          required: !0,
          message: "版本不能为空！"
        }, {
          validator: (0, _validate.noSpaceLengthValidate)(20, !0, "版本不能为空！")
        } ]
      }), b = e("realization", {
        initialValue: "".concat(l.dicIdScriptLang) || "1",
        rules: [ {
          required: !1,
          message: "实现方式不能为空！"
        } ]
      }), v = 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 === m ? _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: i
      }, _react.default.createElement("img", {
        src: require("./../../../assets/iot/img/list_edit.png"),
        alt: ""
      }), _react.default.createElement("label", null, "确认"))) : null), _react.default.createElement("div", {
        className: n
      }, _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, (0, _extends2.default)({
        disabled: !a
      }, _, {
        style: {
          width: 250
        }
      }))), _react.default.createElement(FormItem, {
        label: "版本: ",
        labelCol: {
          span: 2
        },
        wrapperCol: {
          span: 22
        }
      }, _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        disabled: !a
      }, h, {
        style: {
          width: 250
        }
      }))), _react.default.createElement(FormItem, {
        label: "说明: ",
        labelCol: {
          span: 2
        },
        wrapperCol: {
          span: 22
        }
      }, _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        disabled: !a
      }, E, {
        style: {
          width: 250
        }
      }))))), _react.default.createElement("div", {
        className: "protocol-detail-property"
      }, _react.default.createElement("label", null, "脚本信息"), 1 === m ? _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, f))), _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, b, f)), _react.default.createElement(FormItem, {
        label: "代码: ",
        labelCol: {
          span: 2
        },
        wrapperCol: {
          span: 12
        }
      }, _react.default.createElement(TextArea, v)))));
    }
  } ]), a;
}(_react.Component);

PrivateProtocolDetail.displayName = "PrivateProtocolDetail", PrivateProtocolDetail.propTypes = {
  form: _propTypes.default.any,
  callBack: _propTypes.default.func
};

var _default = createForm(PrivateProtocolDetail);

exports.default = _default;