'use client';

import type { ColumnDef } from '@tanstack/react-table';
import { Edit3, Trash2 } from 'lucide-react';

import { DataTable } from '@/components/data-table';
import type { Package } from '@/types';

interface PackageTableProps {
  columns: ColumnDef<Package>[];
  packages: Package[];
  isLoading: boolean;
  skip: number;
  limit: number;
  total: number;
  onPageChange: (skip: number) => void;
  onLimitChange: (limit: number) => void;
  onEdit: (pkg: Package) => void;
  onDelete: (pkg: Package) => void;
}

export function PackageTable({
  columns,
  packages,
  isLoading,
  skip,
  limit,
  total,
  onPageChange,
  onLimitChange,
  onEdit,
  onDelete,
}: PackageTableProps) {
  return (
    <DataTable
      title="Packages"
      data={packages}
      columns={columns}
      actions={[
        {
          label: 'Edit',
          icon: <Edit3 className="size-4" />,
          onClick: onEdit,
        },
        {
          label: 'Delete',
          icon: <Trash2 className="size-4" />,
          className: 'text-destructive',
          onClick: onDelete,
        },
      ]}
      isLoading={isLoading}
      emptyTitle="No packages found."
      pagination={{
        skip,
        limit,
        totalItems: total,
        onPageChange,
        onLimitChange,
      }}
    />
  );
}
