"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _react = _interopRequireWildcard(require("react")),
  _amosAntd = require("amos-antd"),
  _propTypes = _interopRequireDefault(require("prop-types")),
  _processor = require("../../utils/processor"),
  _urlConsts = _interopRequireDefault(require("../../consts/urlConsts")),
  _amosFramework = require("amos-framework"),
  _amosTool = require("amos-tool"),
  _protocolTestView = _interopRequireDefault(require("./protocolTestView")),
  _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 r, a, n = {},
    o = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((a = o ? Object.getOwnPropertyDescriptor(e, r) : null) && (a.get || a.set) ? Object.defineProperty(n, r, a) : 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, a = arguments[t];
      for (r in a) Object.prototype.hasOwnProperty.call(a, r) && (e[r] = a[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 a = t[r];
    a.enumerable = a.enumerable || !1, a.configurable = !0, "value" in a && (a.writable = !0), Object.defineProperty(e, a.key, a)
  }
}

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 a = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, a ? (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 createForm = _amosAntd.Form.create(),
  FormItem = _amosAntd.Form.Item,
  Panel = _amosAntd.Collapse.Panel,
  RadioGroup = _amosAntd.Radio.Group,
  TextArea = _amosAntd.Input.TextArea,
  maxDescLength = 250,
  AddProtocol = function() {
    _inherits(r, _react.Component);
    var t = _createSuper(r);

    function r(e) {
      var a;
      return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(a = t.call(this, e)), "onChange", function(e) {
        console.log("radio checked", e.target.value), a.setState({
          radiovalue: e.target.value
        })
      }), _defineProperty(_assertThisInitialized(a), "onClickDown", function(e) {
        e.preventDefault(), a.props.form.validateFields(function(e, t) {
          e || (t = (0, _validate.objOfStrPropTrim)(t), a.setState({
            itemInfo: t,
            activeKey: "2",
            btnVisible: !1
          }))
        })
      }), _defineProperty(_assertThisInitialized(a), "onClickUp", function() {
        a.setState({
          activeKey: "1"
        })
      }), _defineProperty(_assertThisInitialized(a), "onClick", function() {
        var e = _urlConsts.default.protocolSave,
          t = a.state.itemInfo;
        t.dicIdScriptLang = a.state.radiovalue;
        var r = a.props.form.getFieldValue,
          r = (0, _amosTool.trim)(r("scriptCode"));
        r && "" !== r ? (a.setState({
          waiting: !0
        }), t.scriptCode = r, _processor.AmosFetch.post(e, {
          data: t
        }).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          "SUCCESS" === e.result ? (_amosFramework.message.success("协议新增成功！"), a.props.updateAddView("2")) : (a.setState({
            waiting: !1
          }), _amosFramework.message.danger("协议新增失败！"))
        })) : _amosAntd.Modal.info({
          title: "提示",
          content: "代码不能为空！",
          okText: "确定"
        })
      }), _defineProperty(_assertThisInitialized(a), "delBtn", function() {
        _amosAntd.Modal.confirm({
          title: "删除",
          content: "是否删除所选信息？",
          okText: "确定",
          cancelText: "取消",
          onOk: function() {},
          onCancel: function() {}
        })
      }), _defineProperty(_assertThisInitialized(a), "testBtnFuncOpen", function() {
        a.setState({
          btnVisible: !0
        })
      }), _defineProperty(_assertThisInitialized(a), "testBtnFuncClose", function() {
        a.setState({
          btnVisible: !1
        })
      }), a.state = {
        scriptLangData: [],
        radiovalue: 12,
        activeKey: "1",
        interfaceProList: [],
        itemInfo: {},
        waiting: !1
      }, a
    }
    return _createClass(r, [{
      key: "componentDidMount",
      value: function() {
        var r = this;
        _processor.AmosFetch.get(_urlConsts.default.scriptLangType).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          var t;
          "SUCCESS" === e.result && (t = [], e && e.dataList.map(function(e) {
            "Groovy" === e.name ? t.push({
              value: e.id,
              label: e.name
            }) : t.push({
              value: e.id,
              label: e.name,
              disabled: !0
            })
          }), r.setState({
            scriptLangData: t
          }))
        })
      }
    }, {
      key: "render",
      value: function() {
        var e = this.state,
          t = e.itemInfo,
          r = (e.btnVisible, e.scriptLangData),
          a = t.name,
          n = t.version,
          o = t.descr,
          i = t.scriptCode,
          l = this.props.form.getFieldProps,
          e = {
            labelCol: {
              span: 10
            },
            wrapperCol: {
              span: 4
            }
          },
          t = {
            labelCol: {
              span: 7
            },
            wrapperCol: {
              span: 10
            }
          },
          a = l("name", {
            initialValue: a,
            rules: [{
              required: !0,
              message: "名称不能为空！"
            }, {
              validator: (0, _validate.noSpaceLengthValidate)(50, !0, "名称不能为空！")
            }]
          }),
          n = l("version", {
            initialValue: n,
            rules: [{
              required: !0,
              message: "版本不能为空！"
            }, {
              validator: (0, _validate.noSpaceLengthValidate)(20, !0, "版本不能为空！")
            }]
          }),
          o = l("descr", {
            initialValue: o,
            rules: [{
              validator: (0, _validate.noSpaceLengthValidate)(maxDescLength, !1, null)
            }]
          }),
          i = l("scriptCode", {
            initialValue: i
          });
        return _react.default.createElement("div", {
          className: "table-container"
        }, _react.default.createElement(_amosAntd.Collapse, {
          activeKey: this.state.activeKey,
          accordion: !0
        }, _react.default.createElement(Panel, {
          header: "新建协议",
          key: "1",
          showArrow: !1
        }, _react.default.createElement("div", {
          style: {
            textAlign: "center"
          }
        }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
          span: 24
        }, _react.default.createElement(FormItem, _extends({
          hasFeedback: !0,
          label: "名称"
        }, e), _react.default.createElement(_amosAntd.Input, _extends({
          className: "amos-grid-form-input"
        }, a, {
          placeholder: "请输入名称"
        }))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
          span: 24
        }, _react.default.createElement(FormItem, _extends({
          hasFeedback: !0,
          label: "版本"
        }, e), _react.default.createElement(_amosAntd.Input, _extends({
          className: "amos-grid-form-input"
        }, n, {
          placeholder: "请输入版本"
        }))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
          span: 24
        }, _react.default.createElement(FormItem, _extends({
          label: "描述"
        }, e), _react.default.createElement(_amosAntd.Input, _extends({
          className: "amos-grid-form-input"
        }, o, {
          placeholder: "请输入描述"
        }))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Button, {
          onClick: this.onClickDown
        }, "下一步")))), _react.default.createElement(Panel, {
          header: "新建脚本信息",
          key: "2",
          showArrow: !1
        }, _react.default.createElement("div", {
          style: {
            textAlign: "center"
          }
        }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
          span: 24
        }, _react.default.createElement(FormItem, _extends({
          hasFeedback: !0,
          label: "实现方式"
        }, t, {
          wrapperCol: {
            span: 5,
            offset: 0
          }
        }), _react.default.createElement(RadioGroup, {
          options: r,
          onChange: this.onChange,
          value: this.state.radiovalue
        })))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
          span: 24
        }, _react.default.createElement(FormItem, _extends({
          hasFeedback: !0,
          label: "代码"
        }, t), _react.default.createElement(TextArea, _extends({}, i, {
          autosize: {
            minRows: 8,
            maxRows: 20
          }
        })))))), _react.default.createElement("div", {
          style: {
            height: "2rem"
          }
        }), _react.default.createElement(_amosAntd.Row, {
          type: "flex",
          justify: "center"
        }, _react.default.createElement(_amosAntd.Button, {
          onClick: this.onClickUp
        }, "上一步"), _react.default.createElement("div", {
          style: {
            width: "1.5rem"
          }
        }), _react.default.createElement(_amosAntd.Button, {
          onClick: this.onClick,
          disabled: this.state.waiting
        }, "确定")))))
      }
    }]), r
  }();
AddProtocol.displayName = "AddProtocol", AddProtocol.propTypes = {
  form: _propTypes.default.any,
  updateAddView: _propTypes.default.func
};
var _default = createForm(AddProtocol);
exports.default = _default, module.exports = exports.default;
