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

export default function Index(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Approval.ApprovalTemplates.ReplaceApprover>
      {...MyModalFormProps.props}
      title={`批量修改审批人`}
      wrapperCol={{ span: 24 }}
      width="600px"
      trigger={
        <MyButtons.Default
          title={props.title || '批量修改审批人'}
          type="primary"
          size="middle"
        />
      }
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields();
        }
      }}
      key={new Date().getTime()}
      form={form}
      onFinish={async (values: any) => {
        return Apis.Approval.ApprovalTemplates.ReplaceApprover(values)
          .then(() => {
            props.reload?.();
            message.success('修改成功！');
            return true;
          })
          .catch(() => false);
      }}
      columns={[
        Selects?.Employees({
          title: '原审批人',
          key: 'from_employee_id',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
          required: true,
        }),
        Selects?.Employees({
          title: '选择新的审批人',
          key: 'to_employee_id',
          tooltip: '所有涉及到的审批模版，都修改成当前人',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
          required: true,
        }),
      ]}
    />
  );
}
