1import{r as i,a as be,i as Pe,b as ke,u as q,j as t,T as P,F as M,B as T,dm as Se,dn as Te,H as Fe,G as Ie,b0 as $e,aN as Ve,a$ as Re,an as Ee,f as me,N as Oe,d as Be,ak as z,dp as Ne,dq as ze,dr as Le,ds as _e,dt as Me,du as H,az as qe,I as He,dc as oe,g as W,$ as We,ab as Ge,by as Ae,bp as Ye,aj as G,ax as Q,dv as Qe}from"./index-pPvOpbK4.js";import{d as Ue}from"./Delete-R7Dc77mf.js";import{d as Ke}from"./Edit-DbbgdXbj.js";import{d as L}from"./Receipt-DloY6AaU.js";import{H as Ze}from"./Helmet-CCg8G9ox.js";import{C as Je}from"./CommonLayout-CerJhXaI.js";import{C as Xe}from"./ConfirmDialog-XqG73pdn.js";import{E as et}from"./ExpandIcon-Dltzu-HN.js";import{C as ue}from"./Code-DgPnKuM9.js";import{u as ce,C as tt}from"./CartItemsList-DlmG05t-.js";import nt from"./CartMenuContent-B1bzmi7F.js";import{V as ot}from"./ViewReceiptButton-BkgkQTbu.js";import{H as rt}from"./HelpIconTooltip-ByG0Mcn9.js";import{L as at}from"./LoadingBackgrop-DN2DO7eW.js";import{P as st}from"./Pagination-KrM-5wQK.js";import{a as _}from"./calculations-CWWqduA_.js";import{g as re}from"./getZonedTimeFromLocal-D1G9zhHm.js";import{l as it}from"./limitDecimalPlaces-BpQsytXA.js";import{a as lt}from"./userTypes-D_fgUtxk.js";import{c as mt}from"./customId-BF91Vb_q.js";import{T as ut,a as ae}from"./Tabs-rViWCP5Y.js";import"./ExpandMore-6WJ8h37s.js";import"./Add-CSSOaeP8.js";import"./event-DvkdFTas.js";import"./eventStatus-BQDY6zOY.js";import"./index-BIE3kTcP.js";import"./CircularProgress-DG1AUJQV.js";import"./Settings-DDYPe9OI.js";import"./DiscountLine-CPw-pYLR.js";import"./CartSummary-BvKhNNEc.js";import"./helpers-B1GXanM3.js";import"./checkCompositeFields-CbQUhLIb.js";import"./filterRegForm-B4zuJkMG.js";import"./teams-DqScfkv5.js";import"./Tooltip-kqA8ffb_.js";import"./index-D3Grpiwx.js";import"./index.browser-CeQjyfxW.js";var U={},ct=Pe,dt=ke;Object.defineProperty(U,"__esModule",{value:!0});var de=U.default=void 0,pt=dt(i),ht=ct(be()),ft=(0,ht.default)(pt.createElement("path",{d:"M17.63 5.84C17.27 5.33 16.67 5 16 5L5 5.01C3.9 5.01 3 5.9 3 7v10c0 1.1.9 1.99 2 1.99L16 19c.67 0 1.27-.33 1.63-.84L22 12l-4.37-6.16z"}),"Label");de=U.default=ft;function xt({onSuccess:a,cart:e}){const{t:o}=q(),[l,s]=i.useState((e==null?void 0:e.name)||""),[m,p]=i.useState((e==null?void 0:e.connectCode)||"");i.useEffect(()=>{e&&(l||s(e.name),m||p(e.connectCode))},[e]),i.useEffect(()=>{m||p(mt())},[]);async function c(){l&&(await Se({connectCode:m,name:l}),a==null||a())}async function r(){l&&(await Te({cartId:e._id,name:l}),a==null||a())}return t.jsxs(t.Fragment,{children:[t.jsx(P,{text:o("CheckoutView.groupReg",{count:1})}),t.jsx("p",{children:o("CheckoutView.groupRegTooltip")}),t.jsx(M,{required:!0,label:o("CheckoutView.groupName"),value:l,onChange:k=>s(k.target.value)}),t.jsxs("p",{children:[o("CheckoutView.afterCreated"),":"]}),t.jsx(ue,{text:m}),t.jsx(T,{style:{marginTop:"1.5rem"},variant:"primary",onClick:e?r:c,label:o(e?"Buttons.saveBtnText":"Buttons.createBtnText")})]})}const A=50,j={open:!1,titleText:"",promptText:"",confirmButtonText:"",onConfirm:()=>{}};function Y(a,e){const o=new Date;return a&&(o.setFullYear(a.split("-")[0]),o.setMonth(a.split("-")[1]-1),o.setDate(a.split("-")[2])),e&&(o.setHours(e.split(":")[0]),o.setMinutes(e.split(":")[1]),o.setSeconds(0),o.setMilliseconds(0)),o}const Ct={open:"incompleted",completed:"succeeded"};function an(){var h;const{t:a}=q(),e=Fe(),o=Ie(),{user:l,isInitialLoading:s}=$e(),m=i.useMemo(()=>l.currentProfile&&o.pathname.includes("/organizer")?"company":lt(l)&&(o.pathname.includes("/organizer")||o.pathname.includes("/admin"))?"admin":"athlete",[o.pathname]),p=Ve(),c=i.useMemo(()=>{switch(m){case"company":return"/organizer/group-orders";case"admin":return"/admin/orders";case"athlete":return"/orders";default:return"/orders"}},[m]);i.useEffect(()=>{o.pathname!==`${c}/${r}`&&e.replace(`${c}/${r}`,{noScroll:!0})},[m,c]);const r=o.pathname.includes("completed")?"completed":"open",k=(d,x)=>{e.push(`${c}/${x}`,{noScroll:!0})},v=i.useMemo(()=>Re.parse(o.search,{ignoreQueryPrefix:!0}),[o.search]),F=v.cartNumber||v.orderNumber,D=Number(v.page??1);function I(d){d==="next"&&e.push(`${o.pathname}?page=${D+1}`,{noScroll:!0}),d==="prev"&&e.push(`${o.pathname}?page=${D-1}`,{noScroll:!0})}const E=["orders",m,r,`page=${D}`,`cart=${(v.cartNumber||v.orderNumber)??"all"}`],{data:u,isLoading:O,refetch:y}=Ee({queryKey:E,queryFn:()=>{const d={status:Ct[r],type:m,...F?v:{user:l._id},skip:(D-1)*A,limit:A};return Q("/api/cart/getCarts",d)},enabled:!s,staleTime:1/0}),B=me();i.useEffect(()=>()=>B.invalidateQueries({queryKey:E}),[]),ce((h=u==null?void 0:u.map(({cart:d})=>d.items))==null?void 0:h.flat());const w=i.useMemo(()=>o.pathname.split("/group-registration/")[1],[o.pathname]),$=i.useMemo(()=>{var d;if(w)return(d=u==null?void 0:u.find(({cart:x})=>x.connectCode===w))==null?void 0:d.cart},[u,w]);function C(d){e.push(`${c}/open/group-registration${d?`/${d}`:""}`)}function V(){e.push(`${c}/open`)}let b=null;return b=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"orders-view",children:[t.jsx(P,{scale:1,text:m==="company"?a("CheckoutView.groupReg",{count:2}):a("CheckoutView.orderHistory"),style:{marginBottom:"2rem"}}),m==="athlete"&&t.jsx("div",{style:{marginTop:"2rem",marginBottom:"2rem"},children:t.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[t.jsx(T,{variant:"primary",onClick:()=>C(),children:a("CheckoutView.newGroupRegistration")}),t.jsx(rt,{title:a("CheckoutView.groupRegTooltip")})]})}),t.jsxs(ut,{value:r,onChange:k,"aria-label":"simple tabs example",indicatorColor:"primary",className:"orders-tabs",children:[t.jsx(ae,{label:a("CheckoutView.openOrders"),...se("open")}),t.jsx(ae,{label:a("CheckoutView.completedOrders"),...se("completed")})]}),t.jsx(ie,{value:"open",currentTab:r,children:t.jsx(le,{cartsAndMessages:u,currentTab:r,openGroupRegDialog:C,isLoading:O,openByDefault:F,pageType:m,canWrite:p})}),t.jsx(ie,{value:"completed",currentTab:r,children:t.jsx(le,{cartsAndMessages:u,currentTab:r,isLoading:O,openByDefault:F,pageType:m,canWrite:p})}),(u==null?void 0:u.length)>0&&t.jsx(st,{variant:"text",buttonStyle:{minWidth:"auto",padding:0},listLength:(u==null?void 0:u.length)||0,limit:A,currentPage:D-1,handlePagination:I})]}),t.jsx(Oe,{path:[`${c}/open/group-registration`,`${c}/open/group-registration/:code`],onClose:V,children:t.jsx(xt,{cart:$,onSuccess:()=>{y(),V()}})})]}),t.jsx(t.Fragment,{children:t.jsxs(Je,{style:{maxWidth:"800px"},children:[t.jsx(Ze,{children:t.jsx("title",{children:`${a("CommonFieldNames.orders")} | PACE`})}),b]})})}function se(a){return{id:`simple-tab-${a}`,"aria-controls":`simple-tabpanel-${a}`,value:a}}function ie(a){const{children:e,value:o,currentTab:l,...s}=a;return t.jsx("div",{role:"tabpanel",hidden:o!==l,id:`simple-tabpanel-${l}`,"aria-labelledby":`simple-tab-${l}`,...s,children:o===l&&e})}function le({openByDefault:a,cartsAndMessages:e,currentTab:o,isLoading:l,...s}){const{t:m}=q();return l?t.jsx(at,{open:!0}):(e==null?void 0:e.length)===0?t.jsx("p",{children:m("CheckoutView.noOrders")}):t.jsx("div",{className:"orders-list-container",children:e==null?void 0:e.map(({cart:p,messages:c})=>t.jsx(yt,{cart:p,messages:c,currentTab:o,openByDefault:a,...s},p._id))})}function yt({openByDefault:a=!1,cart:e,messages:o,openGroupRegDialog:l,pageType:s,currentTab:m,canWrite:p=!0}){var X;const c=Be(n=>n.user.info),{t:r}=q(),[k,v]=i.useState(a),[F,D]=i.useState(null),[I,E]=i.useState(!1),[u,O]=i.useState(_(e)),[y,B]=i.useState(null),[w,$]=i.useState(null),[C,V]=i.useState("");i.useEffect(()=>{if(e.status!=="succeeded")return;const n=new Date(e.orderDate);new Date().getFullYear()>n.getFullYear()||new Date().getMonth()>n.getMonth()||(B(e.orderDate.split("T")[0]),$(z(new Date(e.orderDate),"HH:mm")))},[e.status,e.orderDate]),i.useEffect(()=>{if(!y){V("");return}const n=new Date(y);if(new Date().getFullYear()>n.getFullYear()||new Date().getMonth()>n.getMonth()){V("CheckoutView.orderDateMustBeInCurrentOrFutureMonth");return}V("")},[y]);const[b,h]=i.useState(j),d=me(),x=Ne(e),S=()=>{d.invalidateQueries({queryKey:["orders"]}),e.status==="incompleted"&&d.invalidateQueries({queryKey:["cart",e.key]})},K=ze({onError:x,onSuccess:S}),Z=Le({onError:x,onSuccess:S}),pe=_e({onError:x,onSuccess:S}),he=Me({onError:x,onSuccess:S}),fe=H({mutationFn:n=>Q("/api/cart/confirmManually",{cartId:n,createPaymentDocument:I,amount:u,orderDate:re(Y(y,w)).toISOString()}),retry:!1,onSuccess:S,onError:x}),xe=H({mutationFn:n=>Q("/api/cart/paymentDocument",{cartId:n,amount:u,orderDate:re(Y(y,w)).toISOString()}),retry:!1,onSuccess:S,onError:x}),Ce=H({mutationFn:n=>Qe(`/api/cart/paymentDocument/${n}`),retry:!1,onSuccess:S,onError:x}),ye=n=>{D(n.currentTarget)},R=()=>{D(null)},J=!!F,ge=J?"simple-popover":void 0,f=i.useMemo(()=>{const n=s!=="company"&&!!e.connectCode&&e.status==="incompleted",N=s!=="company"&&e.status==="incompleted",je=s!=="athlete"&&p&&e.status==="incompleted"&&e.items.length>0,ve=s==="admin"&&e.status==="succeeded"&&e.items.some(g=>{var ne;return(ne=g.payment)==null?void 0:ne.amount})&&_(e)>0&&e.items.every(g=>!g.orderDate||new Date(g.orderDate).getFullYear()>=new Date().getFullYear()&&new Date(g.orderDate).getMonth()>=new Date().getMonth()),De=s==="admin"&&e.status==="incompleted"&&e.items.length>0&&_(e)>0,ee=s==="admin"&&e.status==="succeeded"&&e.items.length>0&&e.items.some(g=>g.purchasedPrice>0)&&e.items.every(g=>!g.payment),te={editLabel:n,removeOrder:N,confirmOrder:je,removePaymentDocument:ve,createPaymentDocumentCheckbox:De,createPaymentDocumentButton:ee,paymentDocumentAmount:I||ee},we=m==="open"||s==="admin"&&Object.values(te).some(Boolean);return{...te,editIconVisible:we,editIconInDom:m==="open"||s==="admin"}},[e.status,e.items.length,e.updatedAt,e.items.map(n=>{var N;return(N=n.payment)==null?void 0:N._id}).join(","),I]);return t.jsxs("div",{children:[t.jsxs(qe,{button:!0,className:"order-container",onClick:()=>v(!k),dense:!0,children:[f.editIconInDom&&t.jsx(He,{style:{visibility:f.editIconVisible?"visible":"hidden"},onClick:n=>{n.stopPropagation(),ye(n)},children:f.createPaymentDocumentButton?t.jsx(L,{style:{fontSize:"1.2rem",color:oe["error-red-35"]}}):t.jsx(Ke,{style:{fontSize:"1.2rem"}})}),t.jsxs("div",{className:"item-info",children:[!e.connectCode&&t.jsxs("div",{children:[e.items[0]?t.jsx(gt,{item:e.items[0]}):t.jsx(P,{scale:4,text:r("CheckoutView.emptyCart")}),e.items.length>1&&t.jsxs(W,{color:"textSecondary",variant:"body2",children:[r("General.and")," ",e.items.length-1," ",r("General.more")]})]}),e.connectCode&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx(P,{scale:4,text:e.name||r("CheckoutView.groupReg",{count:1}),style:{maxWidth:"17.5rem",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}}),e.items.length>0&&t.jsxs(W,{color:"textSecondary",variant:"body2",children:[r("CheckoutView.tickets"),": ",e.items.length]})]}),e.status==="incompleted"&&t.jsx(ue,{size:"small",text:e.connectCode})]})]}),t.jsxs("div",{className:"order-info",children:[e.status==="succeeded"&&t.jsx(ot,{cart:e,label:e.orderNumber||""}),t.jsx(W,{color:"textSecondary",variant:"body2",style:{width:"max-content"},children:z(new Date(e.orderDate||e.createdAt),"dd.MM.yyyy H:mm")}),t.jsx(P,{style:{whiteSpace:"nowrap"},scale:5,text:`${(X=_(e)??0)==null?void 0:X.toFixed(2)} ${e.currency}`})]}),t.jsx(et,{open:k})]}),t.jsxs(We,{in:k,className:"cart-items-list-container",children:[e.status==="incompleted"&&t.jsx(Ge,{className:"cart-menu cart-menu-content",children:t.jsx(nt,{cart:e,messages:o,addToCart:K,removeFromCart:Z,editCart:pe,showAddParticipant:!e.connectCode&&s==="athlete",fetchEvents:!1,showRemove:s==="athlete",openParticipantManagement:s!=="athlete",showCheckout:s==="athlete",showSettings:s==="athlete"})}),e.status==="succeeded"&&t.jsx("div",{className:"order-page-cart-items-list",children:t.jsx(tt,{cart:e,showTeam:!0,showRemove:!1,showAddParticipant:!1,showDiscoverEventsButton:!1,addToCart:K,removeFromCart:Z,fetchEvents:!1,countDiscount:!1,openEditPage:s==="athlete",openParticipantManagement:s!=="athlete",showEdit:n=>s==="company"||s==="admin"||s==="athlete"&&(n.athlete===c._id||!e.connectCode)})})]}),t.jsxs(Ae,{id:ge,open:J,anchorEl:F,onClose:R,anchorOrigin:{vertical:"bottom",horizontal:"center"},transformOrigin:{vertical:"top",horizontal:"center"},PaperProps:{style:{width:"18.5rem"}},children:[f.editLabel&&t.jsxs(T,{variant:"text",size:"small",onClick:n=>{n.stopPropagation(),l(e.connectCode),R()},children:[t.jsx(de,{style:{fontSize:"1.2rem",marginRight:"0.5rem"}}),r("CommonFieldNames.edit")," ",r("CommonFieldNames.label").toLowerCase()]}),f.removeOrder&&t.jsxs(T,{variant:"alert-text",size:"small",onClick:n=>{n.stopPropagation(),h({...j,open:!0,promptText:r("CheckoutView.sureWantToDeleteOrder"),onConfirm:()=>
1{R(),h(j),he.mutateAsync(e._id)}})},children:[t.jsx(Ue,{style:{fontSize:"1.2rem",marginRight:"0.5rem"}}),r("Buttons.deleteBtnText")]}),f.confirmOrder&&t.jsxs(T,{variant:"text",size:"small",disabled:(C==null?void 0:C.length)>0,onClick:async n=>{n.stopPropagation(),h({...j,open:!0,titleText:r("CheckoutView.manualConfirmation"),promptText:r("CheckoutView.sureWantToConfirm"),confirmButtonText:r("CommonFieldNames.Confirm"),onConfirm:()=>{R(),h(j),fe.mutateAsync(e._id)}})},children:[t.jsx(L,{style:{fontSize:"1.2rem",marginRight:"0.5rem"}}),r("CheckoutView.confirmManually")]}),f.removePaymentDocument&&t.jsxs(T,{variant:"alert-text",size:"small",onClick:n=>{n.stopPropagation(),h({...j,open:!0,promptText:r("CheckoutView.sureWantToDeletePaymentDocument"),onConfirm:()=>{R(),h(j),Ce.mutateAsync(e._id)}})},children:[t.jsx(L,{style:{fontSize:"1.2rem",marginRight:"0.5rem"}}),r("CheckoutView.deletePaymentDocument")]}),(f.createPaymentDocumentCheckbox||f.createPaymentDocumentButton)&&t.jsxs("div",{style:{minWidth:"9rem",display:"flex",flexFlow:"column",alignItems:"flex-start",gap:"0.4rem",margin:"0.25rem 1rem 0.75rem"},children:[f.createPaymentDocumentButton&&t.jsx("div",{style:{color:oe["error-red-55"],fontSize:"0.9rem",marginTop:"0.5rem"},children:r("CheckoutView.noPaymentDocument")}),f.createPaymentDocumentCheckbox&&t.jsx(Ye,{style:{marginLeft:"-0.6rem",minWidth:"5rem"},FormControlLabelProps:{style:{margin:0,lineHeight:"1.2"}},size:"small",label:r("CheckoutView.createPaymentDocument"),checked:I,onChange:()=>E(n=>!n)}),t.jsx(M,{style:{width:"100%"},label:r("ParticipantsView.payment"),type:"number",size:"small",disabled:!f.paymentDocumentAmount,value:u,endAdornment:e.currency,onChange:n=>O(it(n.target.value))}),t.jsx(M,{style:{width:"100%"},label:r("CommonFieldNames.orderDay"),type:"date",size:"small",value:y||new Date().toISOString().split("T")[0],errorMessage:r(C),onChange:n=>{n.target.value&&n.target.value!==new Date().toISOString().split("T")[0]?$("00:00"):$(null),B(n.target.value)}}),t.jsx(M,{style:{width:"100%"},label:r("CommonFieldNames.orderTime"),type:"time",size:"small",value:w||z(new Date,"HH:mm"),onChange:n=>$(n.target.value)}),f.createPaymentDocumentButton&&t.jsxs(T,{variant:"text",size:"small",disabled:(C==null?void 0:C.length)>0,onClick:async n=>{n.stopPropagation(),h({...j,open:!0,titleText:r("CheckoutView.createPaymentDocument"),promptText:t.jsxs(t.Fragment,{children:[t.jsx("span",{children:r("CheckoutView.sureWantToCreatePaymentDocument")}),t.jsx("br",{}),t.jsx("br",{}),t.jsxs("span",{children:[r("ParticipantsView.payment"),":"," ",u.toFixed(2)," ",e.currency]}),t.jsx("br",{}),t.jsxs("span",{children:[r("CommonFieldNames.orderDate"),":"," ",z(Y(y,w),"dd.MM.yyyy HH:mm")]}),t.jsx("br",{})]}),confirmButtonText:r("CommonFieldNames.Confirm"),onConfirm:()=>{R(),h(j),xe.mutateAsync(e._id)}})},children:[t.jsx(L,{style:{fontSize:"1.2rem",marginRight:"0.5rem"}}),r("CheckoutView.createPaymentDocument")]})]})]}),t.jsx(Xe,{open:b.open,handleClose:()=>h(n=>({...n,open:!1})),onReject:()=>h(n=>({...n,open:!1})),titleText:b.titleText,promptText:b.promptText,confirmButtonText:b.confirmButtonText,onConfirm:b.onConfirm})]})}function gt({item:a,style:e={}}){var l,s,m,p,c,r;const[o]=ce([a],{fetch:!1});return t.jsxs("div",{style:e,children:[t.jsx(P,{scale:4,text:G(o==null?void 0:o.eventName)}),t.jsx(P,{variant:"tertiary",scale:5,text:`${G((s=(l=o==null?void 0:o.distancesV2)==null?void 0:l[a.distanceId])==null?void 0:s.distanceName)||"..."}, ${G((r=(c=(p=(m=o==null?void 0:o.distancesV2)==null?void 0:m[a.distanceId])==null?void 0:p.groups)==null?void 0:c[a.groupId])==null?void 0:r.groupName)||"..."}`}),t.jsx(P,{variant:"secondary",scale:5,text:`${a.personalInfo.firstName} ${a.personalInfo.lastName}`})]})}export{an 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.