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

export default function Create(props: MyBetaModalFormProps) {
  return (
    <BetaSchemaForm<ApiTypes.Merchants.Store>
      {...MyModalFormProps.props}
      title={`添加${props.title}`}
      wrapperCol={{ span: 24 }}
      width="500px"
      trigger={<MyButtons.Create title={`添加${props.title}`} />}
      onFinish={async (values) =>
        Apis.Merchants.Store(values)
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        Selects.Agents({ required: true }),
        Selects.Bosses({ required: true }),
        Selects.Factories({ required: true }),
        Selects.Platforms({ required: true }),
        {
          key: 'name',
          title: '简称',
          formItemProps: { ...rulesHelper.text },
        },
        {
          key: 'full_name',
          title: '全称',
          formItemProps: { ...rulesHelper.text },
        },
      ]}
    />
  );
}
