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

export default function Create(props: MyBetaModalFormProps) {
  return (
    <BetaSchemaForm<ApiTypes.Banner.BannerSpaces.Store>
      {...MyModalFormProps.props}
      title={`添加广告位`}
      wrapperCol={{ span: 24 }}
      width="500px"
      trigger={<MyButtons.Create title={`添加广告位`} />}
      key={new Date().getTime()}
      onFinish={async (values) =>
        Apis.Banner.BannerSpaces.Store(values)
          .then(() => {
            props.reload?.();
            message.success('添加广告位成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          key: 'name',
          title: '广告位名称',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
        },
        MyFormItems.EnumRadio({
          key: 'type',
          title: '类型',
          colProps: { span: 24 },
          valueEnum: BannerSpacesTypeEnum,
          required: true,
        }),
        {
          key: 'remark',
          title: '备注',
          valueType: 'textarea',
          colProps: { span: 24 },
          fieldProps: {
            rows: 4,
            maxLength: 500,
            showCount: true,
          },
        },
      ]}
    />
  );
}
