import React from "react";
import { getInitialValues, getValidationSchema } from "./formUtil";
import { ModalEnum } from "../../../enums/Model";
import LayoutModel from "../../../Layout/Dashboard/LayoutModel";
import { QueryStatusEnum } from "../../../enums/QueryStatus";
import ModelForm from "./ModelForm";
import { useAddReSeller } from "../../../api/ReSeller";

const AddModel: React.FC = () => {
  const { mutate, status } = useAddReSeller();

  const handleSubmit = (values: any) => {
    const newValue = JSON.parse(JSON.stringify({...values}))
    const location = {lat:newValue?.lat,lng:newValue?.lng}
    mutate({
      ...newValue,
      location
    });
  };
  return (
    <>
      <LayoutModel
        status={status as QueryStatusEnum}
        ModelEnum={ModalEnum.RE_SELLER_ADD}
        modelTitle="ReSeller"
        handleSubmit={handleSubmit}
        getInitialValues={getInitialValues({})}
        getValidationSchema={getValidationSchema}
      >
        <ModelForm />
      </LayoutModel>
    </>
  );
};

export default AddModel;
