import { useEffect, useState } from "react"; import { Bell, X } from "lucide-react"; import { useRootData } from "~/hooks/use-root-data"; import { usePushNotifications } from "~/hooks/usePushNotifications"; const DISMISS_KEY = "push_banner_dismissed"; /** * One-time, dismissible bar prompting logged-in users to enable web push. * Shown only when: logged in, push is supported, permission not yet decided, * and the user hasn't dismissed or already subscribed. A permanent toggle in * settings lets them change their mind later. */ export function PushPermissionBanner() { const { user } = useRootData(); const { supported, permission, isSubscribed, subscribe, busy } = usePushNotifications(); const [visible, setVisible] = useState(false); useEffect(() => { if (typeof window === "undefined") return; const dismissed = localStorage.getItem(DISMISS_KEY) === "1"; setVisible( !!user?.access_token && supported && permission === "default" && !isSubscribed && !dismissed ); }, [user?.access_token, supported, permission, isSubscribed]); if (!visible) return null; const dismiss = () => { localStorage.setItem(DISMISS_KEY, "1"); setVisible(false); }; const enable = async () => { const ok = await subscribe(); // Whether granted or denied, don't nag again from the banner. localStorage.setItem(DISMISS_KEY, "1"); setVisible(false); return ok; }; return (

اعلان‌ها را فعال کنید تا از پیام‌ها و وضعیت سفارش‌ها باخبر شوید.

); }