import { useState, useEffect } from "react"; import WatchConnectivity from "../../modules/watch-connectivity"; type WatchConnectionStatus = "connected" | "disconnected" | "pending"; export function useWatchConnection() { const [status, setStatus] = useState("pending"); const [isPaired, setIsPaired] = useState(false); const [isInstalled, setIsInstalled] = useState(false); useEffect(() => { checkStatus(); const interval = setInterval(checkStatus, 5000); return () => clearInterval(interval); }, []); const checkStatus = async () => { try { const supported = await WatchConnectivity.isSupported(); if (!supported) { setStatus("disconnected"); return; } const paired = await WatchConnectivity.isPaired(); const installed = await WatchConnectivity.isWatchAppInstalled(); const reachable = await WatchConnectivity.isReachable(); setIsPaired(paired); setIsInstalled(installed); setStatus(reachable ? "connected" : "disconnected"); } catch { setStatus("disconnected"); } }; return { status, isPaired, isInstalled }; }