"use client"
import { withFormik } from "formik";
import * as Yup from "yup";
import InnerCreateTransferPackageForm from "./InnerCreateTransferPackageForm";
export interface CreateTransferPackageValues {
  location: string;
  price: string;
  locationImageIds: string[];
  galleryImageIds: string[];
  translations: {
    lang_id: number;
    name: string;
    content: string;
  }[];
}

export interface CreateTransferPackageProps {
  languages: {
    id: number;
    title: string;
    slug: string;
  }[];
  createPending: boolean;

}


const CreateTransferPackageForm = withFormik<
  CreateTransferPackageProps,
  CreateTransferPackageValues
>({
  mapPropsToValues: (props) => ({
    location: "",
    price: "",
    locationImageIds: [],
    galleryImageIds: [],
    translations: props.languages.map((lang) => ({
      lang_id: lang.id,
      name: "",
      content: "",
    })),
  }),

  validationSchema: Yup.object().shape({
    location: Yup.string().required("موقعیت الزامی است"),
    price: Yup.string().required("قیمت الزامی است"),
    translations: Yup.array().of(
      Yup.object().shape({
        name: Yup.string().required("نام الزامی است"),
        content: Yup.string().required("محتوا الزامی است"),
      }),
    ),
  }),

  handleSubmit: (values, { props }) => {
   console.log(values)
  },
})(InnerCreateTransferPackageForm);

export default CreateTransferPackageForm;
