import {
  MyBetaModalFormProps,
  MyButtons,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
import { Apis } from '@/gen/Apis';
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.Attendance.AttendanceConfigs.UpdateConfig>
      {...MyModalFormProps.props}
      title={`打卡配置`}
      trigger={<MyButtons.Edit title={`修改`} />}
      wrapperCol={{ span: 24 }}
      key={new Date().getTime()}
      width="500px"
      form={form}
      onOpenChange={(open: any) => {
        if (open && props.item) {
          form.setFieldsValue(props.item);
        }
      }}
      onFinish={async (values) =>
        Apis.Attendance.AttendanceConfigs.UpdateConfig({
          ...values,
          id: props.item?.id ?? 1,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '编辑成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          key: 'check_in_range',
          title: '可打卡范围',
          valueType: 'digit',
          fieldProps: {
            suffix: '米内',
            style: { width: '100%' },
          },
          formItemProps: { ...rulesHelper.number },
          colProps: { span: 24 },
        },
        {
          title: '是否要求拍照打卡',
          key: 'require_photo',
          valueType: 'switch',
          colProps: { span: 12 },
        },
        // {
        //   title: '是否允许范围外打卡',
        //   key: 'allow_out_range_checkin',
        //   valueType: 'switch',
        //   colProps: { span: 12 },
        // },
      ]}
    />
  );
}
