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.Contract.ContractArchiveTransfers.Store>
      {...MyModalFormProps.props}
      title={`${props.title}`}
      wrapperCol={{ span: 24 }}
      width="600px"
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open) {
          form.setFieldsValue({
            files: props?.item?.archive_files,
          });
        }
      }}
      trigger={
        <MyButtons.Default
          size="small"
          type="primary"
          title={props?.title ?? '转交'}
        />
      }
      onFinish={async (values: any) => {
        console.log(values, 'values');
        return Apis.Contract.ContractArchiveTransfers.Store({
          ...values,
          contract_archives_id: props?.item?.id,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false);
      }}
      columns={[
        Selects?.Employees({
          title: '新保管人',
          dataIndex: 'new_keeper_id',
          key: 'new_keeper_id',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
          fieldProps: {
            showSearch: true,
          },
          required: true,
        }),
        {
          key: 'remark',
          title: '备注',
          dataIndex: 'remark',
          valueType: 'textarea',
          colProps: { span: 24 },
        },
      ]}
    />
  );
}
