PageSourceSearch

https://projet-garderie.web.app/_app/immutable/chunks/Cn6GjU4z.js

js projet-garderie.web.app collected 2026-10-03 12:36:17 UTC 12,763 bytes, 2 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./CXjoeY5j.js","./Dp1pzeXC.js","./BhjbYdww.js","./BqFx2359.js","./lGRd_bat.js","./k3cEw5AQ.js"])))=>i.map(i=>d[i]);
2var C=Object.defineProperty;var _=(u,e,t)=>e in u?C(u,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):u[e]=t;var h=(u,e,t)=>_(u,typeof e!="symbol"?e+"":e,t);import{_ as P}from"./Dp1pzeXC.js";import{e as c,a as r,b as s}from"./BbtZ9zyD.js";import{Capacitor as d}from"./BhjbYdww.js";import{a as g}from"./DzLQPBVA.js";import{d as b,g as L,a as R,h as B}from"./CaRavT0G.js";import{d as N,u as S,e as D,g as z}from"./D7OQQumb.js";import{g as T}from"./unFpG8fo.js";import{a as $}from"./Cn_dVAt4.js";import{g as O}from"./CYCJTacv.js";import{e as M,r as U,w as q,g as j}from"./C1uLuxPV.js";import{t as x}from"./D4U0lY42.js";import{t as V}from"./hseYEndr.js";let l=null;async function W(){if(d.isNativePlatform())try{l=(await P(()=>import("./CXjoeY5j.js"),__vite__mapDeps([0,1,2]),import.meta.url)).Badge}catch(u){c("Module Badge non disponible:",u)}}class G{constructor(){h(this,"isInitialized",!1)}async initialize(){if(!(!d.isNativePlatform()||this.isInitialized))try{if(await W(),!l){c("Badge API non disponible sur cette plateforme");return}this.isInitialized=!0,r("Service de badge initialisé avec succès")}catch(e){s("Erreur lors de l'initialisation du service de badge:",e)}}async setBadgeCount(e){if(d.isNativePlatform())try{if(await this.initialize(),!l){c("Badge API non disponible");return}await l.set({count:e}),r(`Badge mis à jour: ${e}`)}catch(t){s("Erreur lors de la mise à jour du badge:",t)}}async clearBadge(){if(d.isNativePlatform())try{if(await this.initialize(),!l){c("Badge API non disponible");return}await l.clear(),r("Badge effacé")}catch(e){s("Erreur lors de l'effacement du badge:",e)}}async getBadgeCount(){if(!d.isNativePlatform())return 0;try{return await this.initialize(),l?(await l.get()).count||0:(c("Badge API non disponible"),0)}catch(e){return s("Erreur lors de la récupération du badge:",e),0}}async incrementBadge(){if(d.isNativePlatform())try{if(await this.initialize(),!l){c("Badge API non disponible");return}await l.increase(),r("Badge incrémenté")}catch(e){s("Erreur lors de l'incrémentation du badge:",e)}}async decrementBadge(){if(d.isNativePlatform())try{if(await this.initialize(),!l){c("Badge API non disponible");return}await l.decrease(),r("Badge décrémenté")}catch(e){s("Erreur lors de la décrémentation du badge:",e)}}async isSupported(){if(!d.isNativePlatform())return!1;try{return await this.initialize(),l?(await l.isSupported()).isSupported:!1}catch(e){return s("Erreur lors de la vérification du support des badges:",e),!1}}}const y=new G,E=2147483647;let I=Date.now()%E;function H(){return I=I%E+1,I}let f,v,p;async function F(){if(!f||!v)try{const[u,e]=await Promise.all([P(()=>import("./BqFx2359.js"),__vite__mapDeps([3,2]),import.meta.url),P(()=>import("./lGRd_bat.js"),__vite__mapDeps([4,1,2]),import.meta.url)]);f=u.PushNotifications,v=e.LocalNotifications}catch(u){s("Erreur lors de l'import des modules de notifications:",u)}if(!p)try{p=(await P(()=>import("./k3cEw5AQ.js"),__vite__mapDeps([5,1,2]),import.meta.url)).Preferences}catch{}}class A{constructor(){h(this,"isInitialized",!1);h(this,"listenersRegistered",!1);h(this,"registrationToken",null);h(this,"pendingToken",null);h(this,"unsubscribeAuth",null);h(this,"tokenResolvers",[]);h(this,"saveInFlight",null);h(this,"lastSavedToken",null);h(this,"lastSavedUserId",null);h(this,"lastSaveAt",0);try{this.unsubscribeAuth=g.subscribe(e=>{if(e.user&&this.pendingToken){r("👤 Utilisateur connecté, sauvegarde du token en attente...");const t=this.pendingToken;this.pendingToken=null,this.saveTokenToFirestore(t)}})}catch{}}async initialize(){if(!d.isNativePlatform()||this.isInitialized){r("NotificationService: Initialisation ignorée (pas natif ou déjà initialisé)");return}try{if(r("🔔 Initialisation du service de notifications..."),await F(),!f)throw new Error("Module de notifications push non disponible");this.registerListeners(),await this.requestPermissions(),await f.register(),this.isInitialized=!0,r("✅ Service de notifications initialisé avec succès")}catch(e){throw s("❌ Erreur lors de l'initialisation du service de notifications:",e),e}}async requestPermissions(){try{const e=await f.checkPermissions();if(r("📋 Statut des permissions:",e),e.receive==="prompt"){r("🔔 Demande de permissions de notifications...");const t=await f.requestPermissions();if(r("📋 Résultat de la demande:",t),t.receive!=="granted")throw new Error("Permissions de notifications refusées")}else if(e.receive==="denied")throw new Error("Permissions de notifications refusées par l'utilisateur");return!0}catch(e){throw s("❌ Erreur lors de la demande de permissions:",e),e}}registerListeners(){if(!this.listenersRegistered){if(this.listenersRegistered=!0,r("🎧 Enregistrement des listeners de notifications..."),f.addListener("registration",e=>{var i;const t=((i=e.value)==null?void 0:i.slice(0,16))||"",n=this.isLikelyFcmToken(e.value);r(`✅ Token de registration reçu (isFCM=${n}, sample=${t}…)`),n?this.registrationToken=e.value:c("Token reçu ne ressemble pas à un token FCM — ignoré pour l'enregistrement");try{T(g).user&&n?this.saveTokenToFirestore(e.value):n?(r("⚠️ Aucun utilisateur connecté, token FCM mis en attente"),this.pendingToken=e.value):r("⚠️ Token non-FCM reçu, aucune mise en attente")}catch{n&&(this.pendingToken=e.value)}
2this.tokenResolvers.forEach(a=>{try{a(e.value)}catch{}}),this.tokenResolvers=[]}),f.addListener("registrationError",e=>{s("❌ Erreur d'enregistrement des notifications:",e)}),f.addListener("pushNotificationReceived",async e=>{var i;r("📨 Notification reçue (app au premier plan):",e);const t=(i=e==null?void 0:e.data)==null?void 0:i.badgeCount,n=typeof t=="string"?parseInt(t,10):NaN;if(!isNaN(n))try{await y.setBadgeCount(n)}catch{}this.handleForegroundNotification(e)}),f.addListener("pushNotificationActionPerformed",async e=>{r("👆 Action sur notification:",e);try{await y.clearBadge()}catch{}await this.handleNotificationAction(M(e))}),v&&v.addListener("localNotificationActionPerformed",async e=>{r("👆 Action sur notification locale:",e);try{await y.clearBadge()}catch{}await this.handleNotificationAction(M(e))}),d.getPlatform()==="ios")try{window.addEventListener("nativeFCMToken",async e=>{var i;const t=(i=e==null?void 0:e.detail)==null?void 0:i.token;if(!t)return;const n=this.isLikelyFcmToken(t);if(r(`📥 nativeFCMToken reçu (isFCM=${n}, sample=${t.slice(0,12)}…)`),!!n){this.registrationToken=t;try{p&&(await p.set({key:"FCMToken",value:t}),r("✅ Token FCM sauvegardé dans Preferences"))}catch(a){s("Erreur lors de la sauvegarde dans Preferences:",a)}try{T(g).user?(r("👤 Utilisateur connecté, sauvegarde immédiate du token FCM"),await this.saveTokenToFirestore(t)):(r("⏳ Aucun utilisateur connecté, token FCM mis en attente"),this.pendingToken=t)}catch{c("nativeFCMToken: erreur sauvegarde immédiate, token en attente"),this.pendingToken=t}this.tokenResolvers.forEach(a=>{try{a(t)}catch{}}),this.tokenResolvers=[]}})}catch(e){c("Impossible d’enregistrer le listener nativeFCMToken",e)}r("✅ Listeners de notifications enregistrés")}}async waitForFcmTokenFromPreferences(e=8e3,t=400){if(!p)return c("Preferences module not available"),null;const n=Date.now();let i=0;for(;Date.now()-n<e;){i++;try{const o=(await p.get({key:"FCMToken"})).value;if(o){if(r(`🔎 Preferences FCMToken found after ${i} attempts (len: ${o.length})`),this.isLikelyFcmToken(o))return o;c("Preferences token not FCM format; retrying...")}else i%5===0&&r(`⏳ Waiting for FCMToken in Preferences (attempt ${i})...`)}catch(a){c("Reading Preferences FCMToken failed (retrying)",a)}await new Promise(a=>setTimeout(a,t))}return c(`❌ Timeout après ${i} tentatives de lecture du FCMToken dans Preferences`),null}async ensureRegistrationTokenSaved(){if(d.isNativePlatform())try{const e=T(g);if(!e.user){r("❌ Aucun utilisateur connecté, impossible de sauvegarder le token");return}if(await F(),!f)return;this.registerListeners(),r("🔍 Recherche du token FCM pour sauvegarde...");let t=this.registrationToken||this.pendingToken;const n=d.getPlatform();if(n==="ios"){if(r("📱 iOS détecté, vérification du token dans Preferences..."),p)try{const i=await p.get({key:"FCMToken"});if(i.value&&this.isLikelyFcmToken(i.value))r("✅ Token FCM trouvé dans Preferences"),t=i.value;else{r("⏳ Token non trouvé dans Preferences, attente...");const a=await this.waitForFcmTokenFromPreferences(1e4,300);a&&(t=a)}}catch(i){s("Erreur lecture Preferences:",i)}if(!t){r("⏳ Attente supplémentaire pour iOS...");const i=await this.waitForFcmTokenFromPreferences(5e3,200);i&&(t=i)}}else if(n==="android"&&!t&&f){r("🔁 Android: re-enregistrement pour obtenir le token");try{t=await new Promise((i,a)=>{const o=()=>{clearTimeout(k),this.tokenResolvers=this.tokenResolvers.filter(w=>w!==m)},m=w=>{o(),i(w)},k=setTimeout(()=>{o(),a(new Error("Timeout"))},5e3);this.tokenResolvers.push(m),f.register().catch(w=>{o(),a(w)})})}catch(i){s("Échec re-enregistrement Android:",i)}}if(t&&this.isLikelyFcmToken(t)){r(`✅ Token FCM valide trouvé, sauvegarde dans Firebase (${t.substring(0,20)}...)`),this.pendingToken=null,this.registrationToken=t,await this.saveTokenToFirestore(t);try{const i=N(b,"users",e.user.uid),k=(((await $(i)).data()||{}).fcmTokens||[]).filter(w=>!this.isLikelyFcmToken(w));k.length>0&&(await S(i,{fcmTokens:D(...k)}),r(`🧹 ${k.length} tokens invalides nettoyés`))}catch(i){c("Nettoyage tokens échoué:",i)}}else s("❌ Aucun token FCM valide disponible pour sauvegarde")}catch(e){s("❌ Erreur dans ensureRegistrationTokenSaved:",e)}}isLikelyFcmToken(e){return e?e.includes(":")?!0:/^[0-9A-F]+$/i.test(e)?!1:e.length>80:!1}async saveTokenToFirestore(e){var t;try{const n=T(g);if(!n.user){r("⚠️ Aucun utilisateur connecté, token non sauvegardé");return}const i=n.user.uid,a=()=>this.lastSavedUserId===i&&this.lastSavedToken===e&&Date.now()-this.lastSaveAt<1e4;if(a())return;if(this.saveInFlight){try{await this.saveInFlight}catch{}if(((t=T(g).user)==null?void 0:t.uid)!==i||a())return}this.saveInFlight=(async()=>{try{const o=L(R,"northamerica-northeast1"),k=await B(o,"registerPushToken")({token:e});this.lastSavedToken=e,this.lastSavedUserId=i,this.lastSaveAt=Date.now(),r(`✅ Token FCM enregistré via CF (removedFrom=${k.data.removedFrom}) pour ${i}`)}catch(o){c("registerPushToken Cloud Function indisponible, fallback direct updateDoc",o);const m=N(b,"users",i);await S(m,{fcmTokens:z(e),lastTokenUpdate:new Date}),this.lastSavedToken=e,this.lastSavedUserId=i,this.lastSaveAt=Date.now(),r("✅ Token FCM sauvegardé (fallback) pour l'utilisateur:",i)}finally{this.saveInFlight=null}})(),await this.saveInFlight}catch(n){s("❌ Erreur lors de la sauvegarde du token:",n)}}async scheduleLocalNotification(e,t){if(d.isNativePlatform())try{if
2(await F(),!v)return;await v.schedule({notifications:[{title:e.title,body:e.body,id:H(),schedule:t?{at:t}:{at:new Date(Date.now()+1e3)},sound:e.sound||"default",attachments:[],actionTypeId:"",extra:e.data}]})}catch(n){s("❌ Erreur scheduleLocalNotification:",n)}}async removeAllDeliveredNotifications(){if(d.isNativePlatform())try{if(await F(),!v)return;await v.removeAllDeliveredNotifications()}catch(e){s("❌ Erreur removeAllDeliveredNotifications:",e)}}async handleForegroundNotification(e){var t;r("🔔 Notification reçue en avant-plan (aucune locale affichée):",e==null?void 0:e.data);try{const n=(t=e==null?void 0:e.data)==null?void 0:t.badgeCount,i=typeof n=="string"?parseInt(n,10):NaN;isNaN(i)||await y.setBadgeCount(i)}catch{}}async handleNotificationAction(e){r("👆 Gestion de l'action sur notification:",e);const t=typeof e.notificationId=="string"?e.notificationId:"";t&&S(N(b,"notifications",t),{read:!0}).catch(m=>{c("Impossible de marquer la notification ouverte comme lue",m)});const n=T(g).currentMode,i=j(window.location.pathname,n),a=U(e,i),o=q(a.href);if(r("🔗 Navigation de notification:",o),a.mode&&(a.mode!==i||a.mode!==n)){a.mode!==i&&x.show(V(a.mode==="parent"?"modeSwitcher.switchedToParent":"modeSwitcher.switchedToEducator"),"info"),await g.switchMode(a.mode,o);return}await O(o)}getRegistrationToken(){return this.registrationToken}isServiceInitialized(){return this.isInitialized}async sendTestNotification(){if(!this.registrationToken)throw new Error("Aucun token d'enregistrement disponible");r("🧪 Envoi d'une notification de test..."),r("Token:",this.registrationToken)}}const X=new A,ce=Object.freeze(Object.defineProperty({__proto__:null,NotificationService:A,notificationService:X},Symbol.toStringTag,{value:"Module"}));export{ce as a,y as b,X as n};

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.