"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _upload = _interopRequireDefault(require("@alifd/next/lib/upload"));
var _checkbox = _interopRequireDefault(require("@alifd/next/lib/checkbox"));
var _radio = _interopRequireDefault(require("@alifd/next/lib/radio"));
var _input = _interopRequireDefault(require("@alifd/next/lib/input"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _form = _interopRequireDefault(require("@alifd/next/lib/form"));
var _react = _interopRequireWildcard(require("react"));
require("./index.scss");
require("@wangeditor/editor/dist/css/style.css");
var _editorForReact = require("@wangeditor/editor-for-react");
var _dynamicColumnDataType = require("../../entity/dynamic-column-data-type");
var _right = _interopRequireDefault(require("../../assets/icon/form/right.png"));
var _excluded = ["dataList", "onClick", "children"]; // import { default as FormItem } from './form-item'
// import { convertChildren } from '../../utils/children-node-handle'
// import DCFormItem from './form-item.tsx'
// 引入 css
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var FormItem = _form["default"].Item;
var Form = function Form(_ref) {
  var dataList = _ref.dataList,
    _ref$onClick = _ref.onClick,
    onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
    children = _ref.children,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _otherProps = otherProps || {};
  dataList = [{
    id: '1042530112370774016',
    fkTableId: '1042530097875259392',
    tableName: 'dynamic_tb_lpjs',
    columnName: 'pic',
    selectActionType: 0,
    selectActionTypeEnum: {
      code: 0,
      name: '无',
      action: '',
      label: '',
      key: '',
      ordinal: 0
    },
    selectAction: '',
    selectActionValue: '',
    selectActionLabel: '',
    selectActionLabelArr: [],
    columnKeyType: 31,
    columnKeyTypeEnum: {
      code: 31,
      name: '富文本',
      dbTypeName: 'longtext',
      ordinal: 25
    },
    columnType: 'longtext',
    columnSize: 0,
    columnDecimal: 0,
    defaultValue: '',
    defaultValueType: 0,
    defaultValueTypeEnum: {
      code: 0,
      name: '无',
      ordinal: 0
    },
    isRequired: 0,
    isRequiredEnum: {
      code: 0,
      name: '否',
      ordinal: 0
    },
    columnComment: '图片',
    linkageColumn: '',
    linkageTable: '',
    linkageTableColumn: '',
    showAddType: 1,
    showAddTypeEnum: {
      code: 1,
      name: '是'
    },
    showUpdateType: 1,
    showUpdateTypeEnum: {
      code: 1,
      name: '是'
    },
    showListType: 0,
    showListTypeEnum: {
      code: 0,
      name: '否'
    },
    showViewType: 1,
    showViewTypeEnum: {
      code: 1,
      name: '是'
    },
    searchType: 0,
    searchTypeEnum: {
      code: 0,
      name: '不显示',
      ordinal: 0
    },
    updateType: 0,
    updateTypeEnum: {
      code: 0,
      name: '否'
    },
    scoreCode: 4,
    fieldWidth: 0,
    listWidth: '0',
    fieldSuffix: '',
    fieldPrefix: '',
    fieldDescription: '',
    guideWords: '请输入退伍军人证',
    fieldValidation: '',
    fieldValidationType: '自定义',
    inputFormat: 'jpg,jpeg,png,bmp,gif',
    optionType: 1,
    optionTypeEnum: {
      code: 1,
      name: '单选',
      ordinal: 1
    },
    fileMaxSize: 5,
    fileMinSize: 0,
    joinTable: '',
    joinColumn: '',
    showCondition: '',
    validationMax: '0',
    validationMin: '0',
    validationUnique: 0,
    validationUniqueEnum: {
      code: 0,
      name: '否'
    },
    showStyle: '',
    handler: '0',
    propList: [{
      id: '1048584180847480832',
      propName: 'updateType',
      propValue: '0'
    }, {
      id: '1048584180730040320',
      propName: 'searchType',
      propValue: '0'
    }, {
      id: '1048584180608405504',
      propName: 'columnType',
      propValue: 'longtext'
    }, {
      id: '1048584180495159296',
      propName: 'defaultValueType',
      propValue: '0'
    }, {
      id: '1048584180365135872',
      propName: 'validationMax',
      propValue: '0'
    }, {
      id: '1048584180235112448',
      propName: 'validationMin',
      propValue: '0'
    }, {
      id: '1048584180142837760',
      propName: 'showViewType',
      propValue: '1'
    }, {
      id: '1048584179996037120',
      propName: 'showUpdateType',
      propValue: '1'
    }, {
      id: '1048584179878596608',
      propName: 'showAddType',
      propValue: '1'
    }, {
      id: '1048584179740184576',
      propName: 'showListType',
      propValue: '0'
    }, {
      id: '1048584179622744064',
      propName: 'handler',
      propValue: '0'
    }, {
      id: '1050823809420103680',
      propName: 'columnComment',
      propValue: '图片'
    }, {
      id: '1050823809323634688',
      propName: 'isRequired',
      propValue: '0'
    }, {
      id: '1050823809222971392',
      propName: 'scoreCode',
      propValue: '4'
    }]
  }];
  // 筛选字段(去除按钮类型和自动生成的类型)
  dataList = dataList ? dataList.filter(function (item) {
    return item.columnKeyType !== _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_BUTTON.code && item.columnKeyType !== _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_AUTO.code && item.columnComment !== '乐观锁' && item.columnComment !== '是否删除';
  }) : [];
  console.log('dataList', dataList);

  // editor 实例
  var _useState = (0, _react.useState)(null),
    editor = _useState[0],
    setEditor = _useState[1]; // TS 语法
  // const [editor, setEditor] = useState(null)                   // JS 语法

  // 编辑器内容
  var _useState2 = (0, _react.useState)('<p>hello</p>'),
    html = _useState2[0],
    setHtml = _useState2[1];

  // 模拟 ajax 请求，异步设置 html
  (0, _react.useEffect)(function () {
    setTimeout(function () {
      setHtml('<p>hello world</p>');
    }, 1500);
  }, []);

  // 工具栏配置
  var toolbarConfig = {}; // TS 语法
  // const toolbarConfig = { }                        // JS 语法

  // 编辑器配置
  var editorConfig = {
    // TS 语法
    // const editorConfig = {                         // JS 语法
    placeholder: '请输入内容...'
  };

  // 及时销毁 editor ，重要！
  (0, _react.useEffect)(function () {
    return function () {
      if (editor == null) return;
      editor.destroy();
      setEditor(null);
    };
  }, [editor]);
  var renderFormTypeContent = function renderFormTypeContent(data) {
    switch (data.columnKeyType) {
      // 输入框
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_TEXT.code:
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_INT.code:
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_MOBILE.code:
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_NUMBER.code:
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_ID_CARD.code:
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_EMAIL.code:
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_LABEL.code:
        return /*#__PURE__*/_react["default"].createElement("div", {
          style: {
            width: '100%',
            display: 'flex'
          }
        }, /*#__PURE__*/_react["default"].createElement("div", {
          style: {
            color: '#999'
          }
        }, data.guideWords), /*#__PURE__*/_react["default"].createElement("img", {
          style: {
            width: '15px'
          },
          src: _right["default"],
          alt: ""
        }));
      // 多行文本
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_TEXTAREA.code:
        return /*#__PURE__*/_react["default"].createElement("div", {
          style: {
            width: '100%'
          }
        }, /*#__PURE__*/_react["default"].createElement(_input["default"].TextArea, {
          style: {
            width: '100%'
          },
          hasClear: true,
          placeholder: data.guideWords
        }));
      // 单选框
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_RADIO.code:
        return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_radio["default"].Group, {
          defaultValue: data.defaultValue
        }, data.columnOptionList ? data.columnOptionList.map(function (item) {
          return /*#__PURE__*/_react["default"].createElement(_radio["default"], {
            id: item.optionName,
            value: item.optionValue
          }, item.optionName);
        }) : /*#__PURE__*/_react["default"].createElement("div", null)));
      // 复选框
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_CHECKBOX.code:
        return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_checkbox["default"].Group, {
          defaultValue: data.defaultValue.split(',')[0]
        }, data.columnOptionList ? data.columnOptionList.map(function (item) {
          return /*#__PURE__*/_react["default"].createElement(_checkbox["default"], {
            id: item.optionName,
            value: item.optionValue
          }, item.optionName);
        }) : /*#__PURE__*/_react["default"].createElement("div", null)));
      // 附件,图片，音频，视频，文档
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_ATTACHMENTS.code:
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_DOC.code:
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_PICTURE.code:
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_VIDEO.code:
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_AUDIO.code:
        return /*#__PURE__*/_react["default"].createElement("div", {
          style: {
            display: 'flex'
          }
        }, /*#__PURE__*/_react["default"].createElement(_upload["default"].Card, {
          listType: "card",
          accept: "image/png, image/jpg, image/jpeg, image/gif, image/bmp"
        }));
      // 富文本
      case _dynamicColumnDataType.DYNAMIC_COLUMN_DATA_TYPE_EDITOR.code:
        return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
          style: {
            border: '1px solid #ccc',
            zIndex: 100
          }
        }, /*#__PURE__*/_react["default"].createElement(_editorForReact.Toolbar, {
          editor: editor,
          defaultConfig: toolbarConfig,
          mode: "default",
          style: {
            borderBottom: '1px solid #ccc'
          }
        }), /*#__PURE__*/_react["default"].createElement(_editorForReact.Editor, {
          defaultConfig: editorConfig,
          value: html,
          onCreated: setEditor,
          onChange: function onChange(editor) {
            return setHtml(editor.getHtml());
          },
          mode: "default",
          style: {
            height: '500px',
            overflowY: 'hidden'
          }
        })));
      default:
        return /*#__PURE__*/_react["default"].createElement("div", {
          style: {
            width: '100%',
            display: 'flex'
          }
        }, /*#__PURE__*/_react["default"].createElement("div", {
          style: {
            color: '#999'
          }
        }, data.guideWords), /*#__PURE__*/_react["default"].createElement("img", {
          style: {
            width: '15px'
          },
          src: _right["default"],
          alt: ""
        }));
    }
  };
  return /*#__PURE__*/_react["default"].createElement(_form["default"], (0, _extends2["default"])({
    className: "form__panel",
    isPreview: "false"
  }, _otherProps), dataList ? dataList.map(function (item, index) {
    var labelAlign = item.columnKeyTypeEnum.name === '图片' || item.columnKeyTypeEnum.name === '多行文本' || item.columnKeyTypeEnum.name === '附件' || item.columnKeyTypeEnum.name === '富文本' ? 'top' : 'left';
    var isFlexStyle = labelAlign === 'top' ? {} : {
      display: 'flex'
    };
    return /*#__PURE__*/_react["default"].createElement(FormItem, {
      key: index,
      label: item.columnComment,
      labelAlign: labelAlign,
      style: isFlexStyle
    }, /*#__PURE__*/_react["default"].cloneElement(renderFormTypeContent(item)));
  }) : /*#__PURE__*/_react["default"].createElement("div", null, "\u6682\u65E0\u8868\u5355\u9879"), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      width: '100%',
      display: 'flex',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/_react["default"].createElement(_form["default"].Submit, {
    style: {
      width: '90%'
    },
    type: "primary",
    validate: true
  }, "\u63D0\u4EA4")));
};
Form.displayName = 'Form';
var _default = exports["default"] = Form;