1import{a as w,j as t}from"./react-vendor-Cr2t-8qL.js";import{u as _}from"./query-vendor-84h9mXBw.js";import{u as L,L as E}from"./router-vendor-y7cRrtaC.js";import{B as b,a as B,g as U}from"./index-XWHW1WUH.js";import{d as $}from"./rapidSaleUtils-BuVDvx3n.js";import{m as R,n as T,D as I}from"./icons-vendor-LBcSlOvB.js";import"./pdf-vendor-g9Gz2X9y.js";import"./charts-vendor-CsIgoOPm.js";const P=o=>new Promise((s,m)=>{const n=new Image;n.onload=()=>s(n),n.onerror=()=>m(new Error("No se pudo cargar la imagen del boleto")),n.src=o});async function q(o=[]){const s=[];for(const a of o)a&&s.push(await P(a));if(!s.length)throw new Error("No hay boletos para descargar");const m=48,n=32,i=Math.max(...s.map(a=>a.width))+m*2,h=s.reduce((a,d)=>a+d.height,0)+m*2+n*(s.length-1),l=document.createElement("canvas");l.width=i,l.height=h;const c=l.getContext("2d");c.fillStyle="#f8fafc",c.fillRect(0,0,i,h);let x=m;return s.forEach(a=>{const d=Math.round((i-a.width)/2);c.drawImage(a,d,x),x+=a.height+n}),new Promise((a,d)=>{l.toBlob(p=>{p?a(p):d(new Error("No se pudo generar el paquete"))},"image/jpeg",.95)})}function Q(){var k,N,y,v;const{token:o=""}=L(),{data:s,isLoading:m,error:n}=_({queryKey:["public-ticket-bundle",o],queryFn:async()=>{var r,u;const e=await B.functions.invoke("getPublicTicketBundleByToken",{token:o});if(!((u=(r=e==null?void 0:e.data)==null?void 0:r.tickets)!=null&&u.length))throw new Error("ticket_link_not_found");return e.data},enabled:!!o,staleTime:1/0,retry:!1,gcTime:0}),{data:i,isLoading:h,error:l}=_({queryKey:["public-ticket-bundle-assets",o],queryFn:async()=>{const e=[];for(const r of s.tickets){if(!(r!=null&&r.asset_ready))throw new Error("ticket_asset_unavailable");const u=await fetch(`${U()}/functions/getProtectedTicketAsset?token=${encodeURIComponent(o)}&index=${encodeURIComponent(r.asset_index)}`,{method:"GET",credentials:"omit"});if(!u.ok){let g="ticket_asset_error";try{const f=await u.json();g=(f==null?void 0:f.error)||g}catch{}throw new Error(g)}e.push(await u.blob())}return e},enabled:!!((k=s==null?void 0:s.tickets)!=null&&k.length)&&!!((N=s==null?void 0:s.tempLink)!=null&&N.protected_assets),staleTime:1/0,retry:!1,gcTime:0}),[c,x]=w.useState([]),[a,d]=w.useState(!1),p=o?(n==null?void 0:n.message)||"":"ticket_link_not_found",j=(l==null?void 0:l.message)||"";w.useEffect(()=>{if(!(i!=null&&i.length)){x([]);return}const e=i.map(r=>URL.createObjectURL(r));return x(e),()=>e.forEach(r=>{try{URL.revokeObjectURL(r)}catch{}})},[i]);const C=async()=>{if(c.length){d(!0);try{const e=await q(c);$(e,`waccess-boletos-${c.length}.jpg`)}catch(e){setAssetErrorCode(String((e==null?void 0:e.message)||"ticket_asset_error").trim()||"ticket_asset_error")}finally{d(!1)}}};if(m)return t.jsx("div",{className:"min-h-screen bg-slate-950 flex items-center justify-center",children:t.jsx(R,{className:"h-8 w-8 animate-spin text-slate-300"})});if(p||!((y=s==null?void 0:s.tickets)!=null&&y.length)){const e=p==="ticket_link_expired";return t.jsx("div",{className:"min-h-screen bg-slate-950 flex items-center justify-center p-6",children:t.jsxs("div",{className:"max-w-md text-center",children:[t.jsx(T,{className:`h-12 w-12 mx-auto mb-3 ${e?"text-amber-400":"text-red-400"}`}),t.jsx("p",{className:"text-white font-medium",children:e?"Este acceso expiró por seguridad. Tu boleto sigue siendo válido. Recupéralo en segundos.":"Este acceso no es válido o ya no está disponible."}),t.jsx(b,{asChild:!0,className:"mt-5 w-full",children:t.jsx(E,{to:"/recuperar-boleto",children:"Recuperar boleto"})})]})})}if(j){const e=j==="ticket_link_expired";return t.jsx("div",{className:"min-h-screen bg-slate-950 flex items-center justify-center p-6",children:t.jsxs("div",{className:"max-w-md text-center",children:[t.jsx(T,{className:`h-12 w-12 mx-auto mb-3 ${e?"text-amber-400":"text-slate-300"}`}),t.jsx("p",{className:"text-white font-medium",children:e?"Este acceso expiró por seguridad. Tu boleto sigue siendo válido. Recupéralo en segundos.":"No se pudieron cargar tus boletos por ahora. Intenta nuevamente en unos minutos."}),t.jsx(b,{asChild:!0,className:"mt-5 w-full",children:t.jsx(E,{to:"/recuperar-boleto",children:"Recuperar boleto"})})]})})}return t.jsx("div",{className:"min-h-screen bg-slate-950 py-8 px-4",children:t.jsxs("div",{className:"max-w-5xl mx-auto
1space-y-4",children:[t.jsxs("div",{className:"rounded-3xl border border-white/10 bg-white/5 p-4 text-white",children:[t.jsx("p",{className:"text-sm text-slate-300",children:((v=s==null?void 0:s.event)==null?void 0:v.name)||"Tus boletos"}),t.jsxs("p",{className:"mt-1 text-lg font-semibold",children:[s.tickets.length," boletos protegidos"]})]}),t.jsxs(b,{onClick:C,disabled:h||a||!c.length,children:[t.jsx(I,{className:"h-4 w-4 mr-2"}),a?"Preparando descarga...":"Descargar grupo"]}),t.jsx("div",{className:"space-y-6",children:h?t.jsx("div",{className:"flex min-h-[320px] items-center justify-center",children:t.jsx(R,{className:"h-8 w-8 animate-spin text-slate-300"})}):s.tickets.map((e,r)=>t.jsx("div",{className:"overflow-hidden rounded-[28px] border border-slate-200 bg-white shadow-2xl",children:t.jsx("img",{src:c[r]||e.pdf_url,alt:`Boleto ${e.ticket_number||r+1}`,className:"block w-full"})},`${e.ticket_number||r}-${r}`))})]})})}export{Q as default};
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.