import { useEffect, useMemo, useState } from "react"; import { useNavigate } from "react-router-dom"; import { ChevronRight, Plus } from "lucide-react"; import { useProfile } from "../context/ProfileContext"; import { getCachedProfile } from "../../services/profileService"; import { getProfileImageUrl } from "../../services/feedService"; import logoImage from "figma:asset/0a77244cc5b7dea0bea10275d45df2915d5170ca.png"; import coinImage from "../../assets/coin-star.png"; import profileFallbackImage from "../../assets/image 5.png"; interface AppHeaderProps { showBack?: boolean; onBack?: () => void; centerTitle?: string; centerSubtitle?: string; } const toPersianNumber = (num: number | null | undefined): string => { if (num === null || num === undefined) return "۰"; const persianDigits = "۰۱۲۳۴۵۶۷۸۹"; return String(num).replace(/\d/g, (digit) => persianDigits[parseInt(digit, 10)]); }; export function AppHeader({ showBack = false, onBack, centerTitle, centerSubtitle }: AppHeaderProps) { const navigate = useNavigate(); const { profile } = useProfile(); const [displayCoins, setDisplayCoins] = useState(() => { const cachedProfile = getCachedProfile(); return cachedProfile?.coin_count ?? 0; }); useEffect(() => { if (profile?.coin_count !== null && profile?.coin_count !== undefined) { setDisplayCoins(profile.coin_count); } }, [profile]); const hasCustomAvatar = Boolean(profile?.image && profile?.user_stage_id); const avatarUrl = useMemo(() => { if (hasCustomAvatar) { return getProfileImageUrl(profile.image, profile.user_stage_id); } return profileFallbackImage; }, [hasCustomAvatar, profile?.image, profile?.user_stage_id]); const navLikePanelStyle = { backgroundImage: ` linear-gradient(180deg, #2E1B3D 0%, #23183E 100%), linear-gradient(120deg, #7c3aed 0%, #f97316 58%, #facc15 100%) `, backgroundOrigin: "border-box", backgroundClip: "padding-box, border-box", boxShadow: "0 -7px 20px rgba(7, 0, 18, 0.5), 0 6px 14px rgba(5, 2, 12, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.2), inset 0 2px 5px rgba(255, 222, 255, 0.09), inset 0 -2px 0 rgba(12, 7, 27, 0.72), inset 0 -8px 14px rgba(8, 4, 18, 0.34), inset 0 0 0 1px rgba(255, 255, 255, 0.045), inset 0 0 0 2px rgba(17, 10, 35, 0.32)", backdropFilter: "blur(14px)", WebkitBackdropFilter: "blur(14px)", } as const; return (
{showBack ? ( ) : ( )}
{centerTitle ? (
{centerTitle}
{centerSubtitle && (
{centerSubtitle}
)}
) : ( مدرسه )}
{toPersianNumber(displayCoins)} سکه
); }