"use client"; import { ArrowRight, Check, Download, LogIn, ScrollText } from "lucide-react"; import { useRouter } from "next/navigation"; import posthog from "posthog-js"; import { type ReactNode, useEffect, useRef, useState } from "react"; import { toast } from "sonner"; import { Blocker } from "@/components/blocker"; import { Button } from "@/components/ui/button"; import { Kbd } from "@/components/ui/kbd"; import { Label } from "@/components/ui/label"; import { MultiSelect, MultiSelectContent, MultiSelectGroup, MultiSelectItem, MultiSelectTrigger, MultiSelectValue, } from "@/components/ui/multi-select"; import { Spinner } from "@/components/ui/spinner"; import { shared } from "@/lib/comms"; import { cn } from "@/lib/utils"; import { calcPrice, cancel, type getDiscordSession, type getEndgameConfig, loginDiscord, } from "./api"; import { RulesDialog } from "./rules"; export function WelcomeScreening({ session, }: { session: Awaited>; }) { const [agreed, setAgreed] = useState(false); const [updated] = shared.state("updated"); if (agreed || (updated && session)) return; return ( {session ? (
!set && setAgreed(true)}> กำลังล็อกอินในฐานะ {session.display}{" "}
) : (
โปรดล็อคอินผ่าน Discord เพื่อดำเนินการต่อ
)}
); } export function ServiceSelector({ types, allDiscount, free, }: Awaited>) { const [selected, setSelected] = shared.state("rubgram.services"); return (
setSelected(l as unknown as Parameters[0]) } > {types.map((t) => ( {t.display}{" "} {free > 0 ? ( <> {t.price}{" "} ฟรี ) : ( <> {t.price} บาท )} ))} เลือกทั้ง {types.length} อย่าง ลดให้ {allDiscount} บาท
); } export function PriceEstimation() { const [selected] = shared.state("rubgram.services"); const [label, setLabel] = useState("ทั้งหมด 0 บาท"); useEffect(() => { if (selected) calcPrice(selected).then((p) => setLabel(`ทั้งหมด ${p} บาท`)); }); return {label}; } export function SlipUpload() { const ref = useRef(null); const [isSelected, setIsSelected] = useState(false); return ( <> setIsSelected(!!ref.current?.files?.length)} /> ); } export function DownloadButton() { return ( ); } export function Countdown({ time, render = String, refreshWhenOver = false, }: { time: Date; render?: (time: string | null) => ReactNode; refreshWhenOver?: boolean; }) { const [now, setNow] = useState(new Date()); const router = useRouter(); useEffect(() => { if (!refreshWhenOver) return; const wait = time.getTime() - Date.now(); if (wait < 0) return; const timeout = setTimeout(() => router.refresh(), wait); return () => clearTimeout(timeout); }, [time, router, refreshWhenOver]); useEffect(() => { const interval = setInterval(() => setNow(new Date()), 1000); return () => clearInterval(interval); }, []); const diff = Math.max(0, time.getTime() - now.getTime()); const minutes = Math.floor(diff / 60000); const seconds = Math.floor((diff % 60000) / 1000); return render( diff <= 0 ? null : `${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`, ); } export function CancelButton({ sid }: { sid: string }) { const [loading, setLoading] = useState(false); const [, setServices] = shared.state("rubgram.services"); return ( ); } export function ClearCookie() { try { // biome-ignore lint/suspicious/noTsIgnore: typescript issue // @ts-ignore cookieStore.delete("rsid"); } catch { console.warn("Cannot clear rubgram cookie"); } return ""; }