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";

interface Props {
  allProjects: ProjectWithTasks[];
  assignedProjects: AssignedProject[];
  leaveRecords: RecordLeaveInput;
}

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

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

export default TimesheetTable;
