import {
  MyBetaModalFormProps,
  MyButtons,
  MyFormItems,
  MyModalFormProps,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { AssetProjectsStatusEnum } 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.Asset.AssetProjects.Update>
      {...MyModalFormProps.props}
      title={`项目退出`}
      trigger={<MyButtons.Default title="退出" danger />}
      wrapperCol={{ span: 24 }}
      width="500px"
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        console.log(props.item, 'props.item');
        if (open && props.item) {
          form.setFieldsValue({
            ...props.item,
            casacader: [
              props.item?.province_id || '',
              props.item?.city_id || '',
              props.item?.area_id || '',
              props.item?.street_id || '',
            ],
            location: `${props.item?.longitude || ''},${
              props.item?.latitude || ''
            }`,
            status: 'Exited',
          });
        }
      }}
      onFinish={async (values: any) =>
        Apis.Asset.AssetProjects.Update({
          ...values,
          id: props.item?.id ?? 0,
          status: 'Exited',
          name: props.item?.name || '',
        })
          .then(() => {
            props.reload?.();
            message.success('编辑成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        MyFormItems.EnumSelect({
          key: 'status',
          title: '项目状态',
          colProps: { span: 24 },
          valueEnum: AssetProjectsStatusEnum,
          fieldProps: { disabled: true },
          // required: true,
        }),

        {
          key: 'exit_date',
          title: '退出日期',
          valueType: 'date',
          fieldProps: { style: { width: '100%' } },
          colProps: { span: 24 },
        },
      ]}
    />
  );
}
