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

export const getInitialValues = (objectToEdit: any): any => {
  return {
    id: objectToEdit?.id ?? null,
    teacher_id: objectToEdit?.teacher?.["id"] ?? null,
    subject_id: objectToEdit?.subject?.id ?? null,
    from: objectToEdit?.from ? dayjs(objectToEdit?.from, "H:mm") : null,
    to: objectToEdit?.to ? dayjs(objectToEdit?.to, "H:mm") : null,
  };
};

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