"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")), _amosTool = require("amos-tool"), _amosFramework = require("amos-framework");

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var r = new WeakMap, t = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? t : r;
  })(e);
}

function _interopRequireWildcard(e, r) {
  if (!r && e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var t = _getRequireWildcardCache(r);
  if (t && t.has(e)) return t.get(e);
  var a = {}, n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var o in e) if ("default" !== o && Object.prototype.hasOwnProperty.call(e, o)) {
    var l = n ? Object.getOwnPropertyDescriptor(e, o) : null;
    l && (l.get || l.set) ? Object.defineProperty(a, o, l) : a[o] = e[o];
  }
  return a.default = e, t && t.set(e, a), a;
}

function _createSuper(e) {
  var r = _isNativeReflectConstruct();
  return function() {
    var t, a = (0, _getPrototypeOf2.default)(e);
    if (r) {
      var n = (0, _getPrototypeOf2.default)(this).constructor;
      t = Reflect.construct(a, arguments, n);
    } else t = a.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;
  }
}

var FormItem = _amosFramework.Form.Item, FormFooter = _amosFramework.Form.Footer, TextArea = _amosFramework.Input.TextArea, formItemLayout = {
  labelCol: {
    xs: {
      span: 10
    },
    sm: {
      span: 6
    },
    className: "colspanlab"
  },
  wrapperCol: {
    xs: {
      span: 14
    },
    sm: {
      span: 18
    },
    className: "colspan"
  }
}, CreateLibForm = function(e) {
  (0, _inherits2.default)(t, e);
  var r = _createSuper(t);
  function t(e) {
    var a;
    (0, _classCallCheck2.default)(this, t), a = r.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(a), "onChange", (function(e, r) {
      var t = a.state.form, n = r.target.value;
      t[e] = n, a.setState({
        form: t
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleSubmit", (function(e) {
      e.preventDefault(), a.form.validate((function(e, r) {
        if (console.log("返回内容:", r, e), !e) return console.log("error submit!!"), !1;
        var t = a.props.libObj.id;
        void 0 !== t && (0, _extends2.default)(r, {
          id: t
        }), a.props.onSave(r);
      }));
    }));
    var n = e.libObj;
    return a.state = {
      form: {
        name: n.name || "",
        descr: n.descr || ""
      },
      rules: {
        name: [ {
          required: !0,
          message: "规则名称不能为空"
        }, {
          min: 1,
          max: 150,
          message: "长度范围：1-150！"
        } ],
        descr: [ {
          required: !1
        }, {
          min: 0,
          max: 150,
          message: "长度范围：0-150！"
        } ]
      }
    }, a;
  }
  return (0, _createClass2.default)(t, [ {
    key: "componentWillReceiveProps",
    value: function(e) {
      _amosTool.utils.isEmpty(e.libObj) || this.setState({
        name: e.libObj.name || "",
        descr: e.libObj.descr || ""
      });
    }
  }, {
    key: "render",
    value: function() {
      var e = this, r = this.state, t = r.form, a = r.rules, n = {
        width: 230
      };
      return _react.default.createElement(_amosFramework.Form, {
        style: {
          width: 350
        },
        className: "create-libaray",
        ref: function(r) {
          return e.form = r;
        },
        model: t,
        rules: a
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: _react.default.createElement("span", null, "规则名称"),
        field: "name"
      }, formItemLayout), _react.default.createElement(_amosFramework.Input, {
        value: t.name,
        style: n,
        placeholder: "请输入规则名称",
        onChange: function(r) {
          return e.onChange("name", r);
        }
      })), _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "规则描述",
        field: "descr"
      }, formItemLayout), _react.default.createElement(TextArea, {
        rows: 4,
        value: t.descr,
        style: n,
        placeholder: "请输入规则描述",
        onChange: function(r) {
          return e.onChange("descr", r);
        }
      })), _react.default.createElement(FormFooter, null, _react.default.createElement("div", {
        className: "create-cancel-btn",
        onClick: this.props.cancelAction
      }, "取消"), _react.default.createElement("div", {
        className: "create-submit-btn",
        onClick: this.handleSubmit
      }, "提交")));
    }
  } ]), t;
}(_react.Component);

(0, _defineProperty2.default)(CreateLibForm, "propTypes", {
  form: _propTypes.default.any,
  onSave: _propTypes.default.func,
  libObj: _propTypes.default.object,
  cancelAction: _propTypes.default.func
}), (0, _defineProperty2.default)(CreateLibForm, "defaultProps", {
  onSave: function() {},
  libObj: {}
}), CreateLibForm.displayName = "CreateLibForm";

var _default = CreateLibForm;

exports.default = _default;