2026-06-04 10:11:00 +03:30
|
|
|
"use client";
|
|
|
|
|
|
2026-06-04 15:52:06 +03:30
|
|
|
import { Bell, Coins, Crown, Gift } from "lucide-react";
|
2026-06-04 10:11:00 +03:30
|
|
|
import { useSessionStore } from "@/lib/session-store";
|
|
|
|
|
import { useUIStore } from "@/lib/ui-store";
|
2026-06-04 15:52:06 +03:30
|
|
|
import { useNotifStore } from "@/lib/notification-store";
|
2026-06-04 10:11:00 +03:30
|
|
|
import { useI18n } from "@/lib/i18n";
|
2026-06-06 18:39:24 +03:30
|
|
|
import { MAX_LEVEL, xpNeededForLevel } from "@/lib/online/gamification";
|
2026-06-04 10:49:54 +03:30
|
|
|
import { Avatar } from "./Avatar";
|
2026-06-04 10:11:00 +03:30
|
|
|
|
|
|
|
|
export function TopBar() {
|
|
|
|
|
const profile = useSessionStore((s) => s.profile);
|
|
|
|
|
const go = useUIStore((s) => s.go);
|
|
|
|
|
const openDaily = useUIStore((s) => s.openDaily);
|
2026-06-04 15:52:06 +03:30
|
|
|
const unread = useNotifStore((s) => s.unread);
|
2026-06-04 10:11:00 +03:30
|
|
|
const { t } = useI18n();
|
|
|
|
|
if (!profile) return null;
|
|
|
|
|
|
2026-06-06 18:39:24 +03:30
|
|
|
const maxed = profile.level >= MAX_LEVEL;
|
|
|
|
|
const xpNeed = xpNeededForLevel(profile.level);
|
|
|
|
|
const xpPct = maxed ? 100 : Math.min(100, Math.max(0, Math.round((profile.xp / xpNeed) * 100)));
|
|
|
|
|
|
2026-06-04 10:11:00 +03:30
|
|
|
return (
|
|
|
|
|
<div className="flex items-center justify-between gap-3">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => go("profile")}
|
|
|
|
|
className="glass rounded-full ltr:pr-4 rtl:pl-4 ltr:pl-1.5 rtl:pr-1.5 py-1.5 flex items-center gap-2 hover:bg-navy-800/80 transition"
|
|
|
|
|
>
|
2026-06-04 10:49:54 +03:30
|
|
|
<span className="relative size-9 rounded-full bg-navy-900 gold-border flex items-center justify-center overflow-hidden">
|
|
|
|
|
<Avatar id={profile.avatar} image={profile.avatarImage} size={profile.avatarImage ? 36 : 26} />
|
2026-06-04 10:11:00 +03:30
|
|
|
</span>
|
2026-06-06 18:39:24 +03:30
|
|
|
<span className="text-start leading-tight min-w-[96px]">
|
2026-06-04 10:49:54 +03:30
|
|
|
<span className="flex items-center gap-1 text-sm font-bold text-cream max-w-28 truncate">
|
2026-06-04 10:11:00 +03:30
|
|
|
{profile.displayName}
|
2026-06-04 10:49:54 +03:30
|
|
|
{profile.plan === "pro" && <Crown className="size-3 text-gold-400 fill-gold-500 shrink-0" />}
|
2026-06-04 10:11:00 +03:30
|
|
|
</span>
|
2026-06-06 18:39:24 +03:30
|
|
|
<span className="flex items-center justify-between text-[10px] text-gold-400/80 mt-0.5">
|
|
|
|
|
<span>{t("common.level")} {profile.level}</span>
|
|
|
|
|
<span className="text-cream/40 tabular-nums">{maxed ? "MAX" : `${xpPct}%`}</span>
|
|
|
|
|
</span>
|
|
|
|
|
<span className="mt-0.5 block h-1 w-full rounded-full bg-navy-900 overflow-hidden">
|
|
|
|
|
<span
|
|
|
|
|
className="block h-full rounded-full bg-gradient-to-r from-gold-500 to-gold-300"
|
|
|
|
|
style={{ width: `${xpPct}%` }}
|
|
|
|
|
/>
|
2026-06-04 10:11:00 +03:30
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
2026-06-04 15:52:06 +03:30
|
|
|
<button
|
|
|
|
|
onClick={() => go("notifications")}
|
|
|
|
|
className="glass rounded-full p-2 hover:bg-navy-800/80 transition relative"
|
|
|
|
|
title={t("notif.title")}
|
|
|
|
|
>
|
|
|
|
|
<Bell className="size-4 text-gold-400" />
|
|
|
|
|
{unread > 0 && (
|
|
|
|
|
<span className="absolute -top-0.5 ltr:-right-0.5 rtl:-left-0.5 min-w-4 h-4 px-1 rounded-full bg-rose-500 text-[9px] font-bold text-white flex items-center justify-center">
|
|
|
|
|
{unread > 9 ? "9+" : unread}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
2026-06-04 10:11:00 +03:30
|
|
|
<button
|
|
|
|
|
onClick={openDaily}
|
|
|
|
|
className="glass rounded-full p-2 hover:bg-navy-800/80 transition"
|
|
|
|
|
title={t("daily.title")}
|
|
|
|
|
>
|
|
|
|
|
<Gift className="size-4 text-gold-400" />
|
|
|
|
|
</button>
|
2026-06-04 16:28:59 +03:30
|
|
|
<button
|
|
|
|
|
onClick={() => go("buycoins")}
|
|
|
|
|
className="glass rounded-full px-3 py-1.5 flex items-center gap-1.5 hover:bg-navy-800/80 transition"
|
|
|
|
|
title={t("buy.title")}
|
|
|
|
|
>
|
2026-06-04 10:11:00 +03:30
|
|
|
<Coins className="size-4 text-gold-400" />
|
|
|
|
|
<span className="text-sm font-bold text-cream tabular-nums">
|
|
|
|
|
{profile.coins.toLocaleString()}
|
|
|
|
|
</span>
|
2026-06-04 16:28:59 +03:30
|
|
|
<span className="text-gold-400 text-sm leading-none font-bold">+</span>
|
|
|
|
|
</button>
|
2026-06-04 10:11:00 +03:30
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|