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


export const getInitialValues = (objectToEdit: any | null = null): any => {
  //@ts-ignore
  return {
    id: objectToEdit?.id ,
    name: objectToEdit?.name ,
    email: objectToEdit?.email ,
    type: objectToEdit?.type ,
    avatar: objectToEdit?.avatar ,

  };
};

export const getInitialValuesForAdd = (objectToEdit: any | null = null): any => {
  return {
    body_en: "" ,
    body_ar: "" ,
    body_de: "" ,
    // meta: "" ,
    title_en: "" ,
    title_ar: "" ,
    title_de: "" ,
    user_ids:[],
    // type: "" ,

  };
};

export const getValidationSchema = (editMode: boolean = false): Yup.Schema<any> => {
  // Validate input
  return Yup.object().shape({
    body_en: Yup.string().required('Required'),
    body_ar: Yup.string().required('Required'),
    body_de: Yup.string().required('Required'),
    // meta: Yup.string().required('Required'),

    title_en: Yup.string().required('Required'),
    title_ar: Yup.string().required('Required'),
    title_de: Yup.string().required('Required'),
    // type: Yup.string().required('Required'),




  });
};



export const getDataToSend = (values: any): FormData => {
  const data = { ...values };


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

export const ChangeDataToPrint = (data: any) => {

  let new_array = data
  for (let i = 0; i < data.length; i++) {
    new_array[i]['status'] = !data[i]['deleted_at'] ? 'available' : 'unavailable'
    delete new_array[i]['deleted_at']
  }
  return new_array
}