import * as Yup from "yup";
import dayjs from "dayjs";

export const getInitialValues = (objectToEdit: any): any => {
  // console.log(objectToEdit,"objectToEdit");

  return {
    id: objectToEdit?.id ?? null,
    title: objectToEdit?.title ?? null,
    content: objectToEdit?.content ?? null,
    session_id: objectToEdit?.session_id ?? null,
    teacher_id: objectToEdit?.teacher?.id ?? objectToEdit?.teacher_id ?? null,
    lesson_id: objectToEdit?.lesson?.id ?? objectToEdit?.lesson_id ?? null,
    date: objectToEdit?.date
      ? dayjs(objectToEdit?.date, "YYYY/MM/DD")
      : dayjs(Date()),
    subject_id: objectToEdit?.session?.subject?.id ?? null,
  };
};

export const getValidationSchema = () => {
  // validate input
  return Yup.object().shape({
    title: Yup.string().required("validation.required"),
    content: Yup.string().required("validation.required"),
    session_id: Yup.string().required("validation.required"),
    teacher_id: Yup.string().required("validation.required"),
    lesson_id: Yup.string().required("validation.required"),
    date: Yup.string().required("validation.required"),
    // subject_id: Yup.string().required("validation.required"),
  });
};
