// PersonalInfoForm.tsx
"use client";

import React from "react";
import { withFormik, type FormikBag } from "formik";

import InnerPersonalInfoForm from "./InnerPersonalInfoForm";
import { PersonalInfoFormValues } from "./types";
import { PERSONAL_INFO_EMPTY_VALUES } from "./constants";
import { PersonalInfoValidationSchema } from "./validation/PersonalInfoFormValidation";


/** اینا رو با Wizard خودت هماهنگ کن */
export interface WizardFormData {
  personalInfo: PersonalInfoFormValues;
  // ... بقیه step ها
}

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

const PersonalInfoForm = withFormik<PersonalInfoFormProps, PersonalInfoFormValues>({
  displayName: "PersonalInfoForm",

  enableReinitialize: true,

  mapPropsToValues: (props) => {
    return props.data?.personalInfo ?? PERSONAL_INFO_EMPTY_VALUES;
  },

  // validationSchema: PersonalInfoValidationSchema,

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

    props.update({ personalInfo: values });

    // برو مرحله بعد
    props.setStep((prev) => prev + 1);

    setSubmitting(false);
  },
})(InnerPersonalInfoForm);

export default PersonalInfoForm;
