import { count, desc, eq } from "drizzle-orm"; import { headers } from "next/headers"; import Image from "next/image"; import Link from "next/link"; import { redirect } from "next/navigation"; import { getTranslations } from "next-intl/server"; import { AmbientOrbs } from "@/components/ambient-orbs"; import { AnimatedCounter } from "@/components/animated-counter"; import { HomeLoginForm } from "@/components/auth/home-login-form"; import { Clock } from "@/components/clock"; import { LanguageSwitcher } from "@/components/language-switcher"; import { Reveal } from "@/components/motion-reveal"; import { ThemeSwitcher } from "@/components/theme-switcher"; import { TypewriterText } from "@/components/typewriter-text"; import { auth } from "@/lib/auth"; import { cached } from "@/lib/cache"; import { CameraWeb, db, Rooms, User, WebsiteArticles } from "@/lib/db"; import { avatarImageUrl } from "@/lib/format"; import { formatDate } from "@/lib/format-date"; import { resolveHotelName } from "@/lib/hotel-name"; import { captchaConfig } from "@/lib/services/captcha"; import { siteSettings } from "@/lib/services/site-settings"; export const revalidate = 120; async function getHotelData() { const [hotelName, imagerRaw, logo] = await Promise.all([ resolveHotelName(), siteSettings.get( "habbo_imaging_url", "https://www.habbo.com/habbo-imaging/avatarimage", ), siteSettings.get("cms_logo", ""), ]); const imager = imagerRaw ?? "https://www.habbo.com/habbo-imaging/avatarimage"; const [ online, users, rooms, articles, recentUsers, recentPhotos, latestUsers, ] = await Promise.all([ cached("online_count", 10_000, () => db .select({ total: count() }) .from(User) .where(eq(User.online, "1")) .then((rows) => rows[0]?.total ?? 0), ).catch(() => 0), cached("total_users", 30_000, () => db .select({ total: count() }) .from(User) .then((rows) => rows[0]?.total ?? 0), ).catch(() => 0), cached("total_rooms", 30_000, () => db .select({ total: count() }) .from(Rooms) .then((rows) => rows[0]?.total ?? 0), ).catch(() => 0), db .select() .from(WebsiteArticles) .orderBy(desc(WebsiteArticles.createdAt)) .limit(5) .catch(() => []), db .select({ username: User.username, look: User.look }) .from(User) .where(eq(User.online, "1")) .limit(30) .catch(() => []), db .select() .from(CameraWeb) .orderBy(desc(CameraWeb.timestamp)) .limit(4) .catch(() => []), db .select({ username: User.username, look: User.look }) .from(User) .orderBy(desc(User.accountCreated)) .limit(8) .catch(() => []), ]); return { hotelName, imager, online, users, rooms, articles, recentUsers, recentPhotos, latestUsers, logo, }; } export default async function Home() { const session = await auth(); if (session?.user?.id) redirect("/me"); const tp = await getTranslations("pages.home"); const th = await getTranslations("header"); const { hotelName, imager, online, users, rooms, articles, recentUsers, recentPhotos, latestUsers, logo, } = await getHotelData(); const captcha = await captchaConfig(); const nonce = (await headers()).get("x-nonce") ?? undefined; return (
{/* ── Top Bar ── */}
{logo ? ( {hotelName} ) : ( {hotelName} )} {hotelName}
{/* ── Hero ── */}
{th("online", { count: online, hotel: hotelName })}

{th("tagline")}

{tp("register")} {th("login")}
Frank
{/* ── Stats ── */}
{[ { value: online, label: tp("statsOnline"), icon: "/assets/images/icons/online-friends.png", }, { value: users, label: tp("statsCitizens"), icon: "/assets/images/icons/friends.png", }, { value: rooms, label: tp("statsRooms"), icon: "/assets/images/icons/catalog.png", }, ].map((s) => (
{s.label}
))}
{/* ── Login + News ── */}
{/* Left: Login & Register */}

Login

Register
{tp("register")} {latestUsers.length > 0 && (

{tp("latestUsers", { count: users.toLocaleString() })}

{latestUsers.map((u) => (
{u.username}
{u.username}
))}
)}
{/* Right: News */}

{tp("latestNews")}

{tp("allNews")}
{articles.length > 0 ? (
{articles.slice(0, 4).map((a) => (
{a.title}
→

{a.title}

{formatDate(a.createdAt, "date", "")}

))}
) : (

{tp("noArticles")}

)}
{/* ── Online users ── */} {recentUsers.length > 0 && (

{tp("recentUsers")}

{tp("allUsers")}
{recentUsers.slice(0, 12).map((u) => (
{u.username} {u.username}
))}
)} {/* ── Bottom CTA ── */}

{tp("joinNow", { hotelName })}

{tp("welcomeBody")}

{tp("register")}
{/* ── Recent photos ── */} {recentPhotos.length > 0 && (

{tp("recentPhotos")}

{recentPhotos.slice(0, 4).map((p) => ( ))}
)}
); }