import * as Yup from "yup";
import dayjs from "dayjs";
import { StudentStatusEnum } from "../../../../../../enums/Items";

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

  function getAttachment(key: string, statusEnum: StudentStatusEnum) {
    return objectToEdit?.status === statusEnum
      ? objectToEdit?.[statusEnum]?.[key]
      : null;
  }

  const attachment =
    getAttachment("attachment", StudentStatusEnum.ABSENCE) ||
    getAttachment("attachment", StudentStatusEnum.EARLY_DEPARTURE) ||
    getAttachment("attachment", StudentStatusEnum.LATE_ARRIVAL);

  const type =
    getAttachment("type", StudentStatusEnum.ABSENCE) ||
    getAttachment("type", StudentStatusEnum.EARLY_DEPARTURE) ||
    getAttachment("type", StudentStatusEnum.LATE_ARRIVAL);

  const justification =
    getAttachment("justification", StudentStatusEnum.ABSENCE) ||
    getAttachment("justification", StudentStatusEnum.EARLY_DEPARTURE) ||
    getAttachment("justification", StudentStatusEnum.LATE_ARRIVAL);

  return {
    id: objectToEdit?.id ?? null,
    attachment: attachment,
    type: type ?? "justified",
    justification: justification,
    status: objectToEdit?.status ?? StudentStatusEnum?.PRESENCE,
    duration: objectToEdit?.[StudentStatusEnum?.LATE_ARRIVAL]?.duration
      ? dayjs(objectToEdit?.[StudentStatusEnum?.LATE_ARRIVAL]?.duration, "H:mm")
      : null,
  };
};

export const getValidationSchema = () => {
  // validate input
  return Yup.object().shape({});
};
