
import * as Yup from "yup";
import { buildFormData } from "../../api/helper/buildFormData";

interface formUtilCommon {
  title:string,
  image:string 
  hover_image:string ,
  video:string ,

}

interface ObjectToEdit extends formUtilCommon {

  id?:number,

}

export interface InitialValues extends ObjectToEdit {
  title:string,
  image:string 
  hover_image:string ,
  video:string ,
  id?:number,

}
interface ValidateSchema  extends formUtilCommon{

}

export const getInitialValues = (objectToEdit: ObjectToEdit | null = null): InitialValues => {
//  console.log(objectToEdit);
 

  return {
    id:objectToEdit?.id?? 0 ,
    title:objectToEdit?.title ?? "",
    image:objectToEdit?.image?? "",
    hover_image:objectToEdit?.hover_image?? "",
    video:objectToEdit?.video?? "",

  }


};

export const getValidationSchema = (editMode: boolean = false): Yup.Schema<ValidateSchema> => {
    // validate input  
  return Yup.object().shape({
    title:Yup.string().required('required'),
    image:Yup.string().required("required"),
    hover_image:Yup.string().required("required"),
    video:Yup.string().required("required"),
  });
};

export const getDataToSend = (values: any): FormData => {
  const data = { ...values };
  
  if(typeof data['image'] == 'string') delete data['image']
  if(typeof data['hover_image'] == 'string') delete data['hover_image']
  if(typeof data['video'] == 'string') delete data['video']

  // const formData = new FormData();
  // buildFormData(formData, data);
  return data;
};

