1import{r as e}from"./vendor-react-BfgFmtGS.js";import{C as r,r as t,P as i}from"./vendor-capacitor-8exTJy5k.js";import{supabase as a}from"./supabase-client-2CObC91N.js";import{a as o}from"./useAuth-DynbexoK.js";import{g as s,n}from"./shareUrls-CnKIAmlW.js";import{c}from"./startup-diagnostics-bridge-BB8dzHvV.js";import{B as l,C as u}from"./useUserSettings-COWmNJt_.js";import{u as m}from"./vendor-router-QOYqHwMx.js";const d=t("EchoFirebase"),f=({enabled:t=!0})=>(((t=!0)=>{const{user:f,profile:p}=o(),v=m(),[h,_]=e.useState("prompt"),[b,g]=e.useState(!1),k=e.useCallback(async e=>{if(!f)return;const t=r.getPlatform();try{l(e);const{data:r,error:i}=await a.rpc("upsert_push_token",{p_token:e,p_platform:t,p_device_info:await u()});if(i)throw i;g(!0)}catch(i){}},[f]),w=e.useCallback(e=>{const r=e.notification.data;(null==r?void 0:r.memory_id)?v(s({id:r.memory_id,ownerUsername:null==p?void 0:p.username})):(null==r?void 0:r.link)&&v(n(r.link,null==p?void 0:p.username)||r.link)},[v,null==p?void 0:p.username]),y=e.useCallback(e=>{},[]),P=e.useCallback(async()=>{if("android"===r.getPlatform())try{await i.createChannel({id:"echo_default",name:"Echo notifications",description:"Updates, reminders, and activity from Echo.",importance:4,visibility:1,vibration:!0,lights:!0,lightColor:"#FC6F61"})}catch(e){}},[]),C=e.useCallback(async()=>{if(!r.isNativePlatform())return!1;try{let e=await i.checkPermissions();if("prompt"===e.receive&&(e=await i.requestPermissions()),"granted"!==e.receive)return _("denied"),!1;_("granted"),await P();const t=await(async()=>r.isNativePlatform()&&"android"===r.getPlatform()?d.ensureInitialized():{initialized:!0,source:"not_android"})();return t.initialized?(await i.register(),!0):(c(new Error(`Firebase initialization failed: ${t.reason||t.source}.`),{source:"push.firebase-init",tags:{platform:r.getPlatform(),firebase_init_source:t.source,firebase_init_reason:t.reason||"unknown"}}),!1)}catch(e){return!1}},[P]);e.useEffect(()=>{if(!t)return;if(!r.isNativePlatform()||!f)return;const e=i.addListener("registration",e=>{k(e.value)}),a=i.addListener("registrationError",e=>{}),o=i.addListener("pushNotificationReceived",y),s=i.addListener("pushNotificationActionPerformed",w);return C(),()=>{e.then(e=>e.remove()),a.then(e=>e.remove()),o.then(e=>e.remove()),s.then(e=>e.remove())}},[t,f,k,y,w,C]);const j=e.useCallback(async e=>{try{await a.rpc("remove_push_token",{p_token:e}),l(""),g(!1)}catch(r){}},[])})(t),t?(r.isNativePlatform(),null):null);export{f as PushNotificationManager};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.