1import{a as c,j as e}from"./react-vendor-Cr2t-8qL.js";import{a as rs,u as qe,b as ue}from"./query-vendor-84h9mXBw.js";import{t as F,a as q,B as W}from"./index-XWHW1WUH.js";import{o as X,b as ls}from"./whatsappSalesUtils-B9CLI8Sp.js";import{i as He,n as ae}from"./rapidSaleUtils-BuVDvx3n.js";import{g as xe,a as Re}from"./getCloudflareTicketUrl-C75rJ8l9.js";import{z as os,m as D,E as is,F as le,e as pe,D as cs,J as ds,P as ms,K as xs,N as Ve,O as We,d as us,V as ps,Y as hs,T as ze,M as bs}from"./icons-vendor-LBcSlOvB.js";import"./pdf-vendor-g9Gz2X9y.js";import"./charts-vendor-CsIgoOPm.js";import"./router-vendor-y7cRrtaC.js";function fs({holds:o,onLoad:_,onCancel:l,cancellingId:p}){return!o||o.length===0?null:e.jsxs("div",{className:"rounded-[28px] bg-amber-50 border border-amber-200 p-5 shadow-sm space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-flex h-2 w-2 rounded-full bg-amber-400 animate-pulse"}),e.jsxs("h2",{className:"font-semibold text-amber-900 text-sm",children:["Selecciones pendientes del mapa (",o.length,")"]})]}),e.jsx("div",{className:"space-y-2",children:o.map(x=>{const j=x.seats.reduce((n,i)=>n+Number(i.price||0),0),C=x.seats.map(n=>n.label).join(", "),h=p===x.id;return e.jsxs("div",{className:"rounded-2xl bg-white border border-amber-100 p-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-xs font-semibold text-slate-800 truncate",children:C||"Sin etiqueta"}),j>0&&e.jsxs("p",{className:"text-xs text-slate-500",children:["$",j.toFixed(2)," · ",x.seats.length," asiento",x.seats.length!==1?"s":""]}),x.customer_name&&!x.customer_name.startsWith("Cliente")&&e.jsxs("p",{className:"text-[10px] text-slate-400 mt-0.5",children:[x.customer_name,x.customer_phone?` · ${x.customer_phone}`:""]}),e.jsxs("p",{className:"text-[10px] text-amber-500 mt-0.5",children:["Expira en: ",e.jsx(gs,{expiresAt:x.expires_at})]})]}),e.jsxs("div",{className:"flex gap-1.5 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>_(x),className:"rounded-xl bg-[#F26A4B] text-white text-xs font-semibold px-3 py-1.5 hover:bg-[#d9543a] transition-colors",children:"Usar"}),e.jsx("button",{type:"button",onClick:()=>l(x.id),disabled:h,className:"rounded-xl bg-slate-100 text-slate-600 text-xs font-semibold px-3 py-1.5 hover:bg-red-50 hover:text-red-600 transition-colors disabled:opacity-50",children:h?e.jsx(D,{className:"h-3 w-3 animate-spin"}):"Cancelar"})]})]},x.id)})})]})}function gs({expiresAt:o}){const[_,l]=c.useState("");return c.useEffect(()=>{const p=()=>{const j=Math.max(0,Math.floor((new Date(o)-Date.now())/1e3));if(j<=0){l("Expirado");return}const C=Math.floor(j/60),h=j%60;l(C>0?`${C}m ${h}s`:`${h}s`)};p();const x=setInterval(p,1e3);return()=>clearInterval(x)},[o]),e.jsx("span",{children:_})}function js({sections:o,seats:_,selectedSeats:l,setSelectedSeats:p,defaultPrice:x,activeSectionId:j,setActiveSectionId:C,quantity:h,setQuantity:n,activeSection:i}){const E=c.useMemo(()=>{const r={};for(const y of _){const v=y.section_id??"none";r[v]||(r[v]=[]),r[v].push(y)}return r},[_]),N=new Set(l.map(r=>r.id)),I=r=>{N.has(r.id)?p(y=>y.filter(v=>v.id!==r.id)):p(y=>[...y,r])},b=E[j]||E.none||[],O=!!(i!=null&&i.is_general);return!o.length&&!_.length?e.jsx("div",{className:"rounded-[28px] bg-white border border-slate-200 p-5 shadow-sm",children:e.jsx("p",{className:"text-sm text-slate-500",children:"No hay asientos disponibles para este evento."})}):e.jsxs("div",{className:"rounded-[28px] bg-white border border-slate-200 p-5 shadow-sm space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(bs,{className:"h-4 w-4 text-[#F26A4B]"}),e.jsx("h2",{className:"font-semibold text-slate-900",children:O?"Boletos generales":"Selecciona asientos"})]}),o.length>1&&e.jsx("div",{className:"flex gap-2 flex-wrap",children:o.map(r=>e.jsx("button",{type:"button",onClick:()=>C(r.id),className:`rounded-full px-3 py-1 text-xs font-semibold border transition-colors ${j===r.id?"border-[#F26A4B] bg-[#FFF4F0] text-[#F26A4B]":"border-slate-200 bg-slate-50 text-slate-600 hover:border-slate-300"}`,children:r.name},r.id))}),O?e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 uppercase tracking-wide",children:"Cantidad de boletos"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>n(r=>Math.max(1,r-1)),className:"h-12 w-12 rounded-2xl border border-slate-200 flex items-center justify-center hover:bg-slate-100 shrink-0",children:e.jsx(Ve,{className:"h-5 w-5"})}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:(i==null?void 0:i.available)??200,value:h,onChange:r=>{const y=(i==null?void 0:i.available)??200,v=Math.max(1,Math.min(y,Number(r.target.value)||1));n(v)},className:"flex-1 h-12 rounded-2xl border border-slate-200 text-center text-2xl font-bold focus:outline-none focus:ring-2 focus:ring-[#F26A4B]/40"}),e.jsx("button",{type:"button",onClick:()=>{const r=(i==null?void 0:i.available)??200;n(y=>Math.min(r,y+1))},className:"h-12 w-12 rounded-2xl border border-slate-200 flex items-center justify-center hover:bg-slate-100 shrink-0",children:e.jsx(We,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-slate-400",children:[(i==null?void 0:i.available)!=null&&e.jsxs("span",{children:["Disponibles: ",e.jsx("span",{className:"font-semibold text-slate-600",children:i.available})]}),(i==null?void 0:i.price)>0&&e.jsxs("span",{className:"ml-auto",children:["$",Number(i.price).toFixed(2)," c/u"]})]})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[b.map(r=>{const y=N.has(r.id),v=r.price!=null?r.price:x;return e.jsxs("button",{type:"button",onClick:()=>I(r),className:`rounded-xl border p-2 text-center text-xs font-semibold transition-colors ${y?"border-[#F26A4B] bg-[#F26A4B] text-white":"border-slate-200 bg-slate-50 text-slate-700 hover:border-[#F26A4B] hover:bg-[#FFF4F0]"}`,children:[e.jsx("span",{className:"block truncate",children:r.label}),v>0&&e.jsxs("span",{className:"block text-[10px] opacity-80",children:["$",v]})]},r.id)}),b.length===0&&e.jsx("p",{className:"col-span-4 text-sm text-slate-400 py-2",children:"Sin asientos disponibles en esta sección."})]}),l.length>0&&e.jsxs("div",{className:"rounded-2xl bg-[#FFF4F0] border border-[#F6C1B4] px-4 py-3 space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm text-slate-600",children:[l.length," asiento",l.length!==1?"s":""," seleccionado",l.length!==1?"s":""]}),e.jsx("button",{type:"button",onClick:()=>p([]),className:"text-xs text-slate-400 hover:text-red-500",children:"Limpiar"})]}),e.jsx("p",{className:"text-xs text-slate-500 truncate",children:l.map(r=>r.label).join(", ")})]})]})]})}function Q({eventName:o,sellerName:_}){return e.jsxs("div",{className:"sticky top-0 z-40 bg-white border-b border-slate-100 shadow-sm",children:[e.jsxs("div",{className:"px-4 py-3 flex items-center gap-3",children:[e.jsx("a",{href:"/eventos",className:"shrink-0 flex items-center justify-center h-8 w-8 rounded-full hover:bg-slate-100 transition-colors",title:"Regresar a eventos",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 text-slate-500",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}),e.jsx("img",{src:"/Logo-web.png",alt:"Waccess",className:"h-8 w-auto object-contain shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-[#F26A4B]/10 px-2.5 py-0.5 text-xs font-semibold text-[#F26A4B] uppercase tracking-wide",children:[e.jsx(ze,{className:"h-3 w-3"}),"Módulo de ventas"]}),o&&e.jsx("p",{className:"mt-0.5 text-sm font-semibold text-slate-800 truncate",children:o})]})]}),_&&e.jsx("div",{className:"px-4 pb-2",children:e.jsxs("p",{className:"text-xs text-slate-400",children:["Vendedor: ",e.jsx("span",{className:"font-medium text-slate-600",children:_})]})})]})}function G(){return e.jsxs("footer",{className:"mt-10 border-t border-slate-100 bg-white py-6 px-4 text-center",children:[e.jsx("img",{src:"/Logo-web.png",alt:"Waccess",className:"mx-auto h-7 w-auto object-contain opacity-50"}),e.jsx("p",{className:"mt-2 text-xs text-slate-400",children:"Plataforma de venta y gestión de boletos"}),e.jsx("p",{className:"text-xs text-slate-300 mt-0.5",children:"waccess.net"})]})}function Ns({salesData:o,isLoading:_,onRefresh:l,token:p,activePin:x}
1){const j=ue({mutationFn:async({ticketIds:n,buyerEmail:i,buyerName:E})=>{var I,b;if(!(n!=null&&n.length))throw new Error("Sin boletos");const N=await q.functions.invoke("sendSellerTicketEmails",{token:p,ticketIds:n,buyerEmail:i,buyerName:E});if(!((I=N.data)!=null&&I.success))throw new Error(((b=N.data)==null?void 0:b.error)||"Error al enviar");return N.data},onSuccess:()=>F.success("Boleto enviado al correo del comprador"),onError:n=>F.error(n.message||"No se pudo enviar el correo")});if(_)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(D,{className:"h-8 w-8 animate-spin text-[#F26A4B]"})});const C=(o==null?void 0:o.sales)||[];if(!C.length)return e.jsxs("div",{className:"rounded-[28px] bg-white border border-slate-200 p-8 text-center space-y-3 shadow-sm",children:[e.jsx(ze,{className:"h-10 w-10 text-slate-200 mx-auto"}),e.jsx("p",{className:"text-sm text-slate-500",children:"Aún no has registrado ventas"}),e.jsx("button",{type:"button",onClick:l,className:"text-xs text-[#F26A4B] font-medium hover:underline",children:"Actualizar"})]});const h=n=>{if(!n)return"";try{return new Date(n).toLocaleDateString("es-MX",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return n}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between px-1",children:[e.jsxs("p",{className:"text-xs text-slate-500",children:[o==null?void 0:o.total_sold," boleto",(o==null?void 0:o.total_sold)!==1?"s":""," vendido",(o==null?void 0:o.total_sold)!==1?"s":""]}),e.jsx("button",{type:"button",onClick:l,className:"text-xs text-[#F26A4B] font-medium hover:underline",children:"Actualizar"})]}),C.map((n,i)=>{const E=n.tickets.map(N=>N.id).filter(Boolean);return e.jsxs("div",{className:"rounded-[28px] bg-white border border-slate-200 p-4 shadow-sm space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-slate-900 text-sm truncate",children:n.buyer_name||"Sin nombre"}),n.buyer_phone&&e.jsx("p",{className:"text-xs text-slate-500",children:n.buyer_phone}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:h(n.sold_at)})]}),e.jsxs("div",{className:"text-right shrink-0",children:[n.total>0&&e.jsxs("p",{className:"font-bold text-slate-900 text-sm",children:["$",n.total.toFixed(2)]}),e.jsxs("p",{className:"text-xs text-slate-400",children:[n.tickets.length," boleto",n.tickets.length!==1?"s":""]}),n.payment_method&&e.jsx("p",{className:"text-[10px] text-slate-400",children:n.payment_method})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[n.buyer_phone&&e.jsxs("button",{type:"button",onClick:()=>{var b;const N=n.buyer_phone.replace(/\D/g,""),I=n.tickets.length>1?`https://waccess.net/boletos?ids=${E.join(",")}&event=${encodeURIComponent(n.event_name||"")}`:((b=n.tickets[0])==null?void 0:b.pdf_url)||`https://waccess.net/boleto/${E[0]}`;X(N.length===10?`52${N}`:N,`Hola ${n.buyer_name||""}, aquà está tu boleto para *${n.event_name||"el evento"}*: 2${I}`)},className:"rounded-xl bg-[#25D366] text-white text-xs font-semibold px-3 py-1.5 hover:bg-[#1ebe5a] transition-colors flex items-center gap-1",children:[e.jsx(le,{className:"h-3 w-3"})," WhatsApp"]}),n.buyer_email&&e.jsxs("button",{type:"button",onClick:()=>j.mutate({ticketIds:E,buyerEmail:n.buyer_email,buyerName:n.buyer_name}),disabled:j.isPending,className:"rounded-xl bg-slate-100 text-slate-700 text-xs font-semibold px-3 py-1.5 hover:bg-slate-200 transition-colors flex items-center gap-1 disabled:opacity-50",children:[e.jsx(pe,{className:"h-3 w-3"})," Reenviar correo"]})]})]},n.order_id||i)})]})}function Ss(){var Fe,Ce,Ee,$e,Pe,Ae,Se,Be,Me,Ie,Le,Te;const o=rs(),l=new URLSearchParams(window.location.search).get("token")||"",[p,x]=c.useState(()=>{try{return sessionStorage.getItem(`seller_pin_${l}`)||""}catch{return""}}),[j,C]=c.useState(!1),[h,n]=c.useState(""),[i,E]=c.useState(""),[N,I]=c.useState(!1),[b,O]=c.useState(""),[r,y]=c.useState(""),[v,oe]=c.useState(""),[H,ie]=c.useState(""),[w,z]=c.useState(1),[k,ce]=c.useState(null),[he,Y]=c.useState(null),[$,be]=c.useState(""),[S,Z]=c.useState([]),[fe,ge]=c.useState("Efectivo"),[ee,je]=c.useState("nueva"),[Ue,Ne]=c.useState(null),[de,me]=c.useState(null),[B,ne]=c.useState(null),[ye,ve]=c.useState(!1),{data:t,isLoading:Ke,error:R}=qe({queryKey:["seller-invite-access",l,p,$],enabled:!!l&&!j,retry:!1,refetchInterval:20*1e3,queryFn:async()=>(await q.functions.invoke("getSellerInviteAccess",{token:l,pin:p,...$?{event_id:$}:{}})).data,staleTime:0});c.useEffect(()=>{const s=String((R==null?void 0:R.message)||"");if((s==="PIN_REQUIRED"||s==="PIN incorrecto")&&(C(!0),s==="PIN incorrecto")){try{
2sessionStorage.removeItem(`seller_pin_${l}`)}catch{}x("")}},[R,l]),c.useEffect(()=>{ie(""),Z([]),me(null),z(1)},[$]),c.useEffect(()=>{var s;(s=t==null?void 0:t.seatSections)!=null&&s.length&&me(a=>a??t.seatSections[0].id)},[t==null?void 0:t.seatSections]),c.useEffect(()=>{Z([]),z(1)},[de]),c.useEffect(()=>{var s;(s=t==null?void 0:t.ticketTypes)!=null&&s.length&&!H&&ie(t.ticketTypes[0].id)},[t==null?void 0:t.ticketTypes,H]);const M=!!((Fe=t==null?void 0:t.event)!=null&&Fe.has_seat_map),u=((t==null?void 0:t.seatSections)||[]).find(s=>s.id===de)||((Ce=t==null?void 0:t.seatSections)==null?void 0:Ce[0])||null,J=M&&!!(u!=null&&u.is_general),L=((t==null?void 0:t.ticketTypes)||[]).find(s=>s.id===H)||null,Qe=S.reduce((s,a)=>s+(a.price!=null?a.price:(L==null?void 0:L.price)||0),0),U=J?Number((u==null?void 0:u.price)||(L==null?void 0:L.price)||0)*w:M?Qe:Number((L==null?void 0:L.price)||0)*w,re=!!(b.trim()&&He(r)&&(J?u!=null&&u.ticket_type_id&&w>0&&((u==null?void 0:u.available)==null||w<=u.available):M?S.length>0:H&&w>0)),se=ue({mutationFn:async()=>{var T,V,A,g,P;const s=ae(r.trim());if(!s)throw new Error("El teléfono no es válido. Debe tener 10 dÃgitos.");const a=`${l}-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,m=J?{ticket_type_id:u.ticket_type_id,quantity:w}:M?{ticket_type_id:((T=S[0])==null?void 0:T.ticket_type_id)||((A=(V=t==null?void 0:t.ticketTypes)==null?void 0:V[0])==null?void 0:A.id)||"",quantity:S.length,seat_ids:S.map(K=>K.id)}:{ticket_type_id:H,quantity:w},d={token:l,...$?{event_id:$}:{},buyer_name:b.trim(),buyer_phone:s,buyer_email:v.trim(),payment_method:fe,request_id:a,...m};console.log("[VendedorAccess] Submitting sale",{hasSeatMap:M,selectedSeats:S.map(K=>({id:K.id,label:K.label})),ticket_type_id:d.ticket_type_id,quantity:d.quantity,buyer_name:d.buyer_name,buyer_phone:d.buyer_phone});const f=await q.functions.invoke("createSellerSale",d);if(console.log("[VendedorAccess] Response",f),!((g=f.data)!=null&&g.success))throw new Error(((P=f.data)==null?void 0:P.error)||"No se pudo completar la venta.");return f.data},onSuccess:s=>{var V,A;Y(null);const a={tickets:s.tickets,total:U,buyer_name:b.trim(),buyer_phone:ae(r.trim()),buyer_email:v.trim(),event_name:s.event_name||((V=t==null?void 0:t.event)==null?void 0:V.name)||"Waccess"};ce(a),F.success("¡Venta completada!"),o.invalidateQueries({queryKey:["seller-invite-access"]});const{tickets:m,buyer_name:d,buyer_phone:f,event_name:T}=a;if(m!=null&&m.length&&f){let g,P;m.length===1?(g=xe(m[0]),P=`Hola ${d}, aquà está tu boleto para *${T}*: 3${g}`):(g=Re(m,T),P=`Hola ${d}, aquà están tus ${m.length} boletos para *${T}*: 4${g}`),X(f,P)}if(a.buyer_email&&((A=s.tickets)!=null&&A.length)){const g=s.tickets.map(P=>P.id).filter(Boolean);g.length&&q.functions.invoke("sendSellerTicketEmails",{token:l,ticketIds:g,buyerEmail:a.buyer_email,buyerName:a.buyer_name}).catch(()=>{})}},onError:s=>{const a=s.message||"No se pudo completar la venta.";console.error("[VendedorAccess] Sale error:",s),Y(a),F.error(a)}}),Ge=()=>{if(!k)return;const{tickets:s,buyer_name:a,buyer_phone:m,event_name:d}=k;let f;s.length===1?(f=xe(s[0]),X(m,`Hola ${a}, aquà está tu boleto para *${d}*: 5${f}`)):(f=Re(s,d),X(m,`Hola ${a}, aquà están tus ${s.length} boletos para *${d}*: 6${f}`))},Xe=()=>{k&&k.tickets.forEach(s=>window.open(xe(s),"_blank"))},De=async()=>{var a,m,d,f,T,V;if(!re){F.error("Completa nombre, teléfono y selección antes de generar el link.");return}const s=ae(r.trim());if(!s){F.error("Teléfono inválido. Debe tener 10 dÃgitos.");return}ve(!0),Y(null);try{const A=J?{ticket_type_id:u.ticket_type_id,quantity:w}:M?{ticket_type_id:((a=S[0])==null?void 0:a.ticket_type_id)||((d=(m=t==null?void 0:t.ticketTypes)==null?void 0:m[0])==null?void 0:d.id)||"",quantity:S.length,seat_ids:S.map(ns=>ns.id)}:{ticket_type_id:H,quantity:w},g=await q.functions.invoke("createSellerPaymentLink",{token:l,...$?{event_id:$}:{},buyer_name:b.trim(),buyer_phone:s,buyer_email:v.trim()||null,...A});if(!((f=g.data)!=null&&f.success))throw new Error(((T=g.data)==null?void 0:T.error)||"No se pudo generar el link.");const P=String(g.data.order_id||"").trim();if(!P)throw new Error("No se recibió order_id del servidor.");const K=`${window.location.origin}/pago/${P}`;ne({order_id:P,url:K,copied:!1}),F.success("Link de pago Mercado Pago generado");const ts=((V=t==null?void 0:t.event)==null?void 0:V.name)||"el evento",as=`Hola ${b.trim()}, aquà tienes tu link de pago para *${ts}*: 7 8${K} 9 10Paga con tarjeta, OXXO o SPEI. El link expira pronto.`;X(s,as),o.invalidateQueries({queryKey:["seller-invite-access"]})}catch(A){const g=(A==null?void 0:A.message)||"No se pudo generar el link";Y(g),F.error(g)}finally{ve(!1)}},Oe=()=>{B!=null&&B.url&&navigator.clipboard.writeText(B.url).then(()=>{ne(s=>s&&{...s,copied:!0}),F.success("Link copiado"),setTimeout(()=>ne(s=>s&&{...s,copied:!1}),3e3)})},te=ue({mutationFn:async()=>{var m,d;if(!(k!=null&&k.buyer_email))throw new Error("No hay correo registrado para este comprador");const s=k.tickets.map(f=>
10f.id).filter(Boolean);if(!s.length)throw new Error("No se encontraron los boletos");const a=await q.functions.invoke("sendSellerTicketEmails",{token:l,ticketIds:s,buyerEmail:k.buyer_email,buyerName:k.buyer_name});if(!((m=a.data)!=null&&m.success))throw new Error(((d=a.data)==null?void 0:d.error)||"Error al enviar correo");return a.data},onSuccess:()=>F.success("Boleto enviado al correo del comprador"),onError:s=>F.error(s.message||"No se pudo enviar el correo")}),Je=()=>{ce(null),O(""),y(""),oe(""),z(1),Z([]),ge("Efectivo"),ne(null),o.invalidateQueries({queryKey:["seller-invite-access"]})},Ye=s=>{Z(s.seats.map(a=>({id:a.id,label:a.label,section_id:a.section_id,price:a.price}))),s.customer_name&&!s.customer_name.startsWith("Cliente")&&O(s.customer_name),s.customer_phone&&y(s.customer_phone),s.customer_email&&oe(s.customer_email),window.scrollTo({top:0,behavior:"smooth"})},Ze=async s=>{var a,m;Ne(s);try{const d=await q.functions.invoke("cancelSellerHold",{token:l,pin:p,reservation_id:s});if(!((a=d.data)!=null&&a.success))throw new Error(((m=d.data)==null?void 0:m.error)||"Error al cancelar");F.success("Reserva cancelada"),o.invalidateQueries({queryKey:["seller-invite-access"]})}catch(d){F.error(d.message||"No se pudo cancelar la reserva")}finally{Ne(null)}},{data:es,isLoading:ss,refetch:we}=qe({queryKey:["seller-sales",l,p,$],enabled:ee==="ventas"&&!!l&&!j,retry:!1,queryFn:async()=>(await q.functions.invoke("listSellerSales",{token:l,pin:p,...$?{event_id:$}:{}})).data}),ke=async()=>{var s;if(!(h.length<4||N)){E(""),I(!0);try{const a=await q.functions.invoke("getSellerInviteAccess",{token:l,pin:h});if(!((s=a.data)!=null&&s.invite))throw new Error("PIN incorrecto");o.setQueryData(["seller-invite-access",l,h,""],a.data);try{sessionStorage.setItem(`seller_pin_${l}`,h)}catch{}x(h),C(!1)}catch(a){E(String((a==null?void 0:a.message)||"PIN incorrecto"))}finally{I(!1)}}};if(j)return e.jsxs("div",{className:"min-h-screen bg-slate-50 flex flex-col",children:[e.jsx(Q,{}),e.jsx("div",{className:"flex-1 flex items-center justify-center p-6",children:e.jsxs("div",{className:"rounded-[28px] border border-slate-200 bg-white p-8 max-w-xs w-full shadow-sm space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"mx-auto mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-[#F26A4B]/10",children:e.jsx(os,{className:"h-6 w-6 text-[#F26A4B]"})}),e.jsx("p",{className:"text-lg font-bold text-slate-900",children:"Acceso de vendedor"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Ingresa tu PIN para continuar"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{type:"text",inputMode:"numeric",maxLength:4,value:h,onChange:s=>{n(s.target.value.replace(/\D/g,"")),E("")},onKeyDown:s=>s.key==="Enter"&&ke(),placeholder:"â¢â¢â¢â¢",autoFocus:!0,className:"w-full text-center text-3xl font-bold tracking-[0.5em] rounded-2xl border border-slate-200 py-4 focus:outline-none focus:ring-2 focus:ring-[#F26A4B]/40"}),i&&e.jsx("p",{className:"text-sm text-center text-red-500 font-medium",children:i}),e.jsx(W,{className:"w-full h-12 rounded-2xl bg-[#F26A4B] hover:bg-[#d9543a] text-white font-semibold",onClick:ke,disabled:h.length<4||N,children:N?e.jsx(D,{className:"h-4 w-4 animate-spin"}):"Ingresar"})]}),e.jsxs("p",{className:"text-center text-xs text-slate-400",children:["Recibe tu PIN del organizador del evento.",e.jsx("br",{}),"Solo podrás registrar ventas de boletos."]})]})}),e.jsx(G,{})]});if(!l)return e.jsxs("div",{className:"min-h-screen bg-slate-50 flex flex-col",children:[e.jsx(Q,{}),e.jsx("div",{className:"flex-1 flex items-center justify-center p-6",children:e.jsxs("div",{className:"rounded-3xl border border-slate-200 bg-white p-8 text-center max-w-sm w-full shadow-sm",children:[e.jsx("p",{className:"text-lg font-semibold text-slate-900",children:"Acceso no válido"}),e.jsx("p",{className:"mt-2 text-sm text-slate-500",children:"Este enlace de vendedor no tiene token. Solicita un nuevo acceso a tu organizador."})]})}),e.jsx(G,{})]});if(Ke)return e.jsxs("div",{className:"min-h-screen bg-slate-50 flex flex-col",children:[e.jsx(Q,{}),e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx(D,{className:"h-10 w-10 animate-spin text-[#F26A4B] mx-auto"}),e.jsx("p",{className:"text-sm text-slate-400",children:"Cargando módulo de ventas..."})]})}),e.jsx(G,{})]});if(R||!(t!=null&&t.invite))return e.jsxs("div",{className:"min-h-screen bg-slate-50 flex flex-col",children:[e.jsx(Q,{}),e.jsx("div",{className:"flex-1 flex items-center justify-center p-6",children:e.jsxs("div",{className:"rounded-3xl border border-slate-200 bg-white p-8 text-center max-w-sm w-full shadow-sm",children:[e.jsx("p",{className:"text-lg font-semibold text-slate-900",children:"Acceso de vendedor no disponible"}),e.jsx("p",{className:"mt-2 text-sm text-slate-500",children:(R==null?void 0:R.message)||"Este enlace ha expirado o fue desactivado. Solicita acceso al organizador."})]})}),e.jsx(G,{})]});const _e=(((Ee=t==null?void 0:t.events)==null?void 0:Ee.length)||0)>1;return t&&!(!_e||!!$)?e.jsxs("div",{className:"min-h-screen bg-slate-50 flex flex-col",children:[e.jsx(Q,{sellerName:($e=t.invite)==null?void 0:$e.seller_name}),e.jsxs("div",{className:"flex-1 px-4 py-8 max-w-md mx-auto w-full space-y-4",children:[e.jsxs("div",{className:"rounded-[28px] bg-white border border-slate-200 p-5 shadow-sm space-y-3",children:[e.jsx("h2",{className:"font-semibold text-slate-900",children:"Selecciona el evento"}),e.jsx("div",{className:"space-y-2",children:t.events.map(s=>e.jsxs("button",{type:"button",onClick:()=>be(s.id),className:"w-full rounded-2xl border border-slate-200 bg-slate-50 p-4 text-left hover:border-[#F26A4B] hover:bg-[#FFF4F0] transition-colors",children:[e.jsx("p",{className:"font-semibold text-slate-900",children:s.name}),s.date&&e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:new Date(s.date+"T12:00:00").toLocaleDateString("es-MX",{day:"2-digit",month:"long",year:"numeric"})}),s.venue_name&&e.jsx("p",{className:"text-xs text-slate-400",children:s.venue_name})]},s.id))})]}),e.jsx("a",{href:"/eventos",className:"block w-full text-center text-xs text-slate-400 hover:text-slate-600 py-2 transition-colors",children:"â Regresar a eventos"})]}),e.jsx(G,{})]}):k?e.jsxs("div",{className:"min-h-screen bg-slate-50 flex flex-col",children:[e.jsx(Q,{eventName:(Pe=t.event)==null?void 0:Pe.name,sellerName:(Ae=t.invite)==null?void 0:Ae.seller_name}),e.jsxs("div",{className:"flex-1 px-4 py-8 max-w-md mx-auto w-full space-y-4",children:[e.jsxs("div",{className:"rounded-[28px] bg-emerald-50 border border-emerald-200 p-6 text-center shadow-sm",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-full bg-emerald-100",children:e.jsx(is,{className:"h-7 w-7 text-emerald-600"})}),e.jsx("p",{className:"text-xl font-bold text-emerald-900",children:"¡Venta completada!"}),e.jsxs("p",{className:"mt-1 text-sm text-emerald-700",children:[k.tickets.length," boleto",k.tickets.length!==1?"s":""," para"," ",e.jsx("strong",{children:k.buyer_name})]}),U>0&&e.jsxs("p",{className:"mt-1 text-sm font-semibold text-emerald-800",children:["Total: $",U.toFixed(2)]})]}),e.jsxs("div",{className:"rounded-[28px] bg-white border border-slate-200 p-5 shadow-sm space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-widest text-slate-400",children:"Entregar boleto"}),e.jsxs(W,{className:"w-full h-12 rounded-2xl text-sm font-semibold bg-[#25D366] hover:bg-[#1ebe5a] text-white",onClick:Ge,children:[e.jsx(le,{className:"h-4 w-4 mr-2"}),"Enviar por WhatsApp"]}),k.buyer_email&&e.jsxs(W,{variant:"outline",className:"w-full h-12 rounded-2xl text-sm",onClick:()=>te.mutate(),disabled:te.isPending||te.isSuccess,children:[te.isPending?e.jsx(D,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(pe,{className:"h-4 w-4 mr-2"}),te.isSuccess?"Correo enviado â":"Enviar por correo"]}),e.jsxs(W,{variant:"outline",className:"w-full h-12 rounded-2xl text-sm",onClick:Xe,children:[e.jsx(cs,{className:"h-4 w-4 mr-2"}),"Ver / descargar boleto"]})]}),e.jsx(W,{variant:"ghost",className:"w-full h-12 rounded-2xl text-sm",onClick:Je,children:"+ Nueva venta"})," ",_e&&e.jsx("button",{type:"button",className:"w-full text-xs text-slate-400 hover:text-slate-600 py-2",onClick:()=>{ce(null),be("")},children:"Cambiar evento"}),e.jsx("a",{href:"/eventos",className:"block w-full text-center text-xs text-slate-400 hover:text-slate-600 py-2 transition-colors",children:"â Regresar a eventos"})]}),e.jsx(G,{})]}):e.jsxs("div",{className:"min-h-screen bg-slate-50 flex flex-col",children:[e.jsx(Q,{eventName:(Se=t.event)==null?void 0:Se.name,sellerName:(Be=t.invite)==null?void 0:Be.seller_name}),e.jsxs("div",{className:"flex-1 px-4 py-6 max-w-md mx-auto w-full space-y-4",children:[e.jsxs("div",{className:"flex rounded-2xl bg-slate-100 p-1 gap-1",children:[e.jsx("button",{type:"button",onClick:()=>
10je("nueva"),className:`flex-1 rounded-xl py-2 text-sm font-semibold transition-colors ${ee==="nueva"?"bg-white text-slate-900 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:"Nueva venta"}),e.jsxs("button",{type:"button",onClick:()=>{je("ventas"),we()},className:`flex-1 rounded-xl py-2 text-sm font-semibold transition-colors flex items-center justify-center gap-1.5 ${ee==="ventas"?"bg-white text-slate-900 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[e.jsx(ds,{className:"h-4 w-4"}),"Mis ventas"]})]}),ee==="ventas"&&e.jsx(Ns,{salesData:es,isLoading:ss,onRefresh:we,token:l,activePin:p}),ee==="nueva"&&e.jsxs(e.Fragment,{children:[M&&((Me=t.pendingHolds)==null?void 0:Me.length)>0&&e.jsx(fs,{holds:t.pendingHolds,onLoad:Ye,onCancel:Ze,cancellingId:Ue}),e.jsxs("div",{className:"rounded-[28px] bg-white border border-slate-200 p-5 shadow-sm space-y-4",children:[e.jsx("h2",{className:"font-semibold text-slate-900",children:"Datos del comprador"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 uppercase tracking-wide",children:"Teléfono *"}),e.jsxs("div",{className:"relative",children:[e.jsx(ms,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400"}),e.jsx("input",{type:"tel",inputMode:"numeric",value:r,onChange:s=>y(s.target.value),placeholder:"10 dÃgitos",className:"w-full rounded-2xl border border-slate-200 pl-10 pr-4 py-3 text-base focus:outline-none focus:ring-2 focus:ring-[#F26A4B]/40"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 uppercase tracking-wide",children:"Nombre *"}),e.jsxs("div",{className:"relative",children:[e.jsx(xs,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400"}),e.jsx("input",{type:"text",value:b,onChange:s=>O(s.target.value),placeholder:"Nombre completo",className:"w-full rounded-2xl border border-slate-200 pl-10 pr-4 py-3 text-base focus:outline-none focus:ring-2 focus:ring-[#F26A4B]/40"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 uppercase tracking-wide",children:"Correo (opcional)"}),e.jsxs("div",{className:"relative",children:[e.jsx(pe,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400"}),e.jsx("input",{type:"email",inputMode:"email",value:v,onChange:s=>oe(s.target.value),placeholder:"[email protected]",className:"w-full rounded-2xl border border-slate-200 pl-10 pr-4 py-3 text-base focus:outline-none focus:ring-2 focus:ring-[#F26A4B]/40"})]})]})]}),M&&He(r)&&e.jsxs(W,{type:"button",variant:"outline",className:"w-full h-12 rounded-2xl text-sm border-green-200 text-green-800 hover:bg-green-50",onClick:()=>{const s=`https://waccess.net/WhatsAppMapShare?eventId=${t.event.id}`,a=ae(r.trim()),m=ls({buyerName:b.trim()||void 0,eventName:t.event.name,mapUrl:s});X(`52${a}`,m)},children:[e.jsx(le,{className:"h-4 w-4 mr-2 text-green-600"}),"Enviar mapa al cliente por WhatsApp"]}),M?e.jsxs(e.Fragment,{children:[e.jsx(js,{sections:t.seatSections||[],seats:t.seats||[],selectedSeats:S,setSelectedSeats:Z,defaultPrice:((Le=(Ie=t.ticketTypes)==null?void 0:Ie[0])==null?void 0:Le.price)||0,activeSectionId:de,setActiveSectionId:me,quantity:w,setQuantity:z,activeSection:u}),J&&(u==null?void 0:u.ticket_type_id)&&e.jsxs("div",{className:"rounded-2xl bg-[#FFF4F0] border border-[#F6C1B4] px-4 py-3 flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm text-slate-600",children:[w," boleto",w!==1?"s":""]}),e.jsx("span",{className:"text-xl font-bold text-[#B94A30]",children:U>0?`$${U.toFixed(2)}`:"Gratis"})]})]}):e.jsxs("div",{className:"rounded-[28px] bg-white border border-slate-200 p-5 shadow-sm space-y-4",children:[e.jsx("h2",{className:"font-semibold text-slate-900",children:"Tipo de boleto"}),((Te=t.ticketTypes)==null?void 0:Te.length)>0?e.jsx("div",{className:"space-y-2",children:t.ticketTypes.map(s=>e.jsx("button",{type:"button",onClick:()=>ie(s.id),className:`w-full rounded-2xl border p-4 text-left transition-colors ${H===s.id?"border-[#F26A4B] bg-[#FFF4F0]":"border-slate-200 bg-slate-50 hover:border-slate-300"}`,children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium text-slate-900",children:s.name}),e.jsx("span",{className:"text-sm font-semibold text-slate-700",children:Number(s.price||0)>0?`$${Number(s.price).toFixed(2)}`:"Gratis"})]})},s.id))}):e.jsx("p",{className:"text-sm text-slate-500",children:"Este evento no tiene tipos de boleto configurados."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 uppercase tracking-wide",children:"Cantidad de boletos"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>z(s=>Math.max(1,s-1)),className:"h-12 w-12 rounded-2xl border border-slate-200 flex items-center justify-center hover:bg-slate-100 shrink-0",children:e.jsx(Ve,{className:"h-5 w-5"})}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:200,value:w,onChange:s=>{const a=Math.max(1,Math.min(200,Number(s.target.value)||1));z(a)},className:"flex-1 h-12 rounded-2xl border border-slate-200 text-center text-2xl font-bold focus:outline-none focus:ring-2 focus:ring-[#F26A4B]/40"}),e.jsx("button",{type:"button",onClick:()=>z(s=>Math.min(200,s+1)),className:"h-12 w-12 rounded-2xl border border-slate-200 flex items-center justify-center hover:bg-slate-100 shrink-0",children:e.jsx(We,{className:"h-5 w-5"})})]})]}),H&&e.jsxs("div",{className:"rounded-2xl bg-[#FFF4F0] border border-[#F6C1B4] px-4 py-3 flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm text-slate-600",children:[w," boleto",w!==1?"s":""]}),e.jsx("span",{className:"text-xl font-bold text-[#B94A30]",children:U>0?`$${U.toFixed(2)}`:"Gratis"})]})]}),he&&e.jsx("div",{className:"rounded-2xl bg-red-50 border border-red-200 p-4 text-sm text-red-700",children:he}),e.jsxs("div",{className:"rounded-[28px] bg-white border border-slate-200 p-5 shadow-sm space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(us,{className:"h-4 w-4 text-slate-400"}),e.jsx("span",{className:"text-sm font-semibold text-slate-700",children:"Método de cobro"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:["Efectivo","Transferencia","Tarjeta"].map(s=>e.jsx("button",{type:"button",onClick:()=>ge(s),className:`rounded-2xl border px-4 py-2 text-sm font-medium transition-colors ${fe===s?"border-[#F26A4B] bg-[#FFF4F0] text-[#B94A30]":"border-slate-200 bg-slate-50 text-slate-600 hover:border-slate-300"}`,children:s},s))})]}
10),e.jsx(W,{className:"w-full h-14 rounded-2xl text-base font-semibold bg-[#F26A4B] hover:bg-[#d9543a] text-white shadow-sm",onClick:()=>{Y(null),se.mutate()},disabled:!re||se.isPending,children:se.isPending?e.jsxs(e.Fragment,{children:[e.jsx(D,{className:"h-5 w-5 animate-spin mr-2"})," Procesando..."]}):"Confirmar venta"}),e.jsx(W,{className:"w-full h-12 rounded-2xl text-sm font-semibold bg-[#FFE600] hover:bg-[#FFD700] text-[#333333] shadow-sm",onClick:De,disabled:!re||ye||se.isPending,children:ye?e.jsxs(e.Fragment,{children:[e.jsx(D,{className:"h-4 w-4 animate-spin mr-2"})," Generando linkâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(ps,{className:"h-4 w-4 mr-2"})," Enviar link de pago Mercado Pago"]})}),(B==null?void 0:B.url)&&e.jsxs("div",{className:"rounded-2xl bg-emerald-50 border border-emerald-200 p-4 space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold text-emerald-800",children:"Link de pago generado"}),e.jsx("p",{className:"text-xs text-emerald-700 break-all",children:B.url}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",onClick:Oe,className:"flex-1 inline-flex items-center justify-center gap-1 rounded-xl border border-emerald-300 bg-white px-3 py-2 text-xs font-medium text-emerald-700 hover:bg-emerald-50",children:[e.jsx(hs,{className:"h-3 w-3"})," ",B.copied?"Copiado":"Copiar link"]}),e.jsxs("button",{type:"button",onClick:()=>{var d;const s=ae(r.trim());if(!s)return;const a=((d=t==null?void 0:t.event)==null?void 0:d.name)||"el evento",m=`Hola ${b.trim()}, aquà tienes tu link de pago para *${a}*: 11 12${B.url} 13 14Paga con tarjeta, OXXO o SPEI.`;X(s,m)},className:"flex-1 inline-flex items-center justify-center gap-1 rounded-xl border border-emerald-300 bg-white px-3 py-2 text-xs font-medium text-emerald-700 hover:bg-emerald-50",children:[e.jsx(le,{className:"h-3 w-3"})," Reenviar WhatsApp"]})]})]}),!re&&!se.isPending&&e.jsx("p",{className:"text-xs text-center text-slate-400",children:J?"Completa teléfono, nombre e indica la cantidad de boletos.":M?"Completa teléfono, nombre y selecciona al menos un asiento.":"Completa teléfono, nombre y selecciona un tipo de boleto."}),e.jsx("a",{href:"/eventos",className:"block w-full text-center text-xs text-slate-400 hover:text-slate-600 py-2 transition-colors",children:"â Regresar a eventos"})]})]}),e.jsx(G,{})]})}export{Ss 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.