"use client";

import React from "react";
import { withFormik, type FormikBag } from "formik";
import { EDUCATION_EMPTY_VALUES } from "./constants";
import InnerEducationForm from "./InnerEducationForm";

export interface EducationItem {
  degree: string;
  field: string;
  university: string;
  startYear: number | "";
  endYear: number | "";
  gpa: number | "";
  certificateImageId: string;
  description: string;
}

export interface EducationFormValues {
  education: EducationItem[];
}

/** این بخش را با WizardFormData واقعی پروژه‌ات هماهنگ کن */
export interface WizardFormData {
  education: EducationItem[];
  // ... other steps
}

export type EducationFormProps = {
  step: number;
  setStep: React.Dispatch<React.SetStateAction<number>>;
  data: WizardFormData;
  update: (patch: Partial<WizardFormData>) => void;
};

const EducationForm = withFormik<EducationFormProps, EducationFormValues>({
  displayName: "EducationForm",
  enableReinitialize: true,

  mapPropsToValues: (props) => {
    return {
      education: props.data?.education ?? EDUCATION_EMPTY_VALUES,
    };
  },

  // validationSchema: EducationValidationSchema,

  handleSubmit: async (
    values,
    bag: FormikBag<EducationFormProps, EducationFormValues>,
  ) => {
    const { props, setSubmitting } = bag;

    props.update({ education: values.education });
    props.setStep((prev) => prev + 1);

    setSubmitting(false);
  },
})(InnerEducationForm);

export default EducationForm;
