"use client";
import {withFormik} from "formik";
import InnerResetPasswordForm from "./InnerResetPasswordForm";
import {AppRouterInstance} from "next/dist/shared/lib/app-router-context.shared-runtime";
import axios from "axios";
import {toast} from "react-toastify";
import privateApi from "@/service/http/privateCall.axios";

export interface ResetPasswordFormValues {
  username: string;
  email: string;
}

export interface ResetPasswordFormProps {
  router: AppRouterInstance;
}
const ResetPasswordForm = withFormik<
  ResetPasswordFormProps,
  ResetPasswordFormValues
>({
  mapPropsToValues: () => ({
    username: "",
    email: "",
  }),
  handleSubmit: async (values, {props}) => {
    try {
      await privateApi.post("/auth/forgot-password", values);
    } catch (error) {
      if (axios.isAxiosError(error)) {
        toast.error(error.response?.data?.error?.message);
      } else {
        console.error("Unexpected error:", error);
      }
    }
  },
})(InnerResetPasswordForm);

export default ResetPasswordForm;
