"use client"; import { usePushNotifications } from "@/lib/usePushNotifications"; import { usePWAInstall } from "@/lib/usePWAInstall"; import { useState } from "react"; // test v1 export function NotificationManager({ publicKey }: { publicKey: string }) { const { isSupported, subscription, subscribeToPush, unsubscribeFromPush } = usePushNotifications(publicKey); const { deferredPrompt, isAppInstalled, handleInstallClick } = usePWAInstall(); const [message, setMessage] = useState("halo apa kabar"); const sendTestNotification = async () => { if (!subscription) return; try { const res = await fetch("/api/send-notification", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ sub: subscription.toJSON(), message }) }); if (!res.ok) { console.error("Failed to send notification:", res.statusText); } } catch (error) { console.error("Notification error:", error); } }; if (!isSupported) { return

Push notifications are not supported in this browser.

; } return (

Push Notifications & PWA Install

{subscription ? ( <>

You are subscribed to push notifications.

setMessage(e.target.value)} />
) : ( <>

You are not subscribed to push notifications.

)}
{!isAppInstalled && deferredPrompt && ( )}
); }