import { ReactNode } from "react";
import AdminDataGrid from "./AdminDataGrid";
import AdminEmptyState from "./AdminEmptyState";
import type { IconDefinition } from "@fortawesome/fontawesome-svg-core";

interface AdminCRUDListProps<T> {
  items: T[];
  renderItem: (item: T, index: number) => ReactNode;
  onEdit?: (item: T) => void;
  onDelete?: (item: T) => void;
  emptyState?: {
    title: string;
    description?: string;
    icon?: IconDefinition;
    action?: {
      label: string;
      onClick: () => void;
    };
  };
  columns?: 1 | 2 | 3 | 4 | 5;
  gap?: "sm" | "md" | "lg";
  className?: string;
}

export default function AdminCRUDList<T extends { id?: number }>({
  items,
  renderItem,
  emptyState,
  columns = 3,
  gap = "md",
  className = "",
}: AdminCRUDListProps<T>) {
  if (items.length === 0 && emptyState) {
    return <AdminEmptyState {...emptyState} />;
  }

  return (
    <AdminDataGrid columns={columns} gap={gap} className={className}>
      {items.map((item, index) => renderItem(item, index))}
    </AdminDataGrid>
  );
}

