import { Loader2Icon } from "lucide-react"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { Card, CardContent } from "@/components/ui/card"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Skeleton } from "@/components/ui/skeleton"
import { useMyBorrows, useReturnBook } from "./hooks"
import { formatDateTime } from "@/lib/formatters"
import { usePlatform } from "@/hooks/usePlatform"
import { useIsMobile } from "@/hooks/useIsMobile"
export default function MyBorrowsPage() {
const { data: records, isLoading, error } = useMyBorrows()
const returnBook = useReturnBook()
const platform = usePlatform()
const isMobile = useIsMobile()
const sel = platform === "web" ? ({ "data-selectable": true } as const) : ({} as const)
if (isLoading) return
if (error) {
return (
加载失败:{error instanceof Error ? error.message : "未知错误"}
)
}
const list = records ?? []
if (list.length === 0) {
return (
)
}
if (!isMobile) {
return (
我的借阅
书名
作者
借阅时间
归还时间
状态
操作
{list.map((r) => (
{r.bookBorrowVo?.name ?? "-"}
{r.bookBorrowVo?.author ?? "-"}
{formatDateTime(r.borrowTime)}
{r.returnTime ? formatDateTime(r.returnTime) : "-"}
{r.status === "BORROWED" ? "借阅中" : "已归还"}
{r.status === "BORROWED" && (
)}
))}
)
}
return (
我的借阅
{list.map((r) => (
#{r.id}
{r.status === "BORROWED" ? "借阅中" : "已归还"}
{r.bookBorrowVo?.name ?? "-"}
{r.bookBorrowVo?.author ?? "-"}
借阅:{formatDateTime(r.borrowTime)}
{r.returnTime && ` | 归还:${formatDateTime(r.returnTime)}`}
{r.status === "BORROWED" && (
)}
))}
)
}
function MyBorrowsSkeleton({ isMobile }: { isMobile: boolean }) {
if (isMobile) {
return (
{Array.from({ length: 5 }).map((_, i) => (
))}
)
}
return (
{Array.from({ length: 5 }).map((_, i) => (
))}
)
}