import {
  RecordLeaveInput,
  RecordTimesheetInput,
} from "@/app/api/timesheets/actions";
import React from "react";
import { useFormContext } from "react-hook-form";
import LeaveEntryTable from "./LeaveEntryTable";
import { LeaveType } from "@/app/api/timesheets";
import DateHoursTable from "../DateHoursTable";
import { HolidaysResult } from "@/app/api/holidays";

interface Props {
  leaveTypes: LeaveType[];
  timesheetRecords: RecordTimesheetInput;
  companyHolidays: HolidaysResult[];
  isSaturdayWorker: boolean;
}

const LeaveTable: React.FC<Props> = ({
  leaveTypes,
  timesheetRecords,
  companyHolidays,
  isSaturdayWorker
}) => {
  const { watch } = useFormContext<RecordLeaveInput>();
  const currentInput = watch();
  const days = Object.keys(currentInput);

  return (
    <DateHoursTable
      companyHolidays={companyHolidays}
      days={days}
      leaveEntries={currentInput}
      timesheetEntries={timesheetRecords}
      EntryTableComponent={LeaveEntryTable}
      entryTableProps={{ leaveTypes }}
      isSaturdayWorker={isSaturdayWorker}
    />
  );
};

export default LeaveTable;
