import React, { useState } from "react"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Perusahaan } from "@/types/perusahaan"; import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, } from "@/components/ui/pagination"; import { Link } from "@inertiajs/react"; import { Edit } from "lucide-react"; interface HistoryPerusahaanTableProps { data: Perusahaan[]; itemsPerPage?: number; } export function HistoryPerusahaanTable({ data, itemsPerPage = 20, }: HistoryPerusahaanTableProps) { // Pagination state const [currentPage, setCurrentPage] = useState(1); const totalPages = Math.ceil(data.length / itemsPerPage); // Calculate displayed items based on current page const startIndex = (currentPage - 1) * itemsPerPage; const endIndex = Math.min(startIndex + itemsPerPage, data.length); const currentData = data.slice(startIndex, endIndex); // Navigation functions const nextPage = () => { if (currentPage < totalPages) { setCurrentPage(currentPage + 1); } }; const prevPage = () => { if (currentPage > 1) { setCurrentPage(currentPage - 1); } }; // Generate page numbers array for pagination const generatePaginationItems = () => { let pages = []; const maxVisiblePages = 5; if (totalPages <= maxVisiblePages) { // Show all pages if total pages is less than max visible pages for (let i = 1; i <= totalPages; i++) { pages.push(i); } } else { // Always show first page pages.push(1); // Calculate start and end of middle pages let startPage = Math.max(2, currentPage - 1); let endPage = Math.min(totalPages - 1, currentPage + 1); // Adjust to show 3 middle pages if (startPage > 2) { pages.push(null); // ellipsis } for (let i = startPage; i <= endPage; i++) { pages.push(i); } if (endPage < totalPages - 1) { pages.push(null); // ellipsis } // Always show last page pages.push(totalPages); } return pages; }; return (