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, X } from "lucide-react"; interface DetailHistoryPerusahaanTableProps { data: Perusahaan[]; itemsPerPage?: number; } export function DetailHistoryPerusahaanTable({ data, itemsPerPage = 20, }: DetailHistoryPerusahaanTableProps) { // 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 (
No. Nomor Surat Tanggal Surat Kelompok Kegiatan Keterangan Dokumen Keterangan Hapus {data.length > 0 ? ( currentData.map((perusahaan, index) => ( {startIndex + index + 1}
{perusahaan.NomorHistory || "-"}
{perusahaan.TanggalHistory || "-"} {perusahaan.HistoryKegiatan || "-"} {perusahaan.KeteranganHistory || "-"} {perusahaan.DokumenHistory || "-"}
)) ) : ( Tidak ada data )}
{/* Pagination using shadcn/ui */} {data.length > 0 && totalPages > 1 && (
{/*
Menampilkan {startIndex + 1}-{endIndex} dari{" "} {data.length} data
*/} {generatePaginationItems().map((page, i) => page === null ? ( ) : ( setCurrentPage(page)} > {page} ) )}
)}
); }