import{a as e,c as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./index-BmLWNgFR.js";var c={"X-Family-Connect-Request":`device`};async function l(){let e={timestamp:new Date().toISOString(),userAgent:navigator.userAgent,viewport:`${window.innerWidth}x${window.innerHeight}`,secureContext:window.isSecureContext,online:navigator.onLine,indexedDb:`indexedDB`in window,serviceWorker:`serviceWorker`in navigator,notifications:`Notification`in window,pushManager:`PushManager`in window,mediaDevices:!!navigator.mediaDevices?.getUserMedia,mediaRecorder:`MediaRecorder`in window};return`MediaRecorder`in window&&(e.supportedAudioTypes=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`].filter(e=>MediaRecorder.isTypeSupported(e))),e}async function u(){return new Promise((e,t)=>{let n=indexedDB.open(`family-connect-probe`,1);n.onupgradeneeded=()=>n.result.createObjectStore(`probe`),n.onerror=()=>t(n.error),n.onsuccess=()=>{let r=n.result,i=r.transaction(`probe`,`readwrite`),a=i.objectStore(`probe`);a.put(new Blob([`probe`],{type:`text/plain`}),`blob`);let o=a.get(`blob`);o.onerror=()=>t(o.error),o.onsuccess=()=>{let t=o.result instanceof Blob&&o.result.size===5;a.delete(`blob`),i.oncomplete=()=>{r.close(),indexedDB.deleteDatabase(`family-connect-probe`),e(t)}}}})}async function d(){await s(`/device-probes/cookie`,{method:`POST`,headers:c,body:`{}`});let e=await s(`/device-probes/cookie`);return await s(`/device-probes/cookie`,{method:`DELETE`,headers:c}),e.stored}async function f(){return`serviceWorker`in navigator?(await(await navigator.serviceWorker.register(`/app/probe-sw.js`,{scope:`/app/`})).unregister(),`registered-and-removed`):`unsupported`}async function p(){let e=await navigator.mediaDevices.getUserMedia({audio:!0}),t=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`].find(e=>MediaRecorder.isTypeSupported(e)),n=new MediaRecorder(e,t?{mimeType:t}:void 0),r=[];return new Promise((t,i)=>{n.ondataavailable=e=>r.push(e.data),n.onerror=()=>i(Error(`MediaRecorder error`)),n.onstop=async()=>{e.getTracks().forEach(e=>e.stop());let i=new Blob(r,{type:n.mimeType}),a=URL.createObjectURL(i),o=new Audio(a),s=await new Promise(e=>{o.oncanplay=()=>e(!0),o.onerror=()=>e(!1),setTimeout(()=>e(!1),3e3)});URL.revokeObjectURL(a),t({type:i.type,size:i.size,playable:s})},n.start(),setTimeout(()=>n.stop(),3e3)})}var m={class:`panel`},h={class:`actions`},g=[`disabled`],_=[`disabled`],v={key:0},y=e({__name:`ProbeView`,setup(e){let s=o({}),c=o(!1);async function y(){c.value=!0,s.value=await l();for(let[e,t]of Object.entries({indexedDbWriteReadDelete:u,secureCookie:d,serviceWorkerRegistration:f}))try{s.value[e]=await t()}catch(t){s.value[e]=t instanceof Error?t.message:`failed`}c.value=!1}async function b(){try{s.value.audioRecording=await p()}catch(e){s.value.audioRecording=e instanceof Error?e.message:`failed`}}function x(){let e=new Blob([JSON.stringify(s.value,null,2)],{type:`application/json`}),t=document.createElement(`a`);t.href=URL.createObjectURL(e),t.download=`family-connect-probe-${Date.now()}.json`,t.click(),URL.revokeObjectURL(t.href)}return(e,o)=>(i(),n(`section`,m,[o[0]||=r(`p`,{class:`eyebrow`},`Diagnostic Passe 1`,-1),o[1]||=r(`h1`,null,`Probes du terminal`,-1),o[2]||=r(`p`,null,`Aucun message familial ni secret n’est collecté.`,-1),r(`div`,h,[r(`button`,{class:`button primary`,disabled:c.value,onClick:y},t(c.value?`Tests en cours…`:`Lancer les probes`),9,g),r(`button`,{class:`button secondary`,onClick:b},`Tester 3 secondes de microphone`),r(`button`,{class:`button secondary`,disabled:!Object.keys(s.value).length,onClick:x},`Exporter en JSON`,8,_)]),Object.keys(s.value).length?(i(),n(`pre`,v,t(JSON.stringify(s.value,null,2)),1)):a(``,!0)]))}});export{y as default};