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

export default function Refund(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Refund.Refunds.Complete>
      {...MyModalFormProps.props}
      title={props.title}
      width="500px"
      wrapperCol={{ span: 24 }}
      trigger={
        <MyButtons.Default
          size="small"
          type="primary"
          disabled={props?.item?.refund_status !== 'Approved'}
          title={props.title}
        />
      }
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      onFinish={async (values) =>
        Apis.Refund.Refunds.Complete({
          ...values,
          id: props.item?.id ?? '',
        })
          .then(() => {
            props.reload?.();
            message.success('提交成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          title: '退款流水号',
          colProps: { span: 24 },
          key: 'serial_number',
          formItemProps: { ...rulesHelper.text },
        },
        {
          title: '退款时间',
          key: 'refund_time',
          colProps: { span: 24 },
          fieldProps: {
            style: {
              width: '100%',
            },
          },
          valueType: 'dateTime',
        },
        MyFormItems.UploadImages({
          key: 'voucher',
          title: '	退款凭证',
          uploadType: 'file',
          colProps: { span: 24 },
          max: 10,
        }),
      ]}
    />
  );
}
