import { Link } from "@inertiajs/react";
import { ChevronLeft, ChevronRight } from "lucide-react";
import { cn } from "@/lib/utils";
interface PaginationProps {
links: {
url: string | null;
label: string;
active: boolean;
}[];
className?: string;
}
export default function Pagination({ links, className }: PaginationProps) {
// 如果只有一頁,不顯示分頁
if (links.length <= 3) return null;
return (
{links.map((link, key) => {
// 處理特殊標籤
let label = link.label;
if (label.includes("«")) label = "Previous";
if (label.includes("»")) label = "Next";
const isPrevious = label === "Previous";
const isNext = label === "Next";
// 如果是 Previous/Next 但沒有 URL,則不渲染(或者渲染為 disabled)
if ((isPrevious || isNext) && !link.url) {
return (
{isPrevious && }
{isNext && }
{!isPrevious && !isNext && }
);
}
return link.url ? (
{isPrevious &&
}
{isNext &&
}
{!isPrevious && !isNext &&
}
) : (
);
})}
);
}