import{a1 as A,o as S,P as E}from"./vue-core-Di3IuVqe.js";import{b as n,s as i}from"./index-BxIwIJfy.js";const a={async updateActivity(t){if(t)try{await n.post(`${i.lienApi}/sessions_remote/${t}/activity`)}catch{}},async recordLogout(t){if(t)try{await n.post(`${i.lienApi}/sessions_remote/${t}/logout`)}catch{}},async recordTimeout(t){if(t)try{await n.post(`${i.lienApi}/sessions_remote/${t}/timeout`)}catch{}}},L={salarie:{sessionKey:"portailSalarieSessionId",logoutMutation:"PORTAIL_SALARIE_LOGOUT",loginPath:"/portail-salarie/login"},client:{sessionKey:"portailClientSessionId",logoutMutation:"PORTAIL_CLIENT_LOGOUT",loginPath:"/portail-client/login"},cabinet:{sessionKey:"portailCabinetSessionId",logoutMutation:"PORTAIL_CABINET_LOGOUT",loginPath:"/portail-cabinet/login"}};function _(t,s=30){const T=A(),r=L[t];if(!r)throw new Error(`usePortailSession: portail inconnu "${t}"`);const h=s*60*1e3,v=6e4;let e=null,c=0;const l=["mousedown","mousemove","keydown","scroll","touchstart","click","wheel"],u=()=>i.state[r.sessionKey],m=async(o="manuel")=>{y();const d=u();o==="timeout"?await a.recordTimeout(d):await a.recordLogout(d),i.commit(r.logoutMutation),T.push({path:r.loginPath,query:o==="timeout"?{reason:"inactivity"}:void 0})},w=()=>{const o=Date.now();o-c>=v&&(c=o,a.updateActivity(u()))},p=()=>{e&&clearTimeout(e),w(),e=setTimeout(()=>m("timeout"),h)},g=()=>p(),f=()=>{l.forEach(o=>window.addEventListener(o,g,{passive:!0})),p()},y=()=>{l.forEach(o=>window.removeEventListener(o,g)),e&&(clearTimeout(e),e=null)};return S(f),E(y),{deconnexion:m}}export{_ as u};
