import { and, eq, gt, lt, not, or, sql } from "drizzle-orm"; import { AlertCircle, BookAlert, CircleDollarSign, List, SendHorizonal, X, } from "lucide-react"; import type { Metadata } from "next"; import { cookies } from "next/headers"; import QRCode from "react-qr-code"; import Link from "next/link"; import { Suspense } from "react"; import banner from "#/logos/rubgram.webp"; import { Blocker } from "@/components/blocker"; import Image from "@/components/image"; import { SimpleTooltip } from "@/components/tooltip"; import { AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Kbd } from "@/components/ui/kbd"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; import { db } from "@/lib/db"; import { endgameSubmissions } from "@/lib/db/schema"; import { LiveButton } from "../artifact/live"; import { Watcher } from "./admin/client"; import { getDiscordSession, getEndgameConfig, getUserSubmissions } from "./api"; import { CancelButton, ClearCookie, Countdown, DownloadButton, PriceEstimation, ServiceSelector, SlipUpload, SubmissionListModal, SubmitAnotherButton, WelcomeScreening, } from "./client"; import { EndgameFormWrapper } from "./form"; import { RulesDialog } from "./rules"; import { ActionButton } from "@/components/action-button"; import { generateQrcode } from "../donate/api"; import { Conditional } from "@/components/conditional"; export const metadata: Metadata = { title: "รับกรรมแทนทางบ้าน", description: "รับเล่นคอนเทนต์เอนเกมเกนชินแทนคนดู", }; export default async function EndgamePage({ searchParams, }: { searchParams: Promise<{ new?: string }>; }) { const sp = await searchParams; const isNew = sp.new === ""; const cookie = await cookies(); const sid = cookie.get("rsid"); const promiseCfg = getEndgameConfig(); const session = await getDiscordSession(); const [[q], userSubs, { count, ...config }] = await Promise.all([ !isNew && sid?.value ? db .select({ // Using endgame.submissions.queue here because // ${endgameSubmissions.queue} does not work queue: sql` ${endgameSubmissions.queue} - ( select count(*) from ${endgameSubmissions} e2 where e2.checked = true and e2.queue < endgame.submissions.queue ) `, paid: endgameSubmissions.paid, price: endgameSubmissions.price, expires: endgameSubmissions.expires, }) .from(endgameSubmissions) .where( and( or( eq(endgameSubmissions.id, sid.value), and( eq(endgameSubmissions.user, session?.uid || "placeholder"), gt(endgameSubmissions.expires, new Date()), ), ), not(endgameSubmissions.deleted), ), ) : [], session ? getUserSubmissions(session.uid) : [], promiseCfg, ]); const canExpire: Promise = q ? db .select({ queue: endgameSubmissions.queue }) .from(endgameSubmissions) .where( and( not(endgameSubmissions.paid), lt(endgameSubmissions.queue, q.queue), ), ) .then((e) => e.length) : 0; const qrcode = await generateQrcode(q.price); return (
{q ? ( !q.paid ? ( "" ) : (
คิวของคุณคือหมายเลข {q.queue} เลขคิวของคุณอาจมีการเปลื่ยนแปลง
) ) : config.locked ? ( ยังไม่เปิดรับคิว ) : config.full ? (
คิวเต็มแล้ว
) : ( )}
รับกรรมแทนทางบ้าน
{q ? ( <>
{/* Promptpay QR Code */}
ยอดชำระ {q.price} บาท{" "} {q.expires && ( )} ผู้รับ: นาย พัชรพล พลพันธุ์ บัญชี: xxx-x-x8666-x เลขที่อ้างอิง: 004999056945438
) : ( <>
)}
อ่านกฏการลงคิว {q && ( แน่ใจหรอ ต้องการยกเลิกการลงคิวของคุณหรือไม่ ไม่ยกเลิก )}
{!q && } {count} / {config.limit < 0 ? "∞" : config.limit} คิว = 0 && count >= config.limit) } >
หากติดปัญหา โปรดแจ้งผ่านทาง ช่องดิสคอร์ด {sid && !q && !isNew && }
); }