1import{j as e,I as O,a as x,k as A,B as E,l as k}from"./@themenu-design-system-PPvpWM1I.js";import{f1 as R,B as D,E as y,ci as B,bX as z,L as Y,at as C,bb as $,H as G,f2 as q,b as U,b_ as V,b$ as W,ae as Q,f3 as X}from"./index-DE1OpxQz.js";import{a as u}from"./@analytics-DNf5dJTn.js";import{u as j,M as K,d as S}from"./@react-intl-CKI24l5Z.js";import{A as J}from"./queryIds-DQpqvu2M.js";import{u as Z}from"./useHistoryOrders-DPs1J4xg.js";import{G as ee}from"./GiftMobileAppHeader-BJJ958ln.js";import{S as I}from"./SafeAreaBottomContainer-q4SekFlo.js";import{t as te,v as se}from"./CartItem-BUfXW_sG.js";import{i as re}from"./index-LihOnOsN.js";import{O as ie}from"./OrderEnrollmentStatus-Bsw6JxCJ.js";import"./@react-aria-stately-4PMgXtPH.js";import"./@libphonenumber-js-CKk4m8Ay.js";import"./@luxon-DfZoh-A_.js";import"./@utils-CrEFOnIh.js";import"./@swiper-DRyvN9l1.js";import"./storeGraphql-Ohg8wK-a.js";import"./useProductQuery-D-yywT9I.js";import"./ProductProvider-NkJpu-MM.js";import"./useMobileBottomBarMargin-BN50mBiY.js";try{let t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},s=new t.Error().stack;s&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[s]="506d3ef9-6528-4128-b883-b2297bfcefff",t._sentryDebugIdIdentifier="sentry-dbid-506d3ef9-6528-4128-b883-b2297bfcefff")}catch{}const oe=({page:t})=>{const s=new URLSearchParams({...t?{page:t.toString()}:void 0}).toString();return R({method:"GET",path:`users/me/cse_activity_enrollments?${s}`,shouldFormatResponsePayload:!0})},ae=()=>D({queryKey:[J],queryFn:({pageParam:t})=>oe({page:t}),initialPageParam:1,getNextPageParam:t=>t.meta.hasNext?t.meta.currentPage+1:void 0}),ne=()=>{const{error:t,data:s,isLoading:r,isFetchingNextPage:i,isError:o,fetchNextPage:l,hasNextPage:b}=Z(),h=u.useMemo(()=>((s==null?void 0:s.pages)??[]).flatMap(a=>{var d,N,_;return(_=(N=(d=a.data)==null?void 0:d.activeCustomer)==null?void 0:N.orders)==null?void 0:_.items}).filter(a=>!!a).filter(a=>a.payments.length>0).map(a=>({...a,type:"shop"})),[s]),{error:m,data:f,isLoading:g,isFetchingNextPage:c,isError:P,fetchNextPage:T,hasNextPage:v}=ae(),n=u.useMemo(()=>((f==null?void 0:f.pages)??[]).flatMap(({cseActivityEnrollments:a})=>a).map(a=>({...a,type:"cse_activities"})),[f]),[p,F]=u.useState({cse_activities:!0,shop:!0}),w=u.useMemo(()=>[...n,...h].filter(a=>p[a.type]||Object.values(p).every(d=>!d)).sort((a,d)=>{if(!a||!d)return 0;const N=a.type==="shop"?new Date(a.orderPlacedAt):new Date(a.createdAt),_=d.type==="shop"?new Date(d.orderPlacedAt):new Date(d.createdAt);return N<_?1:-1}),[n,h,p]);return{availableHistoryTypes:u.useMemo(()=>[...h.length?["shop"]:[],...n.length?["cse_activities"]:[]],[n,h]),enrollmentHasNextPage:v,fetchNextPage:()=>{l(),T()},errors:{enrollmentError:m,orderError:t},isError:o||P&&(m==null?void 0:m.status)!==403,isFetchingNextPage:i||c,isLoading:r||g,orderHasNextPage:b,orders:w,selectedHistoryTypes:p,setSelectedHistoryTypes:F}},ce=t=>{const s=[];return t.lines.forEach(r=>{s.find(i=>i.id===r.productVariant.product.id)||s.push(r.productVariant.product)}),s},le=({order:t})=>{const s=y(),r=ce(t),i=s?1:3;let o=[];return r.length>i&&(o=r.slice(i),r.splice(i)),e.jsxs("div",{className:"flex justify-end",children:[e.jsx("div",{className:"flex justify-end",children:r.map((l,b)=>e.jsx(te,{product:l,remainingProducts:b===i-1?o.length:0},l.id))}),e.jsx(O,{name:"chevron-right",size:s?40:48,variant:"text",component:"div"})]})},de=({order:t})=>{const s=j(),r=y(),i="â¢",o=t.orderPlacedAt??t.createdAt,l=o?new Date(o):void 0;return e.jsxs("div",{className:"flex items-center",children:[l&&!Number.isNaN(l.getTime())&&e.jsxs(e.Fragment,{children:[e.jsx(x,{variant:r?"footnote":"body",weight:"normal",children:Intl.DateTimeFormat(`${s.locale}`,{day:"2-digit",month:"long",year:"numeric"}).format(l)}),e.jsx("div",{className:"mx-8",children:i})]}),e.jsx(se,{state:t.state})]})},me=({order:t,onClick:s})=>{const r=y();return e.jsx(A,{"data-testid":"history-details-button",component:"button",action:e.jsx(le,{order:t}),primaryText:e.jsx(x,{variant:r?"body":"headline",children:t.code}),secondaryText:e.jsx(de,{order:t}),onClick:()=>s(t)},t.id)},fe={cse_activities:"gift_history_list.filters.cse_activities",shop:"gift_history_list.filters.shop"},ge=({availableHistoryTypes:t,selectedHistoryTypes:s,toggleType:r})=>t.length<2?null:e.jsx("div",{className:"space-4 my-20 mb-20 flex flex-wrap",children:t.map(i=>{const o=s[i];return e.jsx(E,{className:"m-4 capitalize",variant:o?"secondary":"text",size:32,endIcon:o?"cancel-circle":void 0,onClick:()=>r(i),children:e.jsx(K,{id:fe[i]})},i)})}),ue=({order:t})=>{const s=j(),r=y(),i="â¢",o=new Date(t.createdAt);return e.jsxs("div",{className:"flex items-center",children:[o&&!Number.isNaN(o.getTime())&&e.jsxs(e.Fragment,{children:[e.jsx(x,{variant:r?"footnote":"body",weight:"normal",children:Intl.DateTimeFormat(`${s.locale}`,{day:"2-digit",month:"long",year:"numeric"}
1).format(o)}),e.jsx("div",{className:"mx-8",children:i})]}),e.jsx(ie,{status:t.status,waitingForPayment:re(t,t.cseActivity)})]})},he=({order:t,onClick:s})=>{const r=y();return e.jsx(A,{"data-testid":"history-details-button",component:"button",action:e.jsx(O,{name:"chevron-right",size:r?40:48,variant:"text",component:"div"}),primaryText:e.jsx(x,{variant:r?"body":"headline",children:t.cseActivity.title}),secondaryText:e.jsx(ue,{order:t}),onClick:()=>s(t)},t.id)},M=S({emptyHistory:{id:"gift_history.empty_label",defaultMessage:"No order for the momentâ¦"},offers:{id:"gift_history.offers_label",defaultMessage:"See current offers"}}),pe=()=>{const t=j();return e.jsxs("div",{className:"flex h-[80vh] flex-col items-center justify-center rounded-sm px-32 pt-32 pb-20 text-background-contrast md:h-[300px] dark:text-background-contrast-dark",children:[e.jsx("span",{className:"text-[70px]",role:"img","aria-label":"no-history",children:"ð"}),e.jsx(x,{variant:"h3",align:"center",children:t.formatMessage(M.emptyHistory)}),e.jsx(B,{className:"no-underline hover:bg-transparent",to:"/gift",children:e.jsx(E,{size:48,mt:24,children:t.formatMessage(M.offers)})})]})},xe=({onOrderClick:t})=>{var v;const s=j(),{availableHistoryTypes:r,enrollmentHasNextPage:i,errors:o,fetchNextPage:l,isError:b,isFetchingNextPage:h,isLoading:m,orderHasNextPage:f,orders:g,selectedHistoryTypes:c,setSelectedHistoryTypes:P}=ne(),T=u.useMemo(()=>g.length===0?!1:c.cse_activities&&c.shop||!c.cse_activities&&!c.shop?i||f:!c.cse_activities&&c.shop?f:i,[g,i,f,c]);if(!m&&b){const n=(v=o.orderError)==null?void 0:v.errors,p=o.enrollmentError;return e.jsx(z,{errors:n??void 0,apiError:p??void 0})}return e.jsxs(e.Fragment,{children:[e.jsx(ge,{availableHistoryTypes:r,selectedHistoryTypes:c,toggleType:n=>P({...c,[n]:!c[n]})}),e.jsx(Y,{isLoading:m,mode:"spinner",height:"150px",children:g&&g.length>0?e.jsx("div",{className:"mb-16 rounded-sm border border-border-default border-solid p-8 dark:border-border-default-dark",children:e.jsx(k,{type:"button",size:72,hideBorder:!0,children:g.map(n=>L(n)?e.jsx(he,{order:n,onClick:t},n.id):e.jsx(me,{order:n,onClick:t},n.id))})}):e.jsx(pe,{})}),!m&&T?e.jsx("div",{className:"mb-16 flex justify-center",children:e.jsx(I,{children:e.jsx(E,{size:48,variant:"secondary",onClick:l,loading:h,children:s.formatMessage({id:"gift_history_list.load_more"})})})}):e.jsx(I,{className:"flex"})]})},H=S({title:{id:"gift_history_list.title",defaultMessage:"Order history"}}),ye=()=>{const t=j(),s=y(),{isMobileApp:r}=C(),{titlePageRef:i}=$();return r?null:e.jsxs(e.Fragment,{children:[e.jsx(G,{children:e.jsxs("title",{children:[t.formatMessage(H.title)," - ",t.formatMessage({id:"gift.main_title"})," - Swile"]})}),e.jsx(x,{pb:16,variant:s?"h3":"h2",component:"h1",align:s?"center":"left",tabIndex:-1,ref:i,children:t.formatMessage(H.title)})]})},be="/gift/history-order",je="/gift/cse-activity-enrollments",L=t=>"cseActivity"in t,ze=()=>{q();const{trackPage:t}=V(),s=U(),{isMobileApp:r}=C(),i=o=>{L(o)?s(`${je}/${o.id}`):s(`${be}/${o.id}`)};return u.useEffect(()=>{t(W.OrderHistory)},[t]),e.jsx(Q,{backgroundColor:"default",rightLayout:e.jsx(e.Fragment,{}),leftLayout:!r&&e.jsx(X,{}),mobileAppHeader:e.jsx(ee,{withHistoryButton:!1,withCartButton:!1}),children:e.jsxs("div",{className:"pt-4 md:pt-0",children:[e.jsx(ye,{}),e.jsx(xe,{onOrderClick:i})]})})};export{ze as HistoryPage,ze as default,L as isCseActivityOrder};
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.