import{b as H,_ as J}from"../chunks/p_pjGDZp.js";import"../chunks/Bzak7iHL.js";import{o as Y,a as Z}from"../chunks/DkY7lyAx.js";import{g as $,p as ee,ay as te,az as ae,l as s,a as d,b as oe,d as n,c as p,k as re,$ as se,s as u,n as g,r as i,o as m,h as _,t as N,e as P,j,f as ne}from"../chunks/CiQWViEs.js";import{i as x}from"../chunks/CEkQpEF5.js";import{h as ie}from"../chunks/DG4rvltU.js";import{r as le}from"../chunks/zaEOnEon.js";import{b as ce}from"../chunks/DfatFK53.js";import{g as de}from"../chunks/CLZfVTF1.js";const ue="EDUMIND1";function me(y){var c,l;const a=y.trim();if(!a)return null;if(a.startsWith(ue+"|")){const o=a.split("|"),v=(c=o[1])==null?void 0:c.trim();return v?{code:v,categoryCode:((l=o[2])==null?void 0:l.trim())||null}:null}if(a.includes("/")){const o=a.split(/[/?#]/).filter(Boolean).pop();if(o)return{code:o.toUpperCase(),categoryCode:null}}return{code:a.toUpperCase(),categoryCode:null}}var pe=p('<p class="mb-4 rounded-lg bg-amber-50 px-4 py-3 text-sm font-medium text-amber-800" role="alert">No se encontró ningún equipo con el código <strong class="font-mono"> </strong>.</p>'),ve=p('<button class="btn-secondary">Detener</button>'),fe=p('<button class="btn-primary">Activar cámara</button>'),be=p('<p class="mt-3 rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700"> </p>'),ge=p('<div class="mt-4 overflow-hidden rounded-xl bg-black"><video class="aspect-video w-full object-cover" autoplay="" playsinline=""></video></div> <p class="mt-2 text-center text-sm text-slate-500">Apunta al código QR de la etiqueta…</p>',3),_e=p('<div class="mt-4 flex aspect-video items-center justify-center rounded-xl border-2 border-dashed border-slate-200 text-slate-400"><span>La cámara aparecerá aquí</span></div>'),xe=p('<div class="mx-auto max-w-xl"><div class="mb-6"><h1 class="text-2xl font-bold text-slate-900">Escanear equipo</h1> <p class="text-slate-600">Escanea el QR con la cámara o el lector USB, o escribe el código del equipo.</p></div> <!> <section class="card p-6"><form class="flex gap-2"><input class="input font-mono" placeholder="Código del equipo (ej. POR-0001)" aria-label="Código del equipo"/> <button class="btn-primary shrink-0" type="submit">Buscar</button></form> <p class="mt-2 text-xs text-slate-500">Un lector USB también funciona aquí: apunta y dispara, se rellena solo.</p></section> <section class="card mt-4 p-6"><div class="flex items-center justify-between"><h2 class="font-semibold text-slate-900">Cámara</h2> <!></div> <!> <!></section></div>');function Be(y,a){ee(a,!0);let c=_(""),l=_(!1),o=_(null),v=_(null),D=null,f=null;function h(e){const t=me(e),r=(t==null?void 0:t.code)??e.trim();r&&de(`/scan?code=${encodeURIComponent(r)}`,{invalidateAll:!0})}function M(e){e.preventDefault(),s(c).trim()&&h(s(c))}async function L(){m(o,null);try{const{BrowserMultiFormatReader:e}=await J(async()=>{const{BrowserMultiFormatReader:t}=await import("../chunks/DD9CTm96.js");return{BrowserMultiFormatReader:t}},[],import.meta.url);D=new e,m(l,!0),await Promise.resolve(),f=await D.decodeFromVideoDevice(void 0,s(v),t=>{t&&(w(),h(t.getText()))})}catch(e){m(o,"No se pudo acceder a la cámara. Comprueba los permisos del navegador o usa el lector USB / la entrada manual."),m(l,!1),console.error(e)}}function w(){f==null||f.stop(),f=null,m(l,!1)}let b="",C=null;function T(e){const t=e.target;if(!(t&&(t.tagName==="INPUT"||t.tagName==="TEXTAREA"))){if(e.key==="Enter"){b.length>=3&&h(b),b="";return}e.key.length===1&&(b+=e.key,C&&clearTimeout(C),C=setTimeout(()=>b="",300))}}Y(()=>{window.addEventListener("keydown",T)}),Z(()=>{typeof window<"u"&&window.removeEventListener("keydown",T),w()});var E=xe();ie("19hdok6",e=>{re(()=>{se.title="Escanear · Inventario EDUmind"})});var A=u(n(E),2);{var S=e=>{var t=pe(),r=u(n(t)),B=n(r,!0);i(r),g(),i(t),N(()=>P(B,a.data.notFoundCode)),d(e,t)};x(A,e=>{a.data.notFoundCode&&e(S)})}var k=u(A,2),R=n(k),U=n(R);le(U),te(U),g(2),i(R),g(2),i(k);var F=u(k,2),q=n(F),O=u(n(q),2);{var Q=e=>{var t=ve();j("click",t,w),d(e,t)},V=e=>{var t=fe();j("click",t,L),d(e,t)};x(O,e=>{s(l)?e(Q):e(V,-1)})}i(q);var I=u(q,2);{var X=e=>{var t=be(),r=n(t,!0);i(t),N(()=>P(r,s(o))),d(e,t)};x(I,e=>{s(o)&&e(X)})}var z=u(I,2);{var K=e=>{var t=ge(),r=ne(t),B=n(r);H(B,G=>m(v,G),()=>s(v)),i(r),g(2),d(e,t)},W=e=>{var t=_e();d(e,t)};x(z,e=>{s(l)?e(K):e(W,-1)})}i(F),i(E),ae("submit",R,M),ce(U,()=>s(c),e=>m(c,e)),d(y,E),oe()}$(["click"]);export{Be as component};
