2026-06-04 10:11:00 +03:30
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { motion } from "framer-motion";
|
|
|
|
|
import { Coins, Trophy, Users } from "lucide-react";
|
|
|
|
|
import { useState } from "react";
|
|
|
|
|
import { ScreenHeader, ScreenShell } from "@/components/online/ScreenHeader";
|
|
|
|
|
import { useOnlineStore } from "@/lib/online-store";
|
2026-06-04 16:28:59 +03:30
|
|
|
import { useSessionStore } from "@/lib/session-store";
|
2026-06-04 10:11:00 +03:30
|
|
|
import { useUIStore } from "@/lib/ui-store";
|
|
|
|
|
import { useI18n } from "@/lib/i18n";
|
|
|
|
|
import { cn } from "@/lib/cn";
|
|
|
|
|
|
2026-06-04 16:28:59 +03:30
|
|
|
const ENTRIES = [100, 500, 1000];
|
2026-06-04 10:11:00 +03:30
|
|
|
|
|
|
|
|
export function OnlineLobbyScreen() {
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
|
const createRoom = useOnlineStore((s) => s.createRoom);
|
|
|
|
|
const startMatchmaking = useOnlineStore((s) => s.startMatchmaking);
|
|
|
|
|
const go = useUIStore((s) => s.go);
|
2026-06-04 16:28:59 +03:30
|
|
|
const coins = useSessionStore((s) => s.profile?.coins ?? 0);
|
|
|
|
|
const [entry, setEntry] = useState(100);
|
2026-06-04 10:11:00 +03:30
|
|
|
|
2026-06-04 16:28:59 +03:30
|
|
|
// Private rooms with friends are free.
|
2026-06-04 10:11:00 +03:30
|
|
|
const onCreate = async () => {
|
2026-06-04 16:28:59 +03:30
|
|
|
await createRoom({ targetScore: 7, stake: 0, ranked: false });
|
2026-06-04 10:11:00 +03:30
|
|
|
go("room");
|
|
|
|
|
};
|
2026-06-04 16:28:59 +03:30
|
|
|
|
|
|
|
|
// Ranked random always costs the entry (you stake it).
|
2026-06-04 10:11:00 +03:30
|
|
|
const onRandom = async () => {
|
2026-06-04 16:28:59 +03:30
|
|
|
if (coins < entry) {
|
|
|
|
|
go("buycoins");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await startMatchmaking({ ranked: true, stake: entry });
|
2026-06-04 10:11:00 +03:30
|
|
|
go("matchmaking");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ScreenShell>
|
2026-06-04 16:28:59 +03:30
|
|
|
<ScreenHeader
|
|
|
|
|
title={t("lobby.title")}
|
|
|
|
|
right={
|
|
|
|
|
<span className="glass rounded-full px-3 py-1.5 text-xs font-bold text-gold-300 flex items-center gap-1">
|
|
|
|
|
<Coins className="size-3.5 text-gold-400" />
|
|
|
|
|
{coins.toLocaleString()}
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
/>
|
2026-06-04 10:11:00 +03:30
|
|
|
|
2026-06-04 16:28:59 +03:30
|
|
|
{/* entry (only for ranked) */}
|
2026-06-04 10:11:00 +03:30
|
|
|
<div className="glass rounded-2xl p-4 mb-4">
|
|
|
|
|
<div className="flex items-center gap-1.5 text-sm text-cream/70 mb-2.5">
|
|
|
|
|
<Coins className="size-4 text-gold-400" />
|
2026-06-04 16:28:59 +03:30
|
|
|
{t("lobby.entry")}
|
2026-06-04 10:11:00 +03:30
|
|
|
</div>
|
|
|
|
|
<div className="flex gap-2">
|
2026-06-04 16:28:59 +03:30
|
|
|
{ENTRIES.map((s) => (
|
2026-06-04 10:11:00 +03:30
|
|
|
<button
|
|
|
|
|
key={s}
|
2026-06-04 16:28:59 +03:30
|
|
|
onClick={() => setEntry(s)}
|
2026-06-04 10:11:00 +03:30
|
|
|
className={cn(
|
|
|
|
|
"flex-1 rounded-xl py-2.5 text-sm font-bold transition",
|
2026-06-04 16:28:59 +03:30
|
|
|
entry === s ? "btn-gold" : "bg-navy-900/70 gold-border text-cream/70 hover:text-cream"
|
2026-06-04 10:11:00 +03:30
|
|
|
)}
|
|
|
|
|
>
|
2026-06-04 16:28:59 +03:30
|
|
|
{s.toLocaleString()}
|
2026-06-04 10:11:00 +03:30
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2026-06-04 16:28:59 +03:30
|
|
|
{coins < entry && (
|
|
|
|
|
<p className="text-rose-300 text-xs mt-2 text-center">{t("lobby.needCoins")}</p>
|
|
|
|
|
)}
|
2026-06-04 10:11:00 +03:30
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
<motion.button
|
|
|
|
|
whileHover={{ y: -2 }}
|
|
|
|
|
whileTap={{ scale: 0.98 }}
|
|
|
|
|
onClick={onRandom}
|
|
|
|
|
className="btn-gold w-full rounded-2xl p-5 flex items-center gap-4 text-start"
|
|
|
|
|
>
|
|
|
|
|
<span className="size-12 rounded-xl bg-black/15 flex items-center justify-center text-[#2a1f04]">
|
|
|
|
|
<Trophy className="size-6" />
|
|
|
|
|
</span>
|
2026-06-04 16:28:59 +03:30
|
|
|
<span className="flex-1">
|
2026-06-04 10:11:00 +03:30
|
|
|
<span className="block text-lg font-black text-[#2a1f04]">{t("lobby.random")}</span>
|
|
|
|
|
<span className="block text-xs text-[#2a1f04]/70">{t("lobby.randomDesc")}</span>
|
|
|
|
|
</span>
|
2026-06-04 16:28:59 +03:30
|
|
|
<span className="flex items-center gap-1 text-[#2a1f04] font-black">
|
|
|
|
|
{entry}
|
|
|
|
|
<Coins className="size-4" />
|
|
|
|
|
</span>
|
2026-06-04 10:11:00 +03:30
|
|
|
</motion.button>
|
|
|
|
|
|
|
|
|
|
<motion.button
|
|
|
|
|
whileHover={{ y: -2 }}
|
|
|
|
|
whileTap={{ scale: 0.98 }}
|
|
|
|
|
onClick={onCreate}
|
|
|
|
|
className="glass w-full rounded-2xl p-5 flex items-center gap-4 text-start hover:bg-navy-800/80 transition"
|
|
|
|
|
>
|
|
|
|
|
<span className="size-12 rounded-xl bg-navy-900 gold-border flex items-center justify-center text-gold-400">
|
|
|
|
|
<Users className="size-6" />
|
|
|
|
|
</span>
|
2026-06-04 16:28:59 +03:30
|
|
|
<span className="flex-1">
|
2026-06-04 10:11:00 +03:30
|
|
|
<span className="block text-lg font-black text-cream">{t("lobby.createRoom")}</span>
|
|
|
|
|
<span className="block text-xs text-cream/55">{t("lobby.createDesc")}</span>
|
|
|
|
|
</span>
|
2026-06-04 16:28:59 +03:30
|
|
|
<span className="text-teal-300 font-bold text-sm">{t("lobby.free")}</span>
|
2026-06-04 10:11:00 +03:30
|
|
|
</motion.button>
|
|
|
|
|
</div>
|
|
|
|
|
</ScreenShell>
|
|
|
|
|
);
|
|
|
|
|
}
|