"use strict";exports.id=4555,exports.ids=[4555],exports.modules={44555:(e,t,n)=>{n.a(e,async(e,r)=>{try{n.d(t,{Aj:()=>useOrder,MH:()=>useSavePaymentMethod,fY:()=>useOrderPayment,j_:()=>useDownloadableProductOrders,xp:()=>useGetPaymentIntent});var a=n(61175),o=n(77649),u=n(54574),s=n(11163),d=n(45009),i=n(86201),l=n(35599),c=n.n(l),y=n(89699),m=n.n(y),P=n(75795),f=n.n(P),O=e([u,i]);function useDownloadableProductOrders(e){let t={...e},{data:n,isLoading:r,error:s,fetchNextPage:d,hasNextPage:i,isFetching:l,isFetchingNextPage:c}=(0,a.useInfiniteQuery)([o.P.ORDERS_DOWNLOADS,t],({queryKey:e,pageParam:t})=>u.Z.orders.downloadable(Object.assign({},e[1],t)),{getNextPageParam:({current_page:e,last_page:t})=>t>e&&{page:e+1}});return{downloadableFiles:n?.pages.flatMap(e=>e.data)??[],isLoading:r,error:s,hasNextPage:i,isFetching:l,isLoadingMore:c,loadMore:function(){d()}}}function useOrder({tracking_number:e}){let{data:t,isLoading:n,error:r,isFetching:s,refetch:d}=(0,a.useQuery)([o.P.ORDERS,e],()=>u.Z.orders.get(e),{refetchOnWindowFocus:!1});return{order:t,isFetching:s,isLoading:n,refetch:d,error:r}}function useGetPaymentIntent({tracking_number:e,payment_gateway:t,recall_gateway:n,form_change_gateway:r}){let i=(0,s.useRouter)(),{openModal:l}=(0,d.SO)(),{data:y,isLoading:P,error:O,refetch:p,isFetching:_}=(0,a.useQuery)([o.P.PAYMENT_INTENT,{tracking_number:e,payment_gateway:t,recall_gateway:n}],()=>u.Z.orders.getPaymentIntent({tracking_number:e,payment_gateway:t,recall_gateway:n}),{enabled:!1,onSuccess:e=>{let t="";if(c()(e)?(t={...e},t=m()(t)?[]:t[0]):f()(e)&&(t=e),t?.payment_intent_info?.is_redirect)return i.push(t?.payment_intent_info?.redirect_url);n&&window.location.reload(),l("PAYMENT_MODAL",{paymentGateway:t?.payment_gateway,paymentIntentInfo:t?.payment_intent_info,trackingNumber:t?.tracking_number})}});return{data:y,getPaymentIntentQuery:p,isLoading:P,error:O}}function useOrderPayment(){let e=(0,a.useQueryClient)(),{mutate:t,isLoading:n}=(0,a.useMutation)(u.Z.orders.payment,{onSettled:t=>{e.refetchQueries(o.P.ORDERS),e.refetchQueries(o.P.ORDERS_DOWNLOADS)},onError:e=>{let{response:{data:t}}=e??{};i.default.error(t?.message)}});return{createOrderPayment:function(e){let n={...e};t(n)},isLoading:n}}function useSavePaymentMethod(){let{mutate:e,isLoading:t,error:n,data:r}=(0,a.useMutation)(u.Z.orders.savePaymentMethod);return{savePaymentMethod:e,data:r,isLoading:t,error:n}}[u,i]=O.then?(await O)():O,r()}catch(e){r(e)}})}};