import * as Yup from "yup";

import dayjs from "dayjs";
import { StudentStatusEnum } from "../../../../enums/Items";

export const getInitialValues = (objectToEdit: any): any => {
  function getAttachment(key: string, statusEnum: StudentStatusEnum) {
    return objectToEdit?.status === statusEnum
      ? objectToEdit?.[statusEnum]?.[0]?.[key]
      : null;
  }

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

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

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

  const Date_Formate = dayjs(
    dayjs(objectToEdit?.date).format("YYYY/MM/DD"),
    "YYYY/MM/DD",
  )?.format("YYYY/MM/DD");

  console.log(objectToEdit);

  return {
    // id: objectToEdit?.id ?? null,
    attachment: attachment,
    type: type ?? "not_justified",
    justification: justification,
    status: objectToEdit?.status,
    duration: objectToEdit?.[StudentStatusEnum?.LATE_ARRIVAL]?.[0]?.duration
      ? dayjs(
          objectToEdit?.[StudentStatusEnum?.LATE_ARRIVAL]?.[0]?.duration,
          "H:mm",
        )
      : null,
    departure_time: objectToEdit?.[StudentStatusEnum?.EARLY_DEPARTURE]?.[0]
      ?.departure_time
      ? dayjs(
          objectToEdit?.[StudentStatusEnum?.EARLY_DEPARTURE]?.[0]
            ?.departure_time,
          "H:mm",
        )
      : null,
    date: Date_Formate,
  };
};

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