1var G=Object.defineProperty;var R=(i,t,e)=>t in i?G(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var u=(i,t,e)=>R(i,typeof t!="symbol"?t+"":t,e);import{t as n,v as E,w as v}from"./index-CKCEYSTE.js";import{q as w,l as p,o as I,w as y,c as S,g as L,a as D,u as f,d as l,b as q}from"./vendor-firebase-DbFCdLkQ.js";import"./vendor-react-BoyrKzsG.js";import"./vendor-ui-Cy9YOY35.js";const C=new v("lumoSession",!0),d=new v("lumoMessages",!0),M=12*60*60*1e3,N=12*60*60*1e3,U={breathing:{id:"breathing",type:"breathing",title:"5-5-5 Breathing",durationMinutes:4,description:"Regulate your nervous system with rhythmic breathing."},grounding:{id:"grounding",type:"writing",title:"Grounding (5-4-3-2-1)",durationMinutes:3,description:"Anchor yourself in the present moment."},leaves_on_stream:{id:"leaves_on_stream",type:"meditation",title:"Leaves on a Stream",durationMinutes:4,description:"A mindfulness exercise to help with mental noise."}};function F(i){return U[i]}const a=class a{static async getOrCreateActiveSession(t,e){const s=w(S(n,this.SESSIONS_COLLECTION),y("userId","==",t),y("status","==","active"),I("lastInteraction","desc"),p(1)),c=await L(s);if(!c.empty){const g=c.docs[0],h=g.data(),m=h.lastInteraction||h.startedAt||0,O=Date.now(),A=12*60*60*1e3,_=new Date(m).toDateString(),x=new Date(O).toDateString(),$=_!==x,b=O-m>A;if(!$&&!b)return{id:g.id,...h};this.archiveSession(g.id).catch(B=>console.warn("[LumoNav] Session archive error:",B))}const r={userId:t,struggles:e,startedAt:Date.now(),lastInteraction:Date.now(),status:"active"};return{id:(await D(S(n,this.SESSIONS_COLLECTION),r)).id,...r}}static async getMessages(t,e=30){const s=w(S(n,this.SESSIONS_COLLECTION,t,this.MESSAGES_SUBCOLLECTION),I("timestamp","desc"),p(e));return(await L(s)).docs.reverse().map(r=>{const o=r.data();return o.exerciseId&&!o.exercise&&(o.exercise=F(o.exerciseId)),{id:r.id,...o}})}static async addMessage(t,e){const s={...e,timestamp:Date.now()};await D(S(n,this.SESSIONS_COLLECTION,t,this.MESSAGES_SUBCOLLECTION),s),await f(l(n,this.SESSIONS_COLLECTION,t),{lastInteraction:Date.now()})}static async archiveSession(t){await f(l(n,this.SESSIONS_COLLECTION,t),{status:"archived",lastInteraction:Date.now()})}static async getStrugglesContext(t){var c;const e=l(n,"users",t),s=await q(e);return s.exists()?((c=s.data().profile)==null?void 0:c.struggles)||[]:[]}static async getOrCreateActiveSessionCached(t,e){return E(C,`session-${t}`,()=>a.getOrCreateActiveSession(t,e),M)}static async getMessagesCached(t){return E(d,`messages-${t}`,()=>a.getMessages(t),N)}static appendToMessagesCache(t,...e){const s=d.get(`messages-${t}`);s&&d.set(`messages-${t}`,[...s,...e],N)}static cacheSession(t,e){C.set(`session-${t}`,e,M)}static invalidateSessionCache(t,e){C.delete(`session-${t}`),e&&d.delete(`messages-${e}`)}static async primeCache(t,e){try{const s=await a.getOrCreateActiveSessionCached(t,e);await a.getMessagesCached(s.id)}catch{}}};u(a,"SESSIONS_COLLECTION","lumo_navigator_sessions"),u(a,"MESSAGES_SUBCOLLECTION","messages");let T=a;export{T as LumoNavigatorService,F as getExerciseById};
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.