import React from 'react';

import { TableColumn } from '@/shared/types/common';
import TableManager from '@/shared/components/table/table-manager';

import { Box } from '@mui/material';
import { IDemandeAbsence } from '@/shared/types/leave';
import AbsenceTableRow from '../view/absence-table-row';


interface AbsenceTableProps {
  filteredData: IDemandeAbsence[];
  table: ReturnType<typeof import('@/shared/components/table/use-tablets').default>;
  tableHead: TableColumn[];
  notFound: boolean;
  filters: Record<string, { value: string; condition: string }>;
  onFilterChange: (key: string, value: string, condition: string) => void;
  handleEdit: (item: IDemandeAbsence) => void;
  handleView: (item: IDemandeAbsence) => void;
  onPageChange?: (event: React.MouseEvent<HTMLButtonElement> | null, page: number) => void;
  page?: number;
  onRowsPerPageChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
  rowsPerPage?: number;
  count?: number;
}

export default function AbsenceTable({
  filteredData,
  table,
  tableHead,
  notFound,
  filters,
  onFilterChange,
  handleEdit,
  handleView,
  onPageChange,
  page,
  onRowsPerPageChange,
  rowsPerPage,
  count,
}: AbsenceTableProps) {
  const renderRow = (row: IDemandeAbsence) => (
    <AbsenceTableRow
      dense={table.dense}
      key={row.id}
      row={row}
      handleEdit={handleEdit}
      handleDetails={handleView}
      selected={table.selected.includes(row.id)}
      onSelectRow={() => table.onSelectRow(row.id)}
      columns={tableHead.slice(0, -1)}
    />
  );

  return (
    <TableManager
      filteredData={filteredData}
      table={table}
      tableHead={tableHead}
      notFound={notFound}
      filters={filters}
      onFilterChange={onFilterChange}
      renderRow={renderRow}
      fixedHeight="550px"
      onPageChange={onPageChange}
      page={page}
      onRowsPerPageChange={onRowsPerPageChange}
      rowsPerPage={rowsPerPage}
      count={count}
    />
  );
}