import {
  MyBetaModalFormProps,
  MyButtons,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { Form, message } from 'antd';

export default function QuestionCategoriesCreate(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();

  return (
    <BetaSchemaForm<ApiTypes.Survey.QuestionCategories.Store>
      {...MyModalFormProps.props}
      form={form}
      title={`添加${props.title}`}
      wrapperCol={{ span: 24 }}
      key={new Date().getTime()}
      width="500px"
      trigger={<MyButtons.Create title={`添加${props.title}`} />}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      onFinish={async (values) =>
        Apis.Survey.QuestionCategories.Store({
          ...values,
          is_enabled: true,
        })
          .then(() => {
            props.reload?.();
            message.success(`添加${props.title}成功`);
            return true;
          })
          .catch(() => false)
      }
      columns={[
        { key: 'name', title: '名称', formItemProps: { ...rulesHelper.text } },
        {
          key: 'description',
          title: '描述',
          valueType: 'textarea',
        },
        // {
        //   key: 'is_enabled',
        //   title: '是否启用',
        //   valueType: 'switch',
        // },
        // MyFormItems.ColorPicker(),
      ]}
    />
  );
}
