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

export default function Reject(props: MyBetaModalFormProps) {
  return (
    <BetaSchemaForm<ApiTypes.Visitor.VisitorApplies.Reject>
      {...MyModalFormProps.props}
      title="驳回"
      trigger={
        <MyButtons.Default
          title="驳回"
          disabled={props?.item?.status !== 'Pending'}
          size="small"
          type="default"
        />
      }
      wrapperCol={{ span: 24 }}
      key={new Date().getTime()}
      width="500px"
      onFinish={async (values) =>
        Apis.Visitor.VisitorApplies.Reject({
          ...values,
          id: props.item?.id ?? 0,
        })
          .then(() => {
            message.success('提交成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          title: '驳回理由',
          valueType: 'textarea',
          key: 'remark',
          formItemProps: { ...rulesHelper.text },
        },
      ]}
    />
  );
}
