1import{r as u,j as e}from"./index-C86y2ZZw.js";import{s as At}from"./sectorOrder-Cuaqy8Yy.js";import{a as dt,s as Bt}from"./audienceOrder-DSesDZPL.js";import{ai as Ot,u as se,K as Ft,U as $t,m as Qt,al as It,bG as Ae,S as ge,z as I,V as R,W as ye,i as v,O as mt,l as ut,B as Q,f as pe,h as _e,bo as Rt,bp as Kt,bq as Ht,br as Vt,bs as zt,M as Lt,a5 as Wt,bj as Ut,ak as gt,v as pt,D as je,a as ve,b as Ne,c as ke,bH as we,a9 as _t,I as Oe,w as xe,n as xt,aL as yt,b7 as Gt}from"./App-BsV2Qj_s.js";import{s as k}from"./client-DMrl-iUj.js";import{A as Be}from"./AdminPageTitle-POBL0ydi.js";import{P as Jt}from"./ProfileSearchSelect-C-07WMPY.js";import{N as Xt}from"./NewClientQuickDialog-DNTRkRye.js";import{u as Yt}from"./useAdminPermissions-W67hJFol.js";import{u as Zt}from"./useVentaEntradasBOPermissions-991iZdMM.js";import{u as es}from"./useActiveMatchTier-BOlsGB-0.js";import{T as ts}from"./textarea-CGKHQQc9.js";import{S as ss}from"./SeatsioChart-DuALRzkE.js";import{G as as}from"./GeneratedTicketsModal-V_kqen7w.js";import{f as is}from"./membershipColors-Nd-0iU3_.js";import{e as ht}from"./edgeError-TbeA1FQd.js";import{P as jt}from"./plus-HguvGPAG.js";import{B as ft}from"./banknote-j7y0gmGQ.js";import{Q as bt}from"./qr-code-CuDlW3Q3.js";import{C as rs}from"./copy-DChoOhGz.js";import"./CiDocumentFields-Dr-zLn1q.js";import"./IdentityMatchDialog-C7-Dt5bS.js";import"./index-BMXkkWuo.js";import"./useSeatsioRegion-Bf3Q6CAk.js";import"./progress-BSMU7b1I.js";import"./TicketRenderer-CyTSO8O8.js";import"./browser-CjSdxGTc.js";import"./ticketSeatParsing-D_Xg3vr-.js";import"./ticketDocuments-BXdS9eRm.js";import"./ticketCanvasAssets-DWRnOKV_.js";import"./hash-B7qdrpFk.js";import"./file-archive-wBWsmUVX.js";import"./download-Bzf4CL-Y.js";function ns(c){const q=Ot(),E=se({queryKey:["backoffice-match-tiers",c],enabled:!!c,queryFn:async()=>{const D={tiers:[],sectorPricesByTier:{},subscriptionDiscountsByTier:{},defaultTierId:null};if(!c)return D;const{data:w}=await k.from("match_sectors").select("id").eq("match_id",c).eq("access_only",!1),y=(w||[]).map(r=>r.id);if(y.length===0)return D;const{data:K}=await k.from("match_sector_price_tiers").select("*").in("match_sector_id",y).order("sort_order"),d=K||[];if(d.length===0)return D;const f=d.map(r=>({id:r.id,match_id:c,name:r.name,sort_order:r.sort_order,status:r.status,audience:r.audience,max_tickets:r.capacity,sold_count:r.sold_count,starts_at:r.starts_at,ends_at:r.ends_at,created_at:r.created_at,updated_at:r.updated_at,is_backoffice_only:!!r.is_backoffice_only,allow_free_price:!!r.allow_free_price,service_fee:Number(r.service_fee||0),visibility_channels:r.visibility_channels||[],max_per_customer:r.max_per_customer,match_sector_id:r.match_sector_id,price:Number(r.price||0),audience_subscription_type_id:r.audie
1nce_subscription_type_id||null,audience_membership_type_id:r.audience_membership_type_id||null})),P={};d.forEach(r=>{P[r.id]=[{id:r.id,tier_id:r.id,match_sector_id:r.match_sector_id,price:Number(r.price||0),capacity:r.capacity,sold_count:Number(r.sold_count||0),is_sold_out:r.status==="sold_out"}]});const A=d.map(r=>r.id),{data:H}=await k.from("match_sector_price_tier_discounts").select("*").in("price_tier_id",A),m=new Map(d.map(r=>[r.id,r])),V={};(H||[]).forEach(r=>{var C;const l=m.get(r.price_tier_id);(V[C=r.price_tier_id]||(V[C]=[])).push({id:r.id,tier_id:r.price_tier_id,match_sector_id:(l==null?void 0:l.match_sector_id)||"",subscription_type_id:r.subscription_type_id,socio_subscription_type_id:null,discount_type:r.discount_type==="percent"?"percentage":r.discount_type,discount_value:Number(r.discount_value||0),final_price:r.final_price!=null?Number(r.final_price):null})});const F=Date.now(),re=r=>{if(r.status==="finished"||r.status==="sold_out")return!1;const l=!r.starts_at||new Date(r.starts_at).getTime()<=F,C=!r.ends_at||new Date(r.ends_at).getTime()>F;return l&&C},z=d.filter(r=>!r.is_backoffice_only),S=z.find(r=>r.status==="active"&&re(r))||z.find(r=>r.status==="scheduled"&&re(r))||z[0]||d[0];return{tiers:f,sectorPricesByTier:P,subscriptionDiscountsByTier:V,defaultTierId:(S==null?void 0:S.id)||null}}});return u.useEffect(()=>{if(!c)return;const D=k.channel(`backoffice-match-tiers-${c}`).on("postgres_changes",{event:"*",schema:"public",table:"match_sector_price_tiers"},()=>q.invalidateQueries({queryKey:["backoffice-match-tiers",c]})).on("postgres_changes",{event:"*",schema:"public",table:"match_sector_price_tier_discounts"},()=>q.invalidateQueries({queryKey:["backoffice-match-tiers",c]})).subscribe();return()=>{k.removeChannel(D)}},[c,q]),E}const G=c=>`Bs ${Number(c||0).toLocaleString("es-BO",{minimumFractionDigits:2,maximumFractionDigits:2})}`;function cs({client:c,onPick:q,onClear:E}){const[D,w]=u.useState(""),[y,K]=u.useState(!1);return e.jsx(I,{children:e.jsxs(R,{className:"p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-wider text-muted-foreground mb-1",children:"Cliente"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Puedes asociar un comprador, pero en esta vista la venta puede continuar sin perfil."})]}),c&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-border/60 bg-muted/25 p-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-primary/15 text-primary font-semibold text-sm flex items-center justify-center shrink-0",children:(c.full_name||"?").slice(0,1).toUpperCase()}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold truncate",children:c.full_name||"â"}),e.jsx("div",{className:"text-[11px] text-muted-foreground truncate",children:[c.ci_number,c.email].filter(Boolean).join(" · ")||"Sin datos"})]})]}),e.jsx(v,{variant:"outline",size:"sm",onClick:()=>{w(""),E()},children:"Cambiar"})]}),e.jsx(Jt,{label:c?"Cambiar cliente":"Buscar cliente",value:D,onChange:(d,f)=>{d&&f&&q({id:d,full_name:f.full_name,email:f.email,ci_number:f.ci_number}),w(d)}}),e.jsxs("div",{className:"flex items-center justify-between pt-1",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"¿No lo encuentras?"}),e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>K(!0),className:"gap-2",children:[e.jsx(Gt,{className:"w-3.5 h-3.5"})," Nuevo cliente"]})]}),e.jsx(Xt,{open:y,onOpenChange:K,onCreated:d=>q({id:d.id,full_name:d.full_name,email:d.email,ci_number:d.ci_number})})]})})}function os({sector:c,activeTariff:q,currentQty:E,onIncrement:D,onDecrement:w,onQuantityChange:y,onOpenSeatMap:K,selectedSeatCount:d,allowFreePrice:f,onPriceChange:P}){const A=c.available_quantity<=0,H=Math.min(c.available_quantity||0,c.max_per_person&&c.max_per_person>0?c.max_per_person:9999),m=c.prices.find(j=>q==="public"?j.pricing_mode==="general":(j.socio_subscription_type_id??j.subscription_type_id
1)===q),V=c.has_numbered_seats,F=V&&!!c.seatsio_event_key,re=c.available_quantity>0&&c.available_quantity<=15,z=!!m&&!f&&m.pricing_mode==="member"&&c.publicPrice>0&&m.price<c.publicPrice,[S,r]=u.useState(String(E));u.useEffect(()=>{r(String(E))},[E]);const[l,C]=u.useState(m?String(m.price):"0");return u.useEffect(()=>{C(m?String(m.price):"0")},[m==null?void 0:m.key,m==null?void 0:m.price]),e.jsxs(I,{className:`relative overflow-hidden ${A?"opacity-60":""}`,children:[e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-[3px]",style:{backgroundColor:c.category_color||"hsl(var(--primary))"}}),e.jsxs(R,{className:"p-4 sm:p-5 pl-5 sm:pl-6 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h4",{className:"font-black italic uppercase text-base sm:text-lg tracking-tight truncate",children:c.name}),!f&&(m==null?void 0:m.discountFromPublic)!=null&&m.discountFromPublic>0&&e.jsxs("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full bg-emerald-500/15 text-emerald-500 border border-emerald-500/30 uppercase tracking-wider whitespace-nowrap",children:["â",m.discountFromPublic.toFixed(0),"% socio"]}),re&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-semibold uppercase tracking-wider text-rose-400 whitespace-nowrap",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-rose-400 animate-pulse"}),"Ãltimas ",c.available_quantity]})]}),m?e.jsx("div",{className:"mt-1 flex items-baseline gap-2 flex-wrap",children:f?e.jsxs("div",{className:"flex items-baseline gap-1",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:"Bs"}),e.jsx(Oe,{type:"number",inputMode:"decimal",min:0,step:"0.01",value:l,onChange:j=>C(j.target.value),onBlur:()=>{const j=Math.max(0,Number(l)||0);C(String(j)),P(m,j)},className:"h-9 w-28 text-2xl sm:text-3xl font-black text-emerald-400 tabular-nums px-2"}),e.jsx("span",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:"/ entrada"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-2xl sm:text-3xl font-black text-emerald-400 tabular-nums leading-none",children:G(m.price)}),z&&e.jsx("span",{className:"text-xs sm:text-sm text-muted-foreground line-through tabular-nums",children:G(c.publicPrice)}),e.jsx("span",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:"/ entrada"})]})}):e.jsx("div",{className:"mt-1 text-[11px] text-muted-foreground italic",children:"Sin tarifa configurada para este tipo en este sector."})]}),m&&e.jsx("div",{className:"shrink-0",children:V?e.jsxs(v,{variant:"outline",size:"sm",className:"uppercase tracking-wider font-bold text-xs h-10 px-4 border-foreground
1/60 hover:border-primary hover:text-primary",disabled:A||!F,onClick:()=>K(m),title:F?void 0:"Este sector no tiene mapa de asientos configurado",children:[e.jsx(yt,{className:"w-3.5 h-3.5 mr-1.5"}),d>0?`${d} asiento${d===1?"":"s"}`:"Elegir asientos"]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>w(m),disabled:A||E<=0,className:"w-10 h-10 rounded-full bg-primary text-primary-foreground flex items-center justify-center transition-all hover:scale-105 hover:brightness-110 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:scale-100","aria-label":"Quitar uno",children:e.jsx(gt,{className:"w-4 h-4",strokeWidth:3})}),e.jsx(Oe,{type:"number",inputMode:"numeric",min:0,max:H,value:S,onChange:j=>r(j.target.value),onBlur:()=>{const j=Math.max(0,Math.min(H,Math.floor(Number(S)||0)));r(String(j)),y(m,j)},onKeyDown:j=>{j.key==="Enter"&&j.target.blur()},className:"h-10 w-16 text-center text-lg font-bold tabular-nums px-1",title:`Máx ${H}`}),e.jsx("button",{type:"button",onClick:()=>D(m),disabled:A||E>=H,className:"w-10 h-10 rounded-full bg-primary text-primary-foreground flex items-center justify-center transition-all hover:scale-105 hover:brightness-110 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:scale-100","aria-label":"Agregar uno",children:e.jsx(jt,{className:"w-4 h-4",strokeWidth:3})})]})})]})]})}function Ks(){var Ye,Ze,et,tt,st,at,it,rt,nt,ct,ot,lt;const{matchId:c}=Ft(),q=$t(),{permissions:E,loading:D}=Yt("venta-entradas-partido"),w=Zt(),[y,K]=u.useState(null),[d,f]=u.useState([]),[P,A]=u.useState(!1),[H,m]=u.useState(""),[V,F]=u.useState(!1),[re,z]=u.useState(!1),[S,r]=u.useState(null),[l,C]=u.useState(null),[j,Fe]=u.useState(!1),{user:ae}=Qt(),oe=se({queryKey:["admin-venta-entradas-recent",c,ae==null?void 0:ae.id],enabled:!!c&&!!(ae!=null&&ae.id),queryFn:async()=>{const{data:t,error:s}=await k.from("reservations").select("id, total_amount, user_id, confirmed_at, created_at, metadata").eq("event_id",c).eq("status","confirmed").filter("metadata->>operator_user_id","eq",ae.id).order("confirmed_at",{ascending:!1,nullsFirst:!1}).limit(10);if(s)throw s;const a=(t||[]).map(p=>p.id);if(a.length===0)return[];const[{data:i},{data:n}]=await Promise.all([k.from("tickets").select("reservation_id, ticket_code").in("reservation_id",a).eq("status","valid").eq("is_deleted",!1),k.from("payments").select("reservation_id, gateway_transaction_id, gateway_response, payment_method").in("reservation_id",a)]),o=new Map;for(const p of i||[]){const b=p.reservation_id,O=o.get(b)||[];O.push(p.ticket_code),o.set(b,O)}const _=new Map((n||[]).map(p=>[p.reservation_id,p])),x=Array.from(new Set((t||[]).map(p=>{var b;return(b=p.metadata)==null?void 0:b.buyer_profile_id}).filter(Boolean))),{data:Y}=x.length?await k.from("profiles").select("id, full_name").in("id",x):{data:[]},B=new Map((Y||[]).map(p=>[p.id,p.full_name]));return(t||[]).map(p=>{var ee,M,g,te;const b=_.get(p.id),O=b?{synced:!!b.gateway_transaction_id,identifier:((ee=b.gateway_response)==null?void 0:ee.identificador)??((M=b.gateway_response)==null?void 0:M.identifier)??null,transaction_id:b.gateway_transaction_id??null,method:b.payment_method||"cash"}:null,Z=(g=p.metadata)==null?void 0:g.buyer_profile_id;return{reservation_id:p.id,ticket_codes:o.get(p.id)||[],total:Number(p.total_amount||0),libelula:O,created_at:p.confirmed_at||p.created_at,client_name:Z&&B.get(Z)||((te=p.metadata)==null?void 0:te.buyer_name)||null}})},staleTime:15e3}),$e=oe.data||[],[he,Qe]=u.useState("public"),[h,Se]=u.useState(null),[le,Ie]=u.useState({}),{data:Ce}=se({queryKey:["seatsio-workspace-key"],queryFn:async()=>{const{data:t}=await k.from("app_settings").select("value").eq("key","seatsio_workspace_key").maybeSingle();return((t==null?void 0:t.value)||"").trim()}}),Re=se({queryKey:["admin-ticket-reserved-seats",c,Object.values(le).sort().join("|")],enabled:!!c,queryFn:async()=>{const t=Object.values(le).filter(Boolean),{data:s}=await k.functions.invoke("ticketing-reserved-seats",{body:{eventId:c,excludeHoldTokens:t}}),a=new Map;
1return((s==null?void 0:s.seats)||[]).forEach(i=>{if(!i.sectorId||!i.eventKey||!i.seatLabel)return;const n=`${i.sectorId}|${i.eventKey}`,o=a.get(n)||[];o.includes(i.seatLabel)||o.push(i.seatLabel),a.set(n,o)}),a},refetchInterval:15e3}),{data:N,isLoading:vt}=se({queryKey:["admin-ticket-sale-event",c],enabled:!!c,queryFn:async()=>{const{data:t}=await k.from("ticketing_events").select("id, name, event_date, event_type, metadata, home_team, away_team, is_published, ticket_sale_enabled, status, competition, ticket_template_id, venues(name), home_team_rel:teams!home_team_id(name, logo_url), away_team_rel:teams!away_team_id(name, logo_url)").eq("id",c).maybeSingle();return t}}),{data:Me=[]}=It(N),J=se({queryKey:["admin-ticket-sale-sectors",c],enabled:!!c,queryFn:async()=>{const{data:t,error:s}=await k.from("match_sectors").select("*, category:match_categories(id,name,color), base_sector:sectors(id, seats_chart_key, seatsio_event_key, has_seats)").eq("match_id",c).eq("is_active",!0).eq("access_only",!1);if(s)throw s;return At(t||[],a=>a.name)}}),Ke=se({queryKey:["admin-ticket-sale-discounts",c,(Ye=J.data)==null?void 0:Ye.length],enabled:!!c&&!!((Ze=J.data)!=null&&Ze.length),queryFn:async()=>{const t=(J.data||[]).map(a=>a.id),{data:s}=await k.from("sector_subscription_discounts").select("*").in("match_sector_id",t).eq("is_active",!0);return s||[]}}),ne=se({queryKey:["admin-ticket-sale-societies"],queryFn:async()=>{const s=(await is()||[]).map(a=>({id:a.id,name:a.name,code:a.code??null,color:a.border_color??null,sort:a.sort_order??999}));return Bt(s,a=>a.name)}}),He=es(c),L=((et=He.data)==null?void 0:et.activeTier)??null,Nt=((tt=He.data)==null?void 0:tt.salesClosed)??!1,$=ns(c),[T,qe]=u.useState(null),kt=t=>{qe(t),f([]),Qe("public"),Ie({})};u.useEffect(()=>{var t;!T&&((t=$.data)!=null&&t.defaultTierId)&&qe($.data.defaultTierId)},[(st=$.data)==null?void 0:st.defaultTierId,T]);const de=u.useMemo(()=>{var s;const t=new Map;return(((s=$.data)==null?void 0:s.tiers)??[]).forEach(a=>{const i=a.name,n=t.get(i);if(n){n.ids.push(a.id),n.audiences.add(a.audience);const o=_=>_==="active"?0:_==="scheduled"?1:_==="sold_out"?2:_==="finished"?3:4;o(a.status)<o(n.representative.status)&&(n.representative=a)}else t.set(i,{key:i,name:a.name,ids:[a.id],audiences:new Set([a.audience]),representative:a})}),Array.from(t.values())},[(at=$.data)==null?void 0:at.tiers]),X=de.find(t=>t.ids.includes(T??""))??null;u.useEffect(()=>{!X&&de.length>0&&qe(de[0].ids[0])},[X,de]);const W=(X==null?void 0:X.representative)??((it=$.data)==null?void 0:it.tiers.find(t=>t.id===T))??null,Ve=(X==null?void 0:X.ids)??(T?[T]:[]),ce=Ve.flatMap(t=>{var s;return((s=$.data)==null?void 0:s.tiers.filter(a=>a.id===t))??[]}),ze=Ve.flatMap(t=>{var s;return((s=$.data)==null?void 0:s.subscriptionDiscountsByTier[t])??[]}),Te=!1,[wt,Le]=u.useState({});u.useEffect(()=>{Le({})},[T]);const Pe=u.useMemo(()=>new Map((ne.data||[]).map(t=>[t.id,t.name])),[ne.data]),We=u.useMemo(()=>{const t=new Map;return ce.forEach(s=>{const a=s.audience_membership_type_id||s.audience_subscription_type_id||"public";t.set(`${s.match_sector_id}::${a}`,s)}),t},[ce]),Ue=u.useMemo(()=>{const t=new Set;return ce.forEach(s=>t.add(s.match_sector_id)),t},[ce]),fe=u.useMemo(()=>{const t=J.data||[],s=Ke.data||[],a=new Map(ce.filter(n=>!n.audience_membership_type_id&&!n.audience_subscription_type_id
1).map(n=>[n.match_sector_id,n])),i=new Map;for(const n of ze){let o=i.get(n.match_sector_id);o||(o=new Map,i.set(n.match_sector_id,o)),o.set(n.subscription_type_id,n)}return t.filter(n=>!T||Ue.has(n.id)).map(n=>{var b,O,Z,ee;const o=a.get(n.id),_=Number(o?o.price:n.base_price||0),x=Number(n.available_quantity||0),Y=[];(!T||o)&&Y.push({key:`${n.id}::public`,label:"Público general",price:_,pricing_mode:"general",subscription_type_id:null,socio_subscription_type_id:null,tier_id:(o==null?void 0:o.id)??null});const B=i.get(n.id);for(const M of ne.data||[]){let g=null;const te=We.get(`${n.id}::${M.id}`);te&&(g=Number(te.price||0));const U=B==null?void 0:B.get(M.id);if(g==null&&U)if(U.final_price!=null)g=Number(U.final_price);else{const ie=Number(U.discount_value||0);g=U.discount_type==="percentage"||U.discount_type==="percent"?Math.max(0,_*(1-ie/100)):Math.max(0,_-ie)}if(g==null){const ie=s.find(ue=>ue.match_sector_id===n.id&&ue.subscription_type_id===M.id);if(ie){const ue=Number(ie.discount_value||0);g=ie.discount_type==="percentage"||ie.discount_type==="percent"?Math.max(0,_*(1-ue/100)):Math.max(0,_-ue)}}if(g==null)continue;const Dt=_>0?(_-g)/_*100:0;Y.push({key:`${n.id}::sub::${M.id}`,label:M.name,price:g,color:M.color,pricing_mode:"member",subscription_type_id:M.id,socio_subscription_type_id:M.id,tier_id:(te==null?void 0:te.id)??(U==null?void 0:U.tier_id)??null,discountFromPublic:Dt})}const p=_;return{id:n.id,name:n.name,has_numbered_seats:!!n.has_numbered_seats,available_quantity:x,base_price:p,max_per_person:n.max_per_person,category_name:((b=n.category)==null?void 0:b.name)||"",category_color:((O=n.category)==null?void 0:O.color)||null,publicPrice:p,prices:Y,seatsio_event_key:n.seatsio_event_key||((Z=n.base_sector)==null?void 0:Z.seatsio_event_key)||null,seats_chart_key:((ee=n.base_sector)==null?void 0:ee.seats_chart_key)||null}})},[J.data,Ke.data,ze,ne.data,Te,wt,T,We,ce,Ue]),Ge=u.useMemo(()=>{const t=new Map;t.set("public",{id:"public",label:"Público general"});for(const s of ne.data||[])t.has(s.id)||t.set(s.id,{id:s.id,label:s.name,color:s.color});return Array.from(t.values()).sort((s,a)=>dt(s.label,s.id==="public")-dt(a.label,a.id==="public"))},[ne.data]),Ee=d.reduce((t,s)=>t+s.unit_price*s.quantity,0),be=d.reduce((t,s)=>t+s.quantity,0),me=(t,s)=>`${t}::${s.pricing_mode}::${s.subscription_type_id??"-"}::${s.tier_id??"-"}`,St=(t,s,a)=>{f(i=>{const n=me(t.id,s),o=i.findIndex(x=>x.key===n),_={key:n,sector_id:t.id,sector_name:t.name,category_name:t.category_name,quantity:a,unit_price:s.price,pricing_mode:s.pricing_mode,subscription_type_id:s.subscription_type_id,socio_subscription_type_id:s.socio_subscription_type_id??null,tier_id:s.tier_id??null,subscription_type_name:s.subscription_type_id?Pe.get(s.subscription_type_id
1)??s.label:null};if(o>=0){const x=[...i];return x[o]={...x[o],quantity:x[o].quantity+a},x}return[...i,_]})},Ct=t=>f(s=>s.filter(a=>a.key!==t)),De=(t,s)=>f(a=>a.flatMap(i=>{if(i.key!==t)return[i];if(i.seat_labels&&i.seat_labels.length>0)return[i];const n=i.quantity+s;return n<=0?[]:[{...i,quantity:n}]})),Mt=(t,s,a)=>{const i=me(t.id,s);f(n=>{const o=n.findIndex(x=>x.key===i);if(a<=0)return n.filter(x=>x.key!==i);const _={key:i,sector_id:t.id,sector_name:t.name,category_name:t.category_name,quantity:a,unit_price:s.price,pricing_mode:s.pricing_mode,subscription_type_id:s.subscription_type_id,socio_subscription_type_id:s.socio_subscription_type_id??null,tier_id:s.tier_id??null,subscription_type_name:s.subscription_type_id?Pe.get(s.subscription_type_id)??s.label:null};if(o>=0){const x=[...n];return x[o]={...x[o],quantity:a,unit_price:s.price},x}return[...n,_]})},qt=(t,s,a)=>{Le(i=>({...i,[s.key]:a})),f(i=>i.map(n=>n.sector_id===t.id&&n.pricing_mode===s.pricing_mode&&(n.subscription_type_id??null)===(s.subscription_type_id??null)&&(n.tier_id??null)===(s.tier_id??null)?{...n,unit_price:a}:n))},Je=(t,s,a,i)=>{var _;const n=t.seatsio_event_key||"",o=n?((_=Re.data)==null?void 0:_.get(`${t.id}|${n}`))||[]:[];if(i&&o.includes(a)){xe.error("Este asiento ya está reservado.");return}f(x=>{const Y=me(t.id,s),B=x.findIndex(g=>g.key===Y),p=B>=0?x[B]:null,b=p!=null&&p.seat_labels?[...p.seat_labels]:[],O=i?b.includes(a)?b:[...b,a]:b.filter(g=>g!==a),Z=Math.min(t.available_quantity||0,t.max_per_person&&t.max_per_person>0?t.max_per_person:99);if(O.length>Z)return xe.error(`Máximo ${Z} asientos para este sector.`),x;const ee={key:Y,sector_id:t.id,sector_name:t.name,category_name:t.category_name,quantity:O.length,unit_price:s.price,pricing_mode:s.pricing_mode,subscription_type_id:s.subscription_type_id,socio_subscription_type_id:s.socio_subscription_type_id??null,tier_id:s.tier_id??null,subscription_type_name:s.subscription_type_id?Pe.get(s.subscription_type_id
1)??s.label:null,seat_labels:O,seatsio_event_key:n||null},M=B>=0?[...x]:[...x,ee];return B>=0&&(M[B]=ee),M.filter(g=>!(g.seat_labels&&g.seat_labels.length===0))})},Xe=t=>d.filter(s=>{var a;return s.sector_id===t&&((a=s.seat_labels)==null?void 0:a.length)}).reduce((s,a)=>{var i;return s+(((i=a.seat_labels)==null?void 0:i.length)||0)},0),Tt=async()=>{if(d.length!==0){A(!0);try{const{data:t,error:s}=await k.functions.invoke("backoffice-ticket-sale",{body:{action:"cash",event_id:c,buyer_profile_id:(y==null?void 0:y.id)??null,tier_id:T,cash_notes:H.trim()||null,items:d.map(i=>({sector_id:i.sector_id,sector_name:i.sector_name,category_name:i.category_name,quantity:i.quantity,unit_price:i.unit_price,pricing_mode:i.pricing_mode,subscription_type_id:i.subscription_type_id,socio_subscription_type_id:i.socio_subscription_type_id??null,subscription_type_name:i.subscription_type_name??null,tier_id:i.tier_id??null,seat_labels:i.seat_labels||null,seatsio_event_key:i.seatsio_event_key||null})),hold_tokens:le}});if(s)throw new Error(await ht(s,"No se pudo registrar la venta en caja"));if(t!=null&&t.error)throw new Error(t.error);F(!1);const a={ticket_codes:t.ticket_codes||[],total:t.total||Ee,reservation_id:t.reservation_id,libelula:t.libelula??null};C(a),oe.refetch(),f([]),m(""),J.refetch()}catch(t){xe.error((t==null?void 0:t.message)||"No se pudo registrar la venta en caja")}finally{A(!1)}}},Pt=async()=>{if(d.length!==0){A(!0);try{const{data:t,error:s}=await k.functions.invoke("backoffice-ticket-sale",{body:{action:"qr",event_id:c,buyer_profile_id:(y==null?void 0:y.id)??null,tier_id:T,items:d.map(i=>({sector_id:i.sector_id,sector_name:i.sector_name,category_name:i.category_name,quantity:i.quantity,unit_price:i.unit_price,pricing_mode:i.pricing_mode,subscription_type_id:i.subscription_type_id,socio_subscription_type_id:i.socio_subscription_type_id??null,subscription_type_name:i.subscription_type_name??null,tier_id:i.tier_id??null,seat_labels:i.seat_labels||null,seatsio_event_key:i.seatsio_event_key||null})),hold_tokens:le}});if(s)throw new Error(await ht(s,"No se pudo generar el QR"));if(t!=null&&t.error)throw new Error(t.error);const a=t;r({qr_url:a.qr_url,checkout_url:a.checkout_url,reservation_id:a.reservation_id,expires_at:a.expires_at}),z(!0),J.refetch()}catch(t){xe.error((t==null?void 0:t.message)||"No se pudo generar el QR")}finally{A(!1)}}},Et=N&&(!N.is_published||!N.ticket_sale_enabled);return D?e.jsxs(Ae,{children:[e.jsx(Be,{children:e.jsx("span",{children:"VENTA DE ENTRADAS â PARTIDO"})}),e.jsx("div",{className:"p-6",children:e.jsx(ge,{className:"h-40 w-full rounded-xl"})})]}):E.can_view?e.jsxs(Ae,{children:[e.jsx(Be,{children:e.jsx("span",{children:"VENTA DE ENTRADAS â PARTIDO"})}),e.jsxs("div",{className:"p-6 pt-4 space-y-4",children:[e.jsxs(v,{variant:"ghost",size:"sm",onClick:()=>q("/admin/partidos"),className:"gap-2",children:[e.jsx(mt,{className:"w-4 h-4"})," Volver a partidos"]}),vt?e.jsx(ge,{className:"h-24 w-full rounded-xl"}):N?e.jsxs(e.Fragment,{children:[e.jsx(I,{children:e.jsxs(R,{className:"p-4 flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[((rt=N.home_team_rel)==null?void 0:rt.logo_url)&&e.jsx("img",{src:N.home_team_rel.logo_url,className:"w-10 h-10 object-contain",alt:""}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold flex items-center gap-2",children:ut(N)?e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"bg-amber-500/20 text-amber-400 border border-amber-500/40",children:"PASE"}),N.name]}):e.jsxs(e.Fragment,{children:[((nt=N.home_team_rel)==null?void 0:nt.name)||N.home_team," ",e.jsx("span",{className:"text-muted-foreground",children:"vs"})," ",((ct=N.away_team_rel)==null?void 0:ct.name)||N.away_team]})}),e.jsx("div",{className:"text-xs text-muted-foreground",children:pe(new Date(N.event_date),"EEE d MMM ⢠HH:mm",{locale:_e})}),ut(N)&&Me.length>0&&e.jsxs("div",{className:"text-[11px] text-muted-foreground mt-0.5 truncate max-w-[420px]",children:[Me.length," encuentros: ",Me.map(t=>t.rivalShortName||t.rivalName).join(" · ")]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[L?e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsxs(Q,{className:"gap-1 bg-emerald-500/15 text-emerald-400 border border-emerald-500/30 hover:bg-emerald-500/20",children:[e.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-emerald-400 animate-pulse"}),"Fase activa: ",L.name]}),e.jsx(Q,{variant:"outline",className:"text-[10px] uppercase tracking-wider",children:L.audience==="both"?"Socios + Público":L.audience==="socios"?"Solo socios":"Público"}),L.max_tickets!=null&&e.jsxs(Q,{variant:"outline",className:"text-[10px] text-muted-foreground",title:"Informativo â Back Office no aplica el lÃmite por fase",children:[L.sold_count,"/",L.max_tickets," (informativo)"]}),L.ends_at&&e.jsxs(Q,{variant:"outline",className:"text-[10px]",children:["Hasta ",pe(new Date(L.ends_at),"d MMM HH:mm",{locale:_e})]})]}):e.jsxs(Q,{variant:"outline",className:"gap-1 text-muted-foreground",children:[e.jsx(ye,{className:"w-3 h-3"})," Sin fase activa"]}),Nt&&e.jsxs(Q,{variant:"outline",className:"gap-1 border-amber-500/40 text-amber-400",children:[e.jsx(ye,{className:"w-3 h-3"})," Fase pública finalizada (admin habilitado)"]}),Et&&e.jsxs(Q,{variant:"destructive",className:"gap-1",children:[e.jsx(ye,{className:"w-3 h-3"})," Venta web deshabilitada"]})]})]})}),e.jsxs("div",{className:"grid lg:grid-cols-[1fr_360px] gap-4 items-start",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-wider text-muted-foreground",children:"Sectores disponibles"}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:[fe.length," sector",fe.length===1?"":"es"]})]}),$.data&&$.data.tiers.length>0&&e.jsx(I,{className:"border-primary/20",children:e.jsx(R,{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-[220px] flex-1",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:"Tarifa del partido (Back Office)"}),e.jsxs(Rt,{value:T??"",onValueChange:kt,children:[e.jsx(Kt,{className:"h-9 mt-1",children:e.jsx(Ht,{placeholder:"Selecciona un tier"})}),e.jsx(Vt,{children:de.filter(t=>w.canSellInactiveTiers||w.loading||t.representative.status==="active").map(t=>{const s=t.representative,a=[s.starts_at,s.ends_at].map(n=>n?pe(new Date(n),"d MMM HH:mm",{locale:_e}
1):null).filter(Boolean).join(" â "),i=s.is_backoffice_only?"Back Office":s.status==="active"?"Activo":s.status==="scheduled"?"Programado":s.status==="finished"?"Finalizado":s.status==="sold_out"?"Agotado":"Borrador";return e.jsxs(zt,{value:t.ids[0],children:[t.name," · ",i,a?` · ${a}`:""]},t.key)})})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[(W==null?void 0:W.is_backoffice_only)&&e.jsx(Q,{variant:"outline",className:"border-primary/40 text-primary",children:"Solo Back Office"}),Te,!(W!=null&&W.is_backoffice_only)&&(W==null?void 0:W.status)==="finished"&&e.jsx(Q,{variant:"outline",className:"text-muted-foreground",children:"Tarifa histórica"})]})]})})}),Ge.length>1&&e.jsx("div",{className:"sticky top-0 z-10 -mx-1 px-1 py-2 bg-background/95 backdrop-blur border-b border-border/60",children:e.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto pb-1",children:Ge.map(t=>{const s=he===t.id,a=t.id==="public";return e.jsx("button",{onClick:()=>Qe(t.id),className:`shrink-0 px-3 h-8 rounded-full text-xs font-semibold uppercase tracking-wider border transition-colors ${s?"bg-primary text-primary-foreground border-primary":"bg-muted/40 border-border/60 text-muted-foreground hover:text-foreground hover:border-primary/40"}`,style:s&&!a&&t.color?{backgroundColor:t.color,borderColor:t.color,color:"#fff"}:{},children:t.label},t.id)})})}),J.isLoading?e.jsxs("div",{className:"space-y-2",children:[e.jsx(ge,{className:"h-24 w-full"}),e.jsx(ge,{className:"h-24 w-full"})]}):fe.length===0?e.jsx(I,{children:e.jsxs(R,{className:"p-6 text-center text-muted-foreground text-sm flex flex-col items-center gap-2",children:[e.jsx(Lt,{className:"w-6 h-6 opacity-60"}),"Aún no hay sectores configurados para este partido."]})}):e.jsx("div",{className:"flex flex-col gap-2.5",children:fe.map(t=>{const s=t.prices.find(o=>he==="public"?o.pricing_mode==="general":(o.socio_subscription_type_id??o.subscription_type_id
1)===he),a=s?me(t.id,s):"",i=d.find(o=>o.key===a),n=i&&!(i.seat_labels&&i.seat_labels.length>0)?i.quantity:0;return e.jsx(os,{sector:t,activeTariff:he,currentQty:n,onIncrement:o=>St(t,o,1),onDecrement:o=>De(me(t.id,o),-1),onQuantityChange:(o,_)=>Mt(t,o,_),onOpenSeatMap:o=>Se({sector:t,row:o}),selectedSeatCount:Xe(t.id),allowFreePrice:Te,onPriceChange:(o,_)=>qt(t,o,_)},t.id)})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(cs,{client:y,onPick:K,onClear:()=>K(null)}),e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-wider text-muted-foreground",children:"Carrito"}),e.jsx(I,{children:e.jsxs(R,{className:"p-4 space-y-3",children:[d.length===0?e.jsxs("div",{className:"text-xs text-muted-foreground py-6 text-center flex flex-col items-center gap-2",children:[e.jsx(Wt,{className:"w-6 h-6 opacity-60"}),"Selecciona sectores para armar el pedido."]}):e.jsx("div",{className:"space-y-2",children:d.map(t=>e.jsxs("div",{className:"border border-border/60 rounded-lg p-2.5 space-y-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold truncate",children:t.sector_name}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[t.pricing_mode==="member"?t.subscription_type_name||"Socio":"Público"," · ",G(t.unit_price)," c/u"]})]}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>Ct(t.key),children:e.jsx(Ut,{className:"w-3.5 h-3.5 text-destructive"})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(v,{variant:"outline",size:"icon",className:"h-7 w-7",onClick:()=>De(t.key,-1),disabled:t.quantity<=1,children:e.jsx(gt,{className:"w-3 h-3"})}),e.jsx("span",{className:"text-sm font-semibold w-6 text-center",children:t.quantity}),e.jsx(v,{variant:"outline",size:"icon",className:"h-7 w-7",onClick:()=>De(t.key,1),children:e.jsx(jt,{className:"w-3 h-3"})})]}),e.jsx("div",{className:"text-sm font-bold",children:G(t.unit_price*t.quantity)})]})]},t.key))}),e.jsx("div",{className:"border-t border-border/60 pt-3 flex items-center justify-between",children:e.jsxs("div",{children:[e.jsxs("div",{className:"text-[10px] uppercase text-muted-foreground",children:["Total (",be," entrada",be===1?"":"s",")"]}),e.jsx("div",{className:"text-xl font-bold text-primary",children:G(Ee)})]})})]})}),e.jsx(I,{children:e.jsxs(R,{className:"p-4 space-y-2",children:[e.jsx("h4",{className:"text-xs uppercase tracking-wider text-muted-foreground mb-1",children:"Método de pago"}),!y&&d.length>0&&e.jsx("div",{className:"rounded-lg border border-primary/30 bg-primary/10 p-2 text-[11px] text-primary",children:"Venta sin perfil asociado. Puedes cobrar y generar las entradas desde esta vista."}),w.canCash&&e.jsxs(v,{className:"w-full gap-2",disabled:d.length===0||P,onClick:()=>F(!0),children:[e.jsx(ft,{className:"w-4 h-4"})," Cobrar en caja (efectivo)"]}),w.canQR&&e.jsxs(v,{variant:"outline",className:"w-full gap-2",disabled:d.length===0||P,onClick:Pt,children:[P?e.jsx(pt,{className:"w-4 h-4 animate-spin"}):e.jsx(bt,{className:"w-4 h-4"}),"Generar QR / Pasarela"]}),!w.canCash&&!w.canQR&&!w.canCard&&!w.loading&&e.jsx("div",{className:"rounded-lg border border-destructive/30 bg-destructive/10 p-2 text-[11px] text-destructive",children:"Este rol no tiene habilitado ningún método de cobro. Solicita al administrador que active al menos uno en Permisos Venta BO."}),e.jsx("p",{className:"text-[10px] text-muted-foreground pt-1",children:"El pago en caja confirma inmediatamente y genera las entradas. El QR queda pendiente hasta que el cliente pague."})]})}),$e.length>0&&e.jsx(I,{children:e.jsxs(R,{className:"p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Ãltimas ventas"}),e.jsx("button",{type:"button",className:"text-[10px] text-muted-foreground hover:text-primary uppercase tracking-wider disabled:opacity-50",onClick:()=>oe.refetch(),disabled:oe.isFetching,children:oe.isFetching?"Actualizandoâ¦":"Actualizar"})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Toca una venta para reabrir el comprobante y reimprimir las entradas."}),e.jsx("div",{className:"space-y-1.5 max-h-72 overflow-auto pr-1",children:$e.map(t=>e.jsx("button",{type:"button",onClick:()=>C({ticket_codes:t.ticket_codes,total:t.total,reservation_id:t.reservation_id,libelula:t.libelula??null}),className:"w-full text-left rounded-lg border border-border/60 bg-muted/20 hover:bg-muted/40 hover:border-primary/40 transition-colors p-2.5",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold truncate",children:t.client_name||"Sin cliente"}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[pe(new Date(t.created_at),"HH:mm · dd MMM",{locale:_e})," · ",t.ticket_codes.length," entrada",t.ticket_codes.length===1?"":"s"]})]}),e.jsx("div",{className:"text-xs font-bold text-primary tabular-nums shrink-0",children:G(t.total)})]})},t.reservation_id))})]})})]})]})]}):e.jsx(I,{children:e.jsx(R,{className:"p-6 text-center text-muted-foreground",children:"Partido no encontrado."})})]}),e.jsx(je,{open:V,onOpenChange:t=>!P&&F(t),children:e.jsxs(ve,{children:[e.jsx(Ne,{children:e.jsxs(ke,{className:"flex items-center gap-2",children:[e.jsx(ft,{className:"w-4 h-4 text-primary"}),"Cobrar en caja"]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("div",{className:"text-[10px] uppercase text-muted-foreground",children:"Total a cobrar"}),e.jsx("div",{className:"text-2xl font-bold text-primary",children:G(Ee)}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[be," entrada",be===1?"":"s"," · ",(y==null?void 0:y.full_name)||"Sin perfil asociad
1o"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Notas (opcional)"}),e.jsx(ts,{value:H,onChange:t=>m(t.target.value),placeholder:"Ej: pago con 200, cambio 50",rows:2})]})]}),e.jsxs(we,{children:[e.jsx(v,{variant:"outline",onClick:()=>F(!1),disabled:P,children:"Cancelar"}),e.jsxs(v,{onClick:Tt,disabled:P,className:"gap-2",children:[P?e.jsx(pt,{className:"w-4 h-4 animate-spin"}):e.jsx(_t,{className:"w-4 h-4"}),"Confirmar cobro"]})]})]})}),e.jsx(je,{open:re,onOpenChange:t=>{t||(z(!1),r(null))},children:e.jsxs(ve,{children:[e.jsx(Ne,{children:e.jsxs(ke,{className:"flex items-center gap-2",children:[e.jsx(bt,{className:"w-4 h-4 text-primary"}),"Cobro por QR / Pasarela"]})}),S&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Comparte el QR o el enlace con el cliente. Las entradas se generan automáticamente al confirmar el pago."}),S.qr_url&&e.jsx("div",{className:"flex justify-center bg-white rounded-lg p-4",children:e.jsx("img",{src:S.qr_url,alt:"QR de pago",className:"w-52 h-52 object-contain"})}),S.checkout_url&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] uppercase text-muted-foreground",children:"Enlace de pasarela"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Oe,{value:S.checkout_url,readOnly:!0,className:"text-xs"}),e.jsx(v,{variant:"outline",size:"icon",onClick:()=>{navigator.clipboard.writeText(S.checkout_url),xe.success("Enlace copiado")},children:e.jsx(rs,{className:"w-4 h-4"})})]})]}),S.expires_at&&e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Válido hasta ",pe(new Date(S.expires_at),"HH:mm 'del' d MMM",{locale:_e})]})]}),e.jsx(we,{children:e.jsx(v,{onClick:()=>{z(!1),r(null),f([])},children:"Cerrar"})})]})}),e.jsx(je,{open:!!l,onOpenChange:t=>{t||C(null)},children:e.jsxs(ve,{children:[e.jsx(Ne,{children:e.jsxs(ke,{className:"flex items-center gap-2 text-green-500",children:[e.jsx(_t,{className:"w-5 h-5"}),"Venta registrada"]})}),l&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"bg-green-500/10 border border-green-500/30 rounded-lg p-3",children:[e.jsx("div",{className:"text-[10px] uppercase text-muted-foreground",children:"Total cobrado"}),e.jsx("div",{className:"text-2xl font-bold text-green-500",children:G(l.total)})]}),l.libelula&&e.jsxs("div",{className:`rounded-lg border p-3 space-y-1.5 ${l.libelula.synced?"bg-blue-500/10 border-blue-500/30":"bg-amber-500/10 border-amber-500/30"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-[10px] uppercase text-muted-foreground",children:"Sincronización Libélula"}),e.jsx("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-full ${l.libelula.synced?"bg-blue-500/20 text-blue-500":"bg-amber-500/20 text-amber-600"}`,children:l.libelula.synced?`Registrado (${l.libelula.method})`:"No sincronizado"})]}),l.libelula.identifier&&e.jsxs("div",{className:"text-[11px] font-mono flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"Identificador:"}),e.jsx("span",{className:"font-semibold truncate",children:l.libelula.identifier})]}),l.libelula.transaction_id&&l.libelula.transaction_id!==l.libelula.identifier&&e.jsxs("div",{className:"text-[11px] font-mono flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"Transacción:"}),e.jsx("span",{className:"font-semibold truncate",children:l.libelula.transaction_id})]}),!l.libelula.synced&&l.libelula.error&&e.jsx("div",{className:"text-[11px] text-amber-600",children:l.libelula.error})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs font-semibold mb-2 flex items-center gap-1",children:[e.jsx(xt,{className:"w-3.5 h-3.5"}),"Códigos de entrada (",l.ticket_codes.length,")"]}),e.jsx("div",{className:"grid grid-cols-2 gap-1.5 max-h-48 overflow-y-auto",children:l.ticket_codes.map(t=>e.jsx("div",{className:"text-[11px] font-mono bg-muted rounded px-2 py-1",children:t},t))})]})]}),e.jsxs(we,{children:[e.jsx(v,{variant:"outline",onClick:()=>{C(null)},children:"Cerrar"}),(l==null?void 0:l.reservation_id)&&e.jsxs(v,{variant:"secondary",onClick:()=>Fe(!0),children:[e.jsx(xt,{className:"w-4 h-4 mr-1.5"}),"Ver entradas"]}),e.jsx(v,{onClick:()=>{C(null),q("/admin/partidos")},children:"Ir a partidos"})]})]})}),(l==null?void 0:l.reservation_id)&&e.jsx(as,{allowRegenerate:!0,open:j,onClose:()=>Fe(!1),reservation:{id:l.reservation_id,total_amount:l.total},event:N}),e.jsx(je,{open:!!h,onOpenChange:t=>{t||Se(null)},children:e.jsxs(ve,{className:"max-w-5xl w-[95vw] h-[85vh] p-0 overflow-hidden flex flex-col",children:[e.jsxs(Ne,{className:"p-4 border-b border-border/60",children:[e.jsxs(ke,{className:"flex items-center gap-2",children:[e.jsx(yt,{className:"w-4 h-4 text-primary"}),h?`Selecciona asientos · ${h.sector.name}`:"Selecciona asientos"]}),h&&e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Tarifa: ",e.jsx("strong",{children:h.row.label})," · ",G(h.row.price)," c/u"]})]}),e.jsx("div",{className:"flex-1 min-h-0 bg-navy-deep",children:h&&Ce&&h.sector.seatsio_event_key?e.jsx(ss,{workspaceKey:Ce,eventKe
1y:h.sector.seatsio_event_key,chartKey:h.sector.seats_chart_key,holdToken:le[h.sector.seatsio_event_key]||null,selectedObjects:((ot=d.find(t=>t.sector_id===h.sector.id&&t.pricing_mode===h.row.pricing_mode&&(t.subscription_type_id??null)===(h.row.subscription_type_id??null)))==null?void 0:ot.seat_labels)||[],blockedObjects:((lt=Re.data)==null?void 0:lt.get(`${h.sector.id}|${h.sector.seatsio_event_key}`))||[],onHoldTokenReady:t=>{const s=h.sector.seatsio_event_key;Ie(a=>a[s]?a:{...a,[s]:t.holdToken})},onObjectSelected:t=>{const s=(t==null?void 0:t.label)||(t==null?void 0:t.id);s&&Je(h.sector,h.row,String(s),!0)},onObjectDeselected:t=>{const s=(t==null?void 0:t.label)||(t==null?void 0:t.id);s&&Je(h.sector,h.row,String(s),!1)}}):e.jsx("div",{className:"h-full flex items-center justify-center text-sm text-muted-foreground p-6 text-center",children:Ce?"Este sector no tiene un evento de Seats.io configurado.":"Workspace key de Seats.io no configurada."})}),e.jsxs(we,{className:"p-3 border-t border-border/60",children:[e.jsx("div",{className:"flex-1 text-xs text-muted-foreground",children:h&&`Seleccionados: ${Xe(h.sector.id)}`}),e.jsx(v,{onClick:()=>Se(null),children:"Listo"})]})]})})]}):e.jsxs(Ae,{children:[e.jsx(Be,{children:e.jsx("span",{children:"VENTA DE ENTRADAS â PARTIDO"})}),e.jsx("div",{className:"p-6",children:e.jsx(I,{children:e.jsxs(R,{className:"p-10 text-center space-y-3",children:[e.jsx(ye,{className:"h-8 w-8 mx-auto text-amber-500"}),e.jsx("div",{className:"text-lg font-semibold",children:"Acceso restringido"}),e.jsxs("p",{className:"text-sm text-muted-foreground max-w-md mx-auto",children:["Tu rol no tiene permisos para vender entradas desde el Back Office. Solicita acceso a un administrador desde",e.jsx("span",{className:"mx-1 font-mono",children:"Ticketing â Permisos Venta BO"}),"."]}),e.jsxs(v,{variant:"outline",onClick:()=>q("/admin/partidos"),children:[e.jsx(mt,{className:"w-4 h-4 mr-2"})," Volver a partidos"]})]})})})]})}export{Ks 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.