"use client"; import Image from "next/image"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { PlusIcon, RefreshCwIcon, RotateCcwIcon, Trash2Icon, } from "lucide-react"; import { useTransition } from "react"; import { toast } from "sonner"; import { deleteStructuredGuide, moveGuideToTrash, restoreStructuredGuide, startCatalogSync, } from "@/app/admin/actions"; import { DeleteConfirmationDialog } from "@/components/admin/delete-confirmation-dialog"; import { GuideVisibilityControl } from "@/components/admin/guide-visibility-control"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyTitle, } from "@/components/ui/empty"; import { Spinner } from "@/components/ui/spinner"; type GuideCard = { id: string; characterKey: string; name: string; overview: string; coverUrl: string; version: number; updatedAt: Date; trashedAt: Date | null; isPublic: boolean; }; export function StructuredDashboard({ guides, trash, catalogVersion, latestCatalogVersion, }: { guides: GuideCard[]; trash: GuideCard[]; catalogVersion: string | null; latestCatalogVersion: string | null; }) { const router = useRouter(); const [pending, startTransition] = useTransition(); const catalogReady = Boolean(catalogVersion); const updateAvailable = Boolean( catalogVersion && latestCatalogVersion && catalogVersion !== latestCatalogVersion, ); function run( action: () => Promise<{ status: string; message?: string }>, success: string, ) { startTransition(async () => { const result = await action(); if (result.status === "error") toast.error(result.message); else { toast.success(success); router.refresh(); } }); } return (
Lunaris ที่ Sync:{" "} {catalogVersion ? `v${catalogVersion}` : "ยังไม่ Sync"} {latestCatalogVersion ? updateAvailable ? `มีอัปเดต: v${latestCatalogVersion}` : `ล่าสุด: v${latestCatalogVersion}` : "ตรวจสอบเวอร์ชันล่าสุดไม่ได้"}
{guides.length ? (
{guides.map((guide) => ( แก้ไข Guide {guide.name}
{`Guide
{guide.name} {guide.overview} v{guide.version}

แก้ไขล่าสุด{" "} {new Date(guide.updatedAt).toLocaleString("th-TH")}

} title={`ย้าย ${guide.name} ไปถังขยะ?`} description="Guide จะหายจากหน้าเว็บไซต์ทันที และสามารถกู้คืนได้ภายหลัง" confirmLabel="ย้ายไปถังขยะ" onConfirm={() => run(() => moveGuideToTrash(guide.id), "ลบสำเร็จ!") } > ย้าย {guide.name} ไปถังขยะ
))}
) : ( ยังไม่มี Guide Sync Catalog แล้วเลือกตัวละครเพื่อสร้าง Guide แรก )} {trash.length ? (

ถังขยะ

Guide ที่ซ่อนไว้จากเว็บไซต์

{trash.map((guide) => ( {guide.name} {guide.overview}
} title={`ลบ ${guide.name} ถาวร?`} description="ข้อมูล Weapons, Artifacts, Constellations, Team และ Extra ทั้งหมดจะกู้คืนไม่ได้" confirmLabel="ยืนยันลบถาวร" onConfirm={() => run( () => deleteStructuredGuide(guide.id), "ลบสำเร็จ!", ) } > ลบถาวร
))}
) : null}
); }