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

interface Props {
  allProjects: ProjectWithTasks[];
  assignedProjects: AssignedProject[];
  leaveRecords: RecordLeaveInput;
  companyHolidays: HolidaysResult[];
  fastEntryEnabled?: boolean;
}

const TimesheetTable: React.FC<Props> = ({
  allProjects,
  assignedProjects,
  leaveRecords,
  companyHolidays,
  fastEntryEnabled,
}) => {
  const { watch } = useFormContext<RecordTimesheetInput>();
  const currentInput = watch();
  const days = Object.keys(currentInput);

  return (
    <DateHoursTable
      companyHolidays={companyHolidays}
      days={days}
      leaveEntries={leaveRecords}
      timesheetEntries={currentInput}
      EntryTableComponent={EntryInputTable}
      entryTableProps={{ assignedProjects, allProjects, fastEntryEnabled }}
    />
  );
};

export default TimesheetTable;
