import { eq, sql } from "drizzle-orm"; import { ChevronLeft, ChevronRight, ReceiptText } from "lucide-react"; import Link from "next/link"; import { cache, Suspense } from "react"; import { SidebarLink } from "@/app/(ui)/admin/client"; import { SimpleTooltip } from "@/components/tooltip"; import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarProvider, SidebarTrigger, } from "@/components/ui/sidebar"; import { db } from "@/lib/db"; import { endgameArchive } from "@/lib/db/schema"; import { parseSearchNumber } from "@/lib/utils"; import { Watcher } from "../../../../admin/client"; export default async function ({ params, children, }: { params: Promise<{ round: string }>; children: React.ReactNode; }) { const { round: r } = await params; const round = parseSearchNumber(r); return ( }> {children} ); } const getRange = cache( async () => await db .select({ min: sql`min(${endgameArchive.round})`, max: sql`max(${endgameArchive.round})`, }) .from(endgameArchive), ); const getEntries = cache( async (round: number) => await db .select() .from(endgameArchive) .where(eq(endgameArchive.round, round)) .orderBy(endgameArchive.queue), ); async function ThisSidebar({ round }: { round: number }) { const [[{ min, max }], entries] = await Promise.all([ getRange(), getEntries(round), ]); return ( เลือกรอบ {range(min, max + 1) .toReversed() .map((r) => ( รอบที่ {r} ))} ประวัติสลิปรายได้ รอบที่ {round} {round <= min ? ( ) : ( )} {round >= max ? ( ) : ( )} {entries.map((e) => ( {e.queue}. {e.name} ))} รายได้รวม {entries.reduce((a, e) => a + e.price, 0)} บาท ); } const range = (start: number, stop?: number, step?: number) => { // Handle cases where stop/step are optional (e.g., range(5) -> [0, 1, 2, 3, 4]) if (stop === undefined) { [stop, start] = [start, 0]; } if (step === undefined) { step = start < stop ? 1 : -1; } // Calculate the length of the array const length = Math.ceil((stop - start) / step); // Create the array using Array.from() and a map function return Array.from({ length }, (_, index) => start + index * step); };