import React from "react";
import FormItemInput from './form-item-input';
import FormItemTextarea from './form-item-textarea';
import FormItemSwitch from './form-item-switch';
import FormItemImage from './form-item-image';
import connect from "../connect";

export interface Props {
  type:
    | 'input' // 输入框
    | 'textarea' // 文本框
    | 'switch' // 开关
    | 'image'; // 图片上传
}

/**
 * 表单项
 */
const FormItem: React.FC<Props> = ({ type, ...otherProps }) => {
  if (type === 'input') return <FormItemInput {...otherProps} />;
  if (type === 'textarea') return <FormItemTextarea {...otherProps} />;
  if (type === 'switch') return <FormItemSwitch {...otherProps} />;
  if (type === 'image') return <FormItemImage {...otherProps} />;
  return null;
};

export default connect(FormItem, {}, {
  'input': (FormItemInput as any).default,
  'textarea': (FormItemTextarea as any).default,
  'switch': (FormItemSwitch as any).default,
  'image': (FormItemImage as any).default,
});
