import { TableCell, TableRow } from "@/components/ui/table";
import { ReactNode } from "react";

interface EmptyListWrapperProps<T> {
  list: T[];
  emptyMessage: string;
  columns: string[];
  children: ReactNode;
  isLoading?: boolean;
}

function EmptyListWrapper<T>({
  list,
  emptyMessage,
  columns,
  children,
  isLoading = false,
}: EmptyListWrapperProps<T>) {
  if (isLoading) {
    return null;
  }

  if (!list.length) {
    return (
      <TableRow data-cy="empty-list-row">
        <TableCell
          className="text-center"
          colSpan={columns.length * 100}
          data-cy="empty-list-cell"
        >
          <h2 data-cy="empty-list-message">{emptyMessage}</h2>
        </TableCell>
      </TableRow>
    );
  }

  return <>{children}</>;
}

export default EmptyListWrapper;
