import{t as e}from"./axios-m7YkukvY.js";import{et as t}from"./runtime-core.esm-bundler-Babufkcf.js";import{t as n}from"./zkBridge-DieZRNp1.js";function r(){let r=t(!1),i=t(0),a=t(!1),o=t(!1),s=t(null),c=t(``),l=t(`idle`),u=[];function d(e){typeof e==`function`&&u.push(e)}async function f(){a.value=!0,c.value=``;try{let t=await n.isOnline();if(r.value=t.online,!t.online)return l.value=`error`,c.value=t.message,{success:!1};let{data:a}=await e.get(`/fingerprints/templates`),o=a?.templates||[];if(!o.length)return i.value=0,l.value=`error`,c.value=`nobody_enrolled`,{success:!1,empty:!0};let s=await n.loadTemplates(o);return s.success?(i.value=s.loaded??o.length,l.value=`ready`,{success:!0,loaded:i.value}):(l.value=`error`,c.value=s.message,{success:!1})}catch(e){return l.value=`error`,c.value=e?.response?.data?.message||`load_failed`,{success:!1}}finally{a.value=!1}}async function p(t,n={}){let[r,i]=await Promise.all([e.get(`/users/`+t).then(e=>e.data).catch(()=>null),e.get(`/fingerprints/`+t).then(e=>e.data?.fingerprint).catch(()=>null)]),a={id:t,score:n.score??null,user:r?.data??r??null,print:i??null};s.value=a;for(let e of u)try{await e(a)}catch{}return a}async function m({timeoutMs:e=1e4}={}){if(o.value)return{success:!1};o.value=!0,l.value=`scanning`,c.value=``,s.value=null;try{let t=await n.identify({timeoutMs:e});return t.success?t.matched?(await p(t.id,{score:t.score}),l.value=`found`,t):(l.value=`nomatch`,c.value=`not_recognised`,t):(l.value=t.offline?`error`:`nomatch`,c.value=t.message,t)}finally{o.value=!1}}function h(){s.value=null,c.value=``,l.value=i.value>0?`ready`:`idle`}return{bridgeOnline:r,loadedCount:i,loading:a,scanning:o,person:s,message:c,state:l,loadDatabase:f,scanOnce:m,onIdentified:p,onIdentifiedHook:d,reset:h}}export{r as t};