1import{j as s,a3 as O,aP as T,a$ as D,a1 as k,bb as M,X as I,aa as G,bc as L}from"./mui-f398fe60.js";import{r}from"./react-6ced0908.js";import{e as q,g as $,d as F,p as R,h as Q,L as U}from"./refine-3c729a1b.js";import{B as V}from"./Modal-18508748.js";import{D as X}from"./index-2a20b3cb.js";import{P as z}from"./Page-9c4bb6e6.js";import{u as H,c as J,m as K}from"./index-768edca3.js";import{c as P}from"./copyToClipboard-a341d50a.js";import{f as S}from"./formatDate-3c7d970d.js";import"./mui-x-61e6070d.js";import"./LoadingCircle-ff3fc190.js";import"./utils-78d57de0.js";import"./i18n-a37d409d.js";import"./auth-utils-7ac2656c.js";const me=()=>{const i=q(),N=$(),{open:u}=F(),{selectedProgram:c}=H(),[E,p]=r.useState(!1),[x,_]=r.useState(""),{dataGridProps:d}=R({dataProviderName:"default",resource:"ticket_orders",sorters:{mode:"server"},filters:{mode:"server"},meta:{program:"all"}}),h=r.useMemo(()=>(d==null?void 0:d.rows)||[],[d==null?void 0:d.rows]),v=c!=="all"?c==null?void 0:c.id:null,{result:o,query:{isLoading:W}={}}=Q({url:v?`/ceremonies/?program=${v}`:"/ceremonies/",method:"get",config:{query:{enabled:!!c}}}),[C,b]=r.useState(null);r.useEffect(()=>{if(o!=null&&o.data){const e=o.data;e&&Array.isArray(e.data)?b(e.data):b(o.data)}},[o]);const[f,y]=r.useState([]),g=r.useMemo(()=>{const e=new Set;return h.forEach(t=>{var l;const a=(l=t==null?void 0:t.ceremony)==null?void 0:l.id;a&&e.add(a)}),Array.from(e)},[h]);r.useEffect(()=>{let e=!0;return(async()=>{if(g.length===0){e&&y([]);return}try{const a=await Promise.all(g.map(n=>K("get",`ceremonies/${n}/products/`)));if(!e)return;const l=a.flatMap(n=>{const m=(n==null?void 0:n.data)??n;return Array.isArray(m)?m:m&&typeof m=="object"&&Array.isArray(m.data)?m.data:[]});y(l)}catch{e&&y([])}})(),()=>{e=!1}},[g]);const j=r.useMemo(()=>{if(!f||f.length===0)return[];const e=new Map;return f.forEach(t=>{t.id&&!e.has(t.id)&&e.set(t.id,{id:t.id,title:t.title,is_ticket:t.is_ticket,seats_per_unit:t.seats_per_unit})}),Array.from(e.values())},[f]),A=(e,t)=>{var l;const a=(l=e.order_items)==null?void 0:l.find(n=>n.product===t);return(a==null?void 0:a.quantity)??"-"},B=r.useMemo(()=>[{field:"id",flex:2,display:"flex",headerName:i("Order ID"),minWidth:160,renderCell:({row:e})=>e!=null&&e.id?s.jsx(O,{title:"Copy",children:s.jsx(T,{component:"span",sx:{cursor:"pointer",textDecoration:"underline",textDecorationStyle:"dotted"},onClick:async()=>{const t=await P(String(e==null?void 0:e.id));u==null||u({message:t?"Copied to clipboard":"Failed to copy",type:t?"success":"error"})},children:e==null?void 0:e.id})}):"-"},{field:"ceremony",flex:3,headerName:i("Ceremony"),minWidth:240,valueGetter:(e,t)=>{var a;return J(((a=t==null?void 0:t.ceremony)==null?void 0:a.title)||"-")}},{field:"event_date",flex:2,headerName:i("Event Date"),minWidth:170,valueGetter:(e,t)=>{var a;return S((a=t==null?void 0:t.ceremony)==null?void 0:a.event_date)||"-"}},{field:"purchase_date",flex:2,headerName:i("Purchase Date"),minWidth:170,valueGetter:(e,t)=>{var a;return S(((a=t==null?void 0:t.invoice)==null?void 0:a.purchase_date)||(t==null?void 0:t.created_at))||"-"}},{field:"seats_ordered",flex:1,headerName:i("Seats Ordered"),minWidth:150,valueGetter:(e,t)=>typeof(t==null?void 0:t.seats_ordered)=="number"?t.seats_ordered:"-"},...j.map(e=>({field:`product_${e.id}`,headerName:e.title,flex:2,minWidth:140,sortable:!1,valueGetter:(t,a)=>A(a,e.id)})),{field:"dietary_restrictions",flex:2,display:"flex",headerName:i("Dietary Restrictions"),minWidth:170,renderCell:({row:e})=>e!=null&&e.dietary_restrictions?s.jsx(D,{width:"100%",alignItems:"center",children:s.jsx(k,{"aria-label":"toggle_dietary_restrictions",onClick:()=>{p(!0),_((e==null?void 0:e.dietary_restrictions)??"")},children:s.jsx(M,{})})}):s.jsx(s.Fragment,{})},{field:"seating_preferences",flex:2,display:"flex",headerName:i("Seating Preferences"),minWidth:170,renderCell:({row:e})=>e!=null&&e.seating_preferences?s.jsx(D,{width:"100%",alignItems:"center",children:s.jsx(k,{"aria-label":"toggle_seating_preferences",onClick:()=>{p(!0),_((e==null?void 0:e.seating_preferences)??"")},children:s.jsx(M,{})})}):s.jsx(s.Fragment,{})},{field:"invoice__status",headerName:i("Is Paid"),flex:1,display:"flex",minWidth:120,align:"center",headerAlign:"center",type:"boolean",renderCell:({row:e})=>{var t;return s.jsx(I,{checked:((t=e==null?void 0:e.invoice)==null?void 0:t.status)==="paid",disabled:!0})}}],[u,i,j]);return s.jsx(z,{title:i("Events"),children:s.jsxs(U,{title:s.jsx(G,{variant:"h5",children:i("Events")}),headerButtons:()=>s.jsx(L,{variant:"contained",onClick:()=>{N({to:"/order-tickets",type:"push"})},id:"order-tickets-button","aria-haspopup":"true",disableElevation:!0,loading:!!W,disabled:typeof c=="string"||!C||C.length===0,children:i("Order Tickets")}),children:[s.jsx(V,{open:E,setOpen:p,text:"",details:x,submitText:i("Copy"),handleSubmit:()=>{P(x)},cancelText:i("Close")}),s.jsx(X,{...d,rows:h,columns:B,filterDebounceMs:500,disableColumnMenu:!0})]})})};export{me as UserCeremoniesPage};
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.