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

interface formUtilCommon {
  id?:number | null,
  title:string,
  sub_title:string,
  description:string,
  direction:boolean,
  is_have_button:boolean,
  image:string
}

interface ObjectToEdit extends formUtilCommon {

    id?:number | null,

}

export interface InitialValues extends ObjectToEdit {

}
interface ValidateSchema  extends formUtilCommon{

}

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

  return {
    id:objectToEdit?.id?? null ,
    title:objectToEdit?.title ?? "",
    sub_title:objectToEdit?.sub_title?? "",
    description:objectToEdit?.description?? "",
    direction:objectToEdit?.direction?? false,
    is_have_button:objectToEdit?.is_have_button?? false,
    image:objectToEdit?.image?? "",
  }


};

export const getValidationSchema = (editMode: boolean = false): Yup.Schema<ValidateSchema> => {
    // validate input  
  return Yup.object().shape({
    title:Yup.string().required('required'),
    sub_title:Yup.string().required("required"),
    description:Yup.string().required("required"),
    direction:Yup.bool().required("required"),
    is_have_button:Yup.bool().required("required"),
    image:Yup.string().required("required"),

  });
};

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

