import {withFormik} from "formik";
import {AppRouterInstance} from "next/dist/shared/lib/app-router-context.shared-runtime";

import {Expertise, getSingleUserDataType, Language, ServerResponse} from "@/types";
import {toast} from "react-toastify";
import {UseMutateAsyncFunction} from "@tanstack/react-query";
import InnerUpdateTransferTeamMemberForm from "./InnerUpdateTransferTeamMemberForm";
import {UsersType} from "@/constants";
import { CreateUserTranslation } from "../new/CreateTransferTeamMemberForm";

export interface CreateDoctorFormValues {
  translations: CreateUserTranslation[];
  type: UsersType;
  email: string;
  phone: string;
  medicalNumber: string;
  imageId: number | null;
  expertiseId: number | null;
}

export type UpdateUserVariables = {
  data: CreateDoctorFormValues;
  id: string;
};
export interface UpdateTransferTeamMemberFormProps {
  router: AppRouterInstance;
  preValues: getSingleUserDataType;
  expertises: Expertise[];
  languages: Language[];
  updateFn: UseMutateAsyncFunction<
    {status: number; data?: getSingleUserDataType[]; message: string},
    Error,
    UpdateUserVariables,
    ServerResponse
  >;
  id: string;
}

const UpdateTransferTeamMemberForm = withFormik<
  UpdateTransferTeamMemberFormProps,
  CreateDoctorFormValues
>({
  mapPropsToValues: (props) => ({
    translations: props?.preValues?.translations,
    email: props?.preValues?.email,
    phone: props?.preValues?.phone,
    expertiseId: props.preValues.expertiseId,
    imageId: null,
    medicalNumber: props?.preValues?.medicalNumber,
    type: "TRANSFER_TEAM",
  }),
  handleSubmit: async (values, {props}) => {
    try {
      const {message} = await props.updateFn({data: values, id: props.id});
      toast.success(message);
    } catch (error) {
      toast.error("dasd");
    }
  },
})(InnerUpdateTransferTeamMemberForm);

export default UpdateTransferTeamMemberForm;
