2026-06-04 10:11:00 +03:30
|
|
|
"use client";
|
|
|
|
|
|
2026-06-04 11:49:19 +03:30
|
|
|
import { Check, Coins, Crown, Music, Pencil, Upload, Volume2 } from "lucide-react";
|
2026-06-04 10:49:54 +03:30
|
|
|
import { useRef, useState } from "react";
|
2026-06-04 10:11:00 +03:30
|
|
|
import { ScreenHeader, ScreenShell } from "@/components/online/ScreenHeader";
|
|
|
|
|
import { RankBadge } from "@/components/online/RankBadge";
|
|
|
|
|
import { XpBar } from "@/components/online/XpBar";
|
2026-06-04 10:49:54 +03:30
|
|
|
import { Avatar } from "@/components/online/Avatar";
|
2026-06-04 10:11:00 +03:30
|
|
|
import { useSessionStore } from "@/lib/session-store";
|
2026-06-04 11:49:19 +03:30
|
|
|
import { useSoundStore } from "@/lib/sound-store";
|
2026-06-04 10:11:00 +03:30
|
|
|
import { useI18n } from "@/lib/i18n";
|
2026-06-04 10:49:54 +03:30
|
|
|
import {
|
|
|
|
|
ACHIEVEMENTS,
|
2026-06-04 11:49:19 +03:30
|
|
|
CARD_BACKS,
|
|
|
|
|
CARD_FRONTS,
|
2026-06-04 10:49:54 +03:30
|
|
|
TITLES,
|
|
|
|
|
achievementProgress,
|
2026-06-04 11:49:19 +03:30
|
|
|
ownedCardBackIds,
|
|
|
|
|
ownedCardFrontIds,
|
2026-06-04 10:49:54 +03:30
|
|
|
} from "@/lib/online/gamification";
|
|
|
|
|
import { AVATARS } from "@/lib/online/types";
|
2026-06-04 10:11:00 +03:30
|
|
|
import { cn } from "@/lib/cn";
|
|
|
|
|
|
|
|
|
|
export function ProfileScreen() {
|
|
|
|
|
const { t, locale } = useI18n();
|
|
|
|
|
const profile = useSessionStore((s) => s.profile);
|
|
|
|
|
const updateProfile = useSessionStore((s) => s.updateProfile);
|
2026-06-04 10:49:54 +03:30
|
|
|
const upgradePlan = useSessionStore((s) => s.upgradePlan);
|
|
|
|
|
const fileRef = useRef<HTMLInputElement>(null);
|
2026-06-04 10:11:00 +03:30
|
|
|
const [editing, setEditing] = useState(false);
|
|
|
|
|
const [name, setName] = useState(profile?.displayName ?? "");
|
|
|
|
|
|
|
|
|
|
if (!profile) return null;
|
|
|
|
|
const s = profile.stats;
|
|
|
|
|
const winrate = s.games > 0 ? Math.round((s.wins / s.games) * 100) : 0;
|
2026-06-04 10:49:54 +03:30
|
|
|
const titleDef = TITLES.find((x) => x.id === profile.title);
|
|
|
|
|
const titleName = titleDef ? (locale === "fa" ? titleDef.nameFa : titleDef.nameEn) : null;
|
2026-06-04 11:49:19 +03:30
|
|
|
const ownedFronts = new Set(ownedCardFrontIds(profile));
|
|
|
|
|
const ownedBacks = new Set(ownedCardBackIds(profile));
|
2026-06-04 10:11:00 +03:30
|
|
|
|
|
|
|
|
const saveName = async () => {
|
|
|
|
|
if (name.trim()) await updateProfile({ displayName: name.trim() });
|
|
|
|
|
setEditing(false);
|
|
|
|
|
};
|
|
|
|
|
|
2026-06-04 10:49:54 +03:30
|
|
|
const onUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
const file = e.target.files?.[0];
|
|
|
|
|
if (!file) return;
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
reader.onload = () => updateProfile({ avatarImage: String(reader.result) });
|
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
|
};
|
|
|
|
|
|
2026-06-04 10:11:00 +03:30
|
|
|
return (
|
|
|
|
|
<ScreenShell>
|
|
|
|
|
<ScreenHeader title={t("profile.title")} />
|
|
|
|
|
|
|
|
|
|
{/* identity */}
|
|
|
|
|
<div className="glass rounded-3xl p-5 text-center">
|
2026-06-04 10:49:54 +03:30
|
|
|
<div className="relative size-20 mx-auto">
|
|
|
|
|
<div className="size-20 rounded-2xl bg-navy-900 gold-border flex items-center justify-center overflow-hidden">
|
|
|
|
|
<Avatar id={profile.avatar} image={profile.avatarImage} size={profile.avatarImage ? 80 : 56} />
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => fileRef.current?.click()}
|
|
|
|
|
className="absolute -bottom-1 ltr:-right-1 rtl:-left-1 btn-gold rounded-full p-1.5"
|
|
|
|
|
title={t("profile.upload")}
|
|
|
|
|
>
|
|
|
|
|
<Upload className="size-3.5" />
|
|
|
|
|
</button>
|
|
|
|
|
<input ref={fileRef} type="file" accept="image/*" className="hidden" onChange={onUpload} />
|
2026-06-04 10:11:00 +03:30
|
|
|
</div>
|
|
|
|
|
|
2026-06-04 10:49:54 +03:30
|
|
|
{titleName && (
|
|
|
|
|
<div className="mt-2 text-xs font-bold text-gold-300">{titleName}</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-06-04 10:11:00 +03:30
|
|
|
{editing ? (
|
|
|
|
|
<div className="mt-3 flex items-center justify-center gap-2">
|
|
|
|
|
<input
|
|
|
|
|
value={name}
|
|
|
|
|
onChange={(e) => setName(e.target.value)}
|
|
|
|
|
className="rounded-lg bg-navy-900/70 gold-border px-3 py-1.5 text-center text-cream outline-none focus:ring-2 focus:ring-gold-500/40"
|
|
|
|
|
/>
|
|
|
|
|
<button onClick={saveName} className="btn-gold rounded-lg p-2">
|
|
|
|
|
<Check className="size-4" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setName(profile.displayName);
|
|
|
|
|
setEditing(true);
|
|
|
|
|
}}
|
|
|
|
|
className="mt-3 inline-flex items-center gap-2 text-xl font-black text-cream hover:text-gold-300 transition"
|
|
|
|
|
>
|
|
|
|
|
{profile.displayName}
|
|
|
|
|
<Pencil className="size-3.5 text-cream/40" />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<div className="mt-2 flex items-center justify-center gap-2">
|
|
|
|
|
<RankBadge rating={profile.rating} showRating />
|
|
|
|
|
<span className="glass rounded-full px-2.5 py-1 text-xs font-bold text-gold-300 flex items-center gap-1">
|
|
|
|
|
<Coins className="size-3.5 text-gold-400" />
|
|
|
|
|
{profile.coins.toLocaleString()}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="mt-4">
|
|
|
|
|
<XpBar level={profile.level} xp={profile.xp} />
|
|
|
|
|
</div>
|
2026-06-04 10:49:54 +03:30
|
|
|
|
|
|
|
|
<div className="mt-4">
|
|
|
|
|
{profile.plan === "pro" ? (
|
|
|
|
|
<span className="inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-bold text-gold-300 bg-gold-500/15 gold-border">
|
|
|
|
|
<Crown className="size-3.5 fill-gold-500" />
|
|
|
|
|
{t("plan.active")}
|
|
|
|
|
</span>
|
|
|
|
|
) : (
|
|
|
|
|
<button
|
|
|
|
|
onClick={upgradePlan}
|
|
|
|
|
className="btn-gold inline-flex items-center gap-1.5 rounded-full px-4 py-2 text-xs"
|
|
|
|
|
>
|
|
|
|
|
<Crown className="size-3.5" />
|
|
|
|
|
{t("plan.upgrade")} — {t("plan.proDesc")}
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-06-04 10:11:00 +03:30
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* avatar picker */}
|
|
|
|
|
<div className="glass rounded-2xl p-4 mt-4">
|
|
|
|
|
<h3 className="text-sm font-bold text-cream/80 mb-3">{t("profile.chooseAvatar")}</h3>
|
|
|
|
|
<div className="flex flex-wrap gap-2">
|
|
|
|
|
{AVATARS.filter((a) => profile.ownedAvatars.includes(a.id)).map((a) => (
|
|
|
|
|
<button
|
|
|
|
|
key={a.id}
|
|
|
|
|
onClick={() => updateProfile({ avatar: a.id })}
|
|
|
|
|
className={cn(
|
|
|
|
|
"size-12 rounded-xl bg-navy-900/70 flex items-center justify-center text-2xl transition",
|
|
|
|
|
profile.avatar === a.id ? "gold-border ring-2 ring-gold-400/60" : "border border-transparent hover:bg-navy-800"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{a.emoji}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-06-04 10:49:54 +03:30
|
|
|
{/* title picker */}
|
|
|
|
|
<div className="glass rounded-2xl p-4 mt-4">
|
|
|
|
|
<h3 className="text-sm font-bold text-cream/80 mb-3">{t("profile.titleLabel")}</h3>
|
|
|
|
|
<div className="flex flex-wrap gap-2">
|
|
|
|
|
{TITLES.filter((tt) => profile.ownedTitles.includes(tt.id)).map((tt) => (
|
|
|
|
|
<button
|
|
|
|
|
key={tt.id}
|
|
|
|
|
onClick={() => updateProfile({ title: tt.id })}
|
|
|
|
|
className={cn(
|
|
|
|
|
"rounded-lg px-3 py-1.5 text-sm transition",
|
|
|
|
|
profile.title === tt.id
|
|
|
|
|
? "btn-gold"
|
|
|
|
|
: "bg-navy-900/70 gold-border text-cream/70 hover:text-cream"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{locale === "fa" ? tt.nameFa : tt.nameEn}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-06-04 11:49:19 +03:30
|
|
|
{/* card front picker */}
|
2026-06-04 10:49:54 +03:30
|
|
|
<div className="glass rounded-2xl p-4 mt-4">
|
2026-06-04 11:49:19 +03:30
|
|
|
<h3 className="text-sm font-bold text-cream/80 mb-3">{t("profile.cardFront")}</h3>
|
2026-06-04 10:49:54 +03:30
|
|
|
<div className="flex flex-wrap gap-2">
|
2026-06-04 11:49:19 +03:30
|
|
|
{CARD_FRONTS.filter((c) => ownedFronts.has(c.id)).map((c) => (
|
2026-06-04 10:49:54 +03:30
|
|
|
<button
|
|
|
|
|
key={c.id}
|
2026-06-04 11:49:19 +03:30
|
|
|
onClick={() => updateProfile({ cardFront: c.id })}
|
2026-06-04 10:49:54 +03:30
|
|
|
className={cn(
|
|
|
|
|
"rounded-xl p-1.5 flex items-center gap-2 transition",
|
2026-06-04 11:49:19 +03:30
|
|
|
profile.cardFront === c.id
|
|
|
|
|
? "gold-border ring-2 ring-gold-400/60 bg-navy-900/70"
|
|
|
|
|
: "bg-navy-900/70 border border-transparent hover:bg-navy-800"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<span
|
|
|
|
|
className="w-7 h-10 rounded-md border flex items-center justify-center text-xs text-slate-900"
|
|
|
|
|
style={{ background: `linear-gradient(160deg, ${c.bg1}, ${c.bg2})`, borderColor: c.border }}
|
|
|
|
|
>
|
|
|
|
|
♠
|
|
|
|
|
</span>
|
|
|
|
|
<span className="text-xs text-cream/80 pe-1">{locale === "fa" ? c.nameFa : c.nameEn}</span>
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* card back picker */}
|
|
|
|
|
<div className="glass rounded-2xl p-4 mt-4">
|
|
|
|
|
<h3 className="text-sm font-bold text-cream/80 mb-3">{t("profile.cardBack")}</h3>
|
|
|
|
|
<div className="flex flex-wrap gap-2">
|
|
|
|
|
{CARD_BACKS.filter((c) => ownedBacks.has(c.id)).map((c) => (
|
|
|
|
|
<button
|
|
|
|
|
key={c.id}
|
|
|
|
|
onClick={() => updateProfile({ cardBack: c.id })}
|
|
|
|
|
className={cn(
|
|
|
|
|
"rounded-xl p-1.5 flex items-center gap-2 transition",
|
|
|
|
|
profile.cardBack === c.id
|
2026-06-04 10:49:54 +03:30
|
|
|
? "gold-border ring-2 ring-gold-400/60 bg-navy-900/70"
|
|
|
|
|
: "bg-navy-900/70 border border-transparent hover:bg-navy-800"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<span
|
|
|
|
|
className="w-7 h-10 rounded-md border"
|
|
|
|
|
style={{
|
|
|
|
|
borderColor: `${c.accent}80`,
|
|
|
|
|
background: `repeating-linear-gradient(45deg, ${c.accent}55 0 4px, transparent 4px 8px), ${c.c2}`,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2026-06-04 11:49:19 +03:30
|
|
|
<span className="text-xs text-cream/80 pe-1">{locale === "fa" ? c.nameFa : c.nameEn}</span>
|
2026-06-04 10:49:54 +03:30
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-06-04 11:49:19 +03:30
|
|
|
{/* audio settings */}
|
|
|
|
|
<SoundSettings />
|
|
|
|
|
|
2026-06-04 10:11:00 +03:30
|
|
|
{/* stats */}
|
|
|
|
|
<div className="glass rounded-2xl p-4 mt-4">
|
|
|
|
|
<h3 className="text-sm font-bold text-cream/80 mb-3">{t("profile.stats")}</h3>
|
|
|
|
|
<div className="grid grid-cols-3 gap-2.5">
|
|
|
|
|
<Stat label={t("profile.games")} value={s.games} />
|
|
|
|
|
<Stat label={t("profile.wins")} value={s.wins} />
|
|
|
|
|
<Stat label={t("profile.winrate")} value={`${winrate}%`} />
|
|
|
|
|
<Stat label={t("profile.kots")} value={s.kotsFor} />
|
|
|
|
|
<Stat label={t("profile.streak")} value={s.bestWinStreak} />
|
|
|
|
|
<Stat label={t("common.rating")} value={Math.round(profile.rating)} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* achievements */}
|
|
|
|
|
<div className="glass rounded-2xl p-4 mt-4 mb-6">
|
|
|
|
|
<h3 className="text-sm font-bold text-cream/80 mb-3">{t("profile.achievements")}</h3>
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
{ACHIEVEMENTS.map((a) => {
|
|
|
|
|
const prog = achievementProgress(a.id, s, profile.rating);
|
|
|
|
|
const unlocked = profile.unlocked.includes(a.id) || prog >= a.goal;
|
|
|
|
|
const pct = Math.min(100, Math.round((prog / a.goal) * 100));
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={a.id}
|
|
|
|
|
className={cn(
|
|
|
|
|
"rounded-xl p-3 flex items-center gap-3 border",
|
|
|
|
|
unlocked ? "bg-gold-500/10 border-gold-500/40" : "bg-navy-900/50 border-navy-700/50"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<span className={cn("text-2xl", !unlocked && "grayscale opacity-50")}>
|
|
|
|
|
{a.icon}
|
|
|
|
|
</span>
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<div className="text-sm font-semibold text-cream">
|
|
|
|
|
{locale === "fa" ? a.nameFa : a.nameEn}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-[11px] text-cream/50 truncate">
|
|
|
|
|
{locale === "fa" ? a.descFa : a.descEn}
|
|
|
|
|
</div>
|
|
|
|
|
{!unlocked && a.goal > 1 && (
|
|
|
|
|
<div className="h-1.5 rounded-full bg-navy-900 overflow-hidden mt-1.5">
|
|
|
|
|
<div
|
|
|
|
|
className="h-full bg-gold-500/70"
|
|
|
|
|
style={{ width: `${pct}%` }}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
{unlocked && <Check className="size-4 text-gold-400 shrink-0" />}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</ScreenShell>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Stat({ label, value }: { label: string; value: string | number }) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="bg-navy-900/60 rounded-xl py-3 text-center">
|
|
|
|
|
<div className="text-xl font-black gold-text">{value}</div>
|
|
|
|
|
<div className="text-[10px] text-cream/55 mt-0.5">{label}</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-06-04 11:49:19 +03:30
|
|
|
|
|
|
|
|
function SoundSettings() {
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
|
const { sfx, music, toggleSfx, toggleMusic } = useSoundStore();
|
|
|
|
|
return (
|
|
|
|
|
<div className="glass rounded-2xl p-4 mt-4">
|
|
|
|
|
<h3 className="text-sm font-bold text-cream/80 mb-2">{t("settings.audio")}</h3>
|
|
|
|
|
<ToggleRow icon={<Volume2 className="size-4 text-gold-400" />} label={t("settings.sound")} on={sfx} onClick={toggleSfx} />
|
|
|
|
|
<ToggleRow icon={<Music className="size-4 text-gold-400" />} label={t("settings.music")} on={music} onClick={toggleMusic} />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ToggleRow({
|
|
|
|
|
icon,
|
|
|
|
|
label,
|
|
|
|
|
on,
|
|
|
|
|
onClick,
|
|
|
|
|
}: {
|
|
|
|
|
icon: React.ReactNode;
|
|
|
|
|
label: string;
|
|
|
|
|
on: boolean;
|
|
|
|
|
onClick: () => void;
|
|
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<button onClick={onClick} className="w-full flex items-center justify-between py-2">
|
|
|
|
|
<span className="flex items-center gap-2 text-sm text-cream/85">
|
|
|
|
|
{icon}
|
|
|
|
|
{label}
|
|
|
|
|
</span>
|
|
|
|
|
<span className={cn("relative w-11 h-6 rounded-full transition", on ? "bg-gold-500" : "bg-navy-700")}>
|
|
|
|
|
<span
|
|
|
|
|
className={cn(
|
|
|
|
|
"absolute top-0.5 size-5 rounded-full bg-white transition-all",
|
|
|
|
|
on ? "ltr:right-0.5 rtl:left-0.5" : "ltr:left-0.5 rtl:right-0.5"
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|