import { useMutation } from "@tanstack/react-query";
import { ContactFormValues } from "./schema";
import { apiPost } from "../../../lib/api/methods";
import { CONTACT_ENDPOINTS } from "./endpoints";
import { errorToast, successToast } from "../../../utils/toast";
import { SUCCESS_MESSAGES } from "./messages";


export default function useContactUs() {
  const { mutateAsync, isPending } = useMutation({
    mutationKey: ["contact-us"],
    mutationFn: async (data: ContactFormValues) => {
      const response = await apiPost(CONTACT_ENDPOINTS.CONTACT_US, {
        ...data,
        dialCode: data.mobileNumber.dialCode,
        phoneNumber: data.mobileNumber.number,
      });
      return response.data;
    },
    onSuccess: (data) => {
      successToast(SUCCESS_MESSAGES.SEND_MESSAGE);
    },
    onError: (error) => {
      errorToast("Something Went Wrong");
    },
  });

  return { contactToSupport: mutateAsync, isContactingSupport: isPending };
}
