import {
  MyBetaModalFormProps,
  MyButtons,
  MyFormItems,
  MyModalFormProps,
  rulesHelper,
} from '@/common';

import { Apis } from '@/gen/Apis';
import { CompanyReceiptAccountsPayChannelEnum } from '@/gen/Enums';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { Form, message } from 'antd';
export default function Update(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Company.CompanyReceiptAccounts.Update>
      {...MyModalFormProps.props}
      title={`编辑${props.title}`}
      trigger={<MyButtons.Edit />}
      wrapperCol={{ span: 24 }}
      width="500px"
      form={form}
      onOpenChange={(open: any) => {
        if (open && props.item) {
          form.setFieldsValue(props.item);
        }
      }}
      onFinish={async (values) =>
        Apis.Company.CompanyReceiptAccounts.Update({
          ...values,
          companies_id: props?.item?.companies_id,
          id: props.item?.id ?? 0,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          key: 'company_name',
          title: '收款账户名称',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
        },
        {
          key: 'company_bank',
          title: '开户行',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
        },
        {
          key: 'company_account',
          title: '收款账户',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
        },
        MyFormItems.EnumRadio({
          key: 'pay_channel',
          title: '收款渠道',
          colProps: { span: 24 },
          valueEnum: CompanyReceiptAccountsPayChannelEnum,
          required: true,
        }),
        {
          key: 'is_default',
          title: '是否设为默认账号',
          valueType: 'switch',
          colProps: { span: 24 },
        },
      ]}
    />
  );
}
