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

interface formUtilCommon {
  link:string
  image:string,
}

interface ObjectToEdit extends formUtilCommon {
    id?:number,
    is_active:boolean,
}

export interface InitialValues extends ObjectToEdit {
    id?:number,
    is_active:boolean,
}
interface ValidateSchema  extends formUtilCommon{

}

export const getInitialValues = (objectToEdit: ObjectToEdit | null = null): InitialValues => {
 
  // console.log(objectToEdit);
  
  return {
    id:objectToEdit?.id?? 0 ,
    link:objectToEdit?.link?? "",
    image:objectToEdit?.image?? "",
    is_active:objectToEdit?.is_active?? true,
  }
};

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

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

