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';

const JudgmentEnum = {
  Yes: { text: '有效工单', color: '#ff0000', value: 'Yes' },
  No: { text: '无效工单', color: '#00ff00', value: 'No' },
};

type FormDataType = ApiTypes.WorkOrder.HouseWorkOrders.Assign & {
  attachments?: any[];
  judgment?: string;
};

export default function WorkOrderAssign(
  props: MyBetaModalFormProps & { item: any },
) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.WorkOrder.HouseWorkOrders.Assign>
      {...MyModalFormProps.props}
      title={`指派工单`}
      wrapperCol={{ span: 19 }}
      width="500px"
      layout="horizontal"
      labelCol={{ span: 5 }}
      trigger={
        <MyButtons.Default title={props.item.title || '指派'} type="primary" />
      }
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      onFinish={async (values: any) => {
        return Apis.WorkOrder.HouseWorkOrders.Assign({
          ...values,
          id: props.item.house_work_orders_id,
          predict_complete_at: props.item.end_time,
          level: props.item.level,
        })
          .then(() => {
            props.reload?.();
            message.success('指派工单成功');
            return true;
          })
          .catch(() => false);
      }}
      columns={[
        Selects?.Employees({
          title: '选择处理人',
          key: 'assign_employees_id',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
          required: true,
        }),
        {
          title: '备注',
          key: 'assign_remark',
          valueType: 'textarea',
          colProps: { span: 24 },
          fieldProps: {
            style: { width: '100%' },
          },
        },
      ]}
    />
  );
}
