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

interface formUtilCommon {
  name:string,
  image:string,
  email:string,
  position: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 => {
 
  
  return {
    id:objectToEdit?.id?? null ,
    name:objectToEdit?.name ?? "",
    image:objectToEdit?.image?? "",
    position:objectToEdit?.position?? "",
    email:objectToEdit?.email?? "",

  }


};

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

  });
};

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

