"use client"; import { Coins } from "lucide-react"; import { useEffect, useState } from "react"; import { ScreenHeader, ScreenShell } from "@/components/online/ScreenHeader"; import { useSessionStore } from "@/lib/session-store"; import { useI18n } from "@/lib/i18n"; import { getService } from "@/lib/online/service"; import { sound } from "@/lib/sound"; import { CoinPack } from "@/lib/online/types"; import { cn } from "@/lib/cn"; export function BuyCoinsScreen() { const { t, locale } = useI18n(); const profile = useSessionStore((s) => s.profile); const setProfile = useSessionStore((s) => s.setProfile); const [packs, setPacks] = useState([]); const [busy, setBusy] = useState(null); const [gained, setGained] = useState(null); useEffect(() => { getService().getCoinPacks().then(setPacks); }, []); const fmt = (n: number) => new Intl.NumberFormat(locale === "fa" ? "fa-IR" : "en-US").format(n); const buy = async (p: CoinPack) => { setBusy(p.id); const res = await getService().buyCoins(p.id); // Live: redirect to the ZarinPal gateway; we credit on return via callback. if (res.redirectUrl) { window.location.href = res.redirectUrl; return; } // Mock/offline: instant credit. if (res.ok && res.profile) { setProfile(res.profile); sound.play("purchase"); setGained(res.coins); setTimeout(() => setGained(null), 2500); } setBusy(null); }; return ( {fmt(profile.coins)} ) } />

{t("buy.note")}

{gained != null && (
+{fmt(gained)}
)}
{packs.map((p) => ( ))}
); }