1import{t as e}from"./axios-D05nDT6A.js";import{t}from"./react-B0xMEQKV.js";import{t as n}from"./Logger-CtWmrqV6.js";import{j as r}from"./schemas-BAjN8wuL.js";import{t as i}from"./service-product-lookup-CdyFWpNq.js";import{a,i as o,n as s,t as c}from"./IProduct-D_0_vJZK.js";import{t as l}from"./ResponseStatus-Do0o1EwQ.js";function u({allRows:e,serviceProductIds:t}){function n(e){return t?.includes(e)??!1}return{productRows:e.filter(e=>!n(e.product?.id)&&!c(e.product?.id)),serviceProductRows:e.filter(e=>n(e.product?.id))}}var d=function(e){return e.REVIEW_DECLINED=`REVIEW_DECLINED`,e.OPPORTUNITY_LOST=`OPPORTUNITY_LOST`,e.OPPORTUNITY_WON=`OPPORTUNITY_WON`,e.LAST_ORDER_DATE_PASSED=`LAST_ORDER_DATE_PASSED`,e.UNDER_REVIEW=`UNDER_REVIEW`,e.NO_DISCOUNT_SET=`NO_DISCOUNT_SET`,e}({});function f(t){if(!e.isAxiosError(t)||!t.response||!t.response.data||!(`discountNotAvailableCause`in t.response.data))return!1;let n=t.response.data;return p(n.discountNotAvailableCause)}function p(e){return Object.values(d).includes(e)}function m(e){if(f(e))return e.response.data.discountNotAvailableCause}async function h({axiosInstance:e,projectDiscountCode:t}){try{return(await e.get(`/api/v1/project/discounts/${t}`)).data}catch(e){let t=e;if(t.response?.status===l.notFound&&t.response?.data.discountNotAvailableCause){if(t.response.data.discountNotAvailableCause===`REVIEW_DECLINED`)throw Error(`REVIEW_DECLINED`);if(t.response.data.discountNotAvailableCause===`OPPORTUNITY_LOST`)throw Error(`OPPORTUNITY_LOST`);if(t.response.data.discountNotAvailableCause===`OPPORTUNITY_WON`)throw Error(`OPPORTUNITY_WON`);if(t.response.data.discountNotAvailableCause===`LAST_ORDER_DATE_PASSED`)throw Error(`LAST_ORDER_DATE_PASSED`);if(t.response.data.discountNotAvailableCause===`UNDER_REVIEW`)throw Error(`UNDER_REVIEW`)}throw e}}function g(e){return e.product.id===s.sku||e.product.id===o.sku}function _(e){return{quantity:e.quantity,maxOrderQuantity:e.maxOrderQuantity,rowTotalSum:e.rowTotalSum,product:e.product}}function v({row:e,serviceProductsMap:t}){let n=i(t,e.product.id);return{quantity:e.quantity,maxOrderQuantity:e.maxOrderQuantity,rowTotalSum:e.rowTotalSum,product:n??e.product}}function y(e){let t=e.shipToAddress;return{companyName:e.companyName??``,receiverName:e.receiverName??``,email:e.email??``,phoneNumber:e.phoneNumber??``,deliveryTypeCode:e.deliveryTypeCode??``,reference:e.reference??``,externalOrderNumber:e.externalOrderNumber??``,additionalDetails:e.additionalDetails??``,requestedDeliveryDate:void 0,promisedDeliveryDate:e.promisedDeliveryDate,shipToAddress:{streetAddress:t?.streetAddress??``,streetAddress2:t?.streetAddress2??``,zipCode:t?.zipCode??``,city:t?.city??``,cities:t?.cities??[],stateProvince:t?.stateProvince,stateProvinceCode:t?.stateProvinceCode,country:t?.country??``,countryCode:t?.countryCode??``}}}function b({order:e,rows:t,discounts:n,serviceProducts:r}){let{productRows:i,serviceProductRows:a}=u({allRows:t,serviceProductIds:r?.ids??[]});return{deliveryDetails:y(e.deliveryDetails),productRows:i.map(_),serviceProductRows:a.map(e=>v({row:e,serviceProductsMap:r?.map})),discounts:n,projectIdDisabled:e.projectIdDisabled}}async function x({axiosInstance:e,projectDiscountCode:t}){if(!t)return{projectDiscountCode:void 0};let n={projectDiscountCode:t};try{let n=await h({axiosInstance:e,projectDiscountCode:t});if(`discountNotAvailableCause`in n)return{projectDiscountCode:void 0};let r=n;return{projectDiscountCode:t,discount:r.basicDiscountPercentage,onlineDiscount:r.onlineProductDiscountPercentage,netPrices:r.netPricesForProducts,percentagePointDiscount:r.percentagePointDiscount,owner:r.projectOwner,discountsRequireManualProcessing:r.discountsRequireManualProcessing}}catch{return n}}var S=`cartStateV2`,C=`cartState`;function w(e,t){return`${S}-${e}-${t}`}function T(e){return e.replace(`${S}-`,`${C}-`)}function E(e){let t=localStorage.getItem(e);if(t)return t;let n=e.substring(0,e.lastIndexOf(`-`)),r=localStorage.getItem(n);return r?(localStorage.removeItem(n),localStorage.setItem(e,r),r):null}function D(e){localStorage.removeItem(e);let t=e.substring(0,e.lastIndexOf(`-`));localStorage.removeItem(t);let n=T(e);if(n!==e){localStorage.removeItem(n);let e=n.substring(0,n.lastIndexOf(`-`));localStorage.removeItem(e)}}function O(e,t){let n=e.cartRows,{productRows:r,serviceProductRows:i}=u({allRows:n.filter(e=>!g(e)),serviceProductIds:t?.ids});return{productRows:r.map(_),serviceProductRows:i.map(e=>v({row:e,serviceProductsMap:t?.map})),deliveryDetails:e.deliveryDetails,discounts:e.discounts,projectIdDisabled:e.projectIdDisabled}}function k(e,t){let{additionalFeesRows:n,...r}=e;return Array.isArray(r.productRows)||!Array.isArray(r.cartRows)?r:O(r,t)}function A(e){let{availability:t,availabilityQty:n,availabilityDate:r,...i}=e;return i}function j(e){return e.deliveryDetails?.requestedDeliveryDate&&(e.deliveryDetails.requestedDeliveryDate=new Date(e.deliveryDetails.requestedDeliveryDate)),e.deliveryDetails?.promisedDeliveryDate&&(e.deliveryDetails.promisedDeliveryDate=new Date(e.deliveryDetails.promisedDeliveryDate)),e.productRows=e.productRows?e.productRows.map(A):[],e.serviceProductRows||(e.serviceProductRows=[]),e}function M(e){let t=e;return{...e,additional_note:t.additional_note===void 0?null:t.additional_note,main_category:t.main_category===void 0?``:t.main_category,antimicrobial_
1coating:t.antimicrobial_coating!==void 0&&t.antimicrobial_coating}}function N(e){return{...e,productRows:(e.productRows??[]).map(e=>({...e,product:M(e.product)}))}}var P={productRows:[],serviceProductRows:[],deliveryDetails:{companyName:``,receiverName:``,email:``,phoneNumber:``,deliveryTypeCode:``,additionalDetails:``,reference:``,externalOrderNumber:``,shipToAddress:{streetAddress:``,streetAddress2:``,zipCode:``,city:``,cities:[],stateProvinceCode:void 0,country:``,countryCode:``}},discounts:{projectDiscountCode:void 0},projectIdDisabled:``};function F({defaults:e,loaded:t}){return t?{...e,...t,deliveryDetails:{...e.deliveryDetails,...t.deliveryDetails,shipToAddress:{...e.deliveryDetails.shipToAddress,...t.deliveryDetails?.shipToAddress}},discounts:t.discounts??e.discounts}:e}function I(e){let t=T(e),n=localStorage.getItem(e);if(n)return{json:n,fromLegacy:!1,legacyKey:t};let r=E(t);return{json:r,fromLegacy:!!r,legacyKey:t}}function L(e,t,n){localStorage.setItem(e,JSON.stringify(n)),localStorage.removeItem(t);let r=t.substring(0,t.lastIndexOf(`-`));localStorage.removeItem(r)}function R({storageKey:e,serviceProducts:t}){let{json:i,fromLegacy:o,legacyKey:s}=I(e);if(!i)return{status:`empty`};let c;try{c=JSON.parse(i)}catch{return{status:`empty`}}if(Array.isArray(c.cartRows)&&!t?.ids.length)return{status:`need-service-products`};let l=N(j(k(c,t)));(o||Array.isArray(c.cartRows))&&L(e,s,l);let u=a.safeParse(l);if(u.success)return{status:`ready`,cart:u.data};n.warn(`Failed to parse cart state, filling missing fields from empty cart`,{storageKey:e,error:r(u.error)});let d=a.safeParse(F({defaults:P,loaded:l}));return d.success?{status:`ready`,cart:d.data}:(n.warn(`Failed to recover cart state`,{storageKey:e,error:r(d.error)}),{status:`empty`})}function z(e,t=!1){let n=t?-1:1;return n*Math.round(n*e*100)/100}function B({productRows:e,serviceProductRows:t,additionalFeesRows:n}){if(e){for(let t of e)if(t.product.price?.currencyCode)return t.product.price.currencyCode}if(t){for(let e of t)if(e.product.price?.currencyCode)return e.product.price.currencyCode}if(n){for(let e of n)if(e.product.price?.currencyCode)return e.product.price.currencyCode}return`EUR`}function V(e){return Number.isFinite(e)}function H({productRows:e,serviceProductRows:t,additionalFeesRows:n=[],discounts:r}){let i=B({productRows:e,serviceProductRows:t,additionalFeesRows:n}),a=e.map(e=>{if(e.quantity>0){let t=c(e.product.id);return{...e,rowTotalSum:U({row:e,discounts:r,ignoreDiscount:t})}}return{...e,rowTotalSum:0}}),o=a.reduce((e,t)=>e+t.rowTotalSum,0),s=t.map(e=>{if(V(e.product.price_factor)){let t=K({productRowsTotal:o,priceFactor:e.product.price_factor});return{...e,rowTotalSum:t,product:{...e.product,price:{price:t,currencyCode:e.product.price?.currencyCode||i}}}}if(e.quantity>0){let t=U({row:e,discounts:r,ignoreDiscount:!0});return{...e,rowTotalSum:t,product:{...e.product,price:{price:t,currencyCode:e.product.price?.currencyCode||i}}}}return{...e,rowTotalSum:0}}),l=n.map(e=>({...e,rowTotalSum:U({row:e,discounts:r,ignoreDiscount:!0})})),u=s.reduce((e,t)=>e+t.rowTotalSum,0),d=l.reduce((e,t)=>e+t.rowTotalSum,0);return{productSubtotal:{price:z(o),currencyCode:i},totalSum:{price:z(o+u+d),currencyCode:i},updatedProductRows:a,updatedServiceProductRows:s,updatedAdditionalFeesRows:l}}function U({row:e,discounts:t,ignoreDiscount:n}){return W({row:e,discounts:n?void 0:t})||0}function W({row:e,discounts:t,fallbackToFullPrice:n=!0,calculateForSingleProduct:r=!1}){let i=r?1:e.quantity,a=e.product;if(t){if(t.percentagePointDiscount){let e=(a.partnerDiscountPercentage||0)+t.percentagePointDiscount;return z(i*a.price.price*(1-e/100),!0)}let e=(t.netPrices||[]).find(e=>e.sku===a.id)?.price;if(e!==void 0)return z(i*e);if(t.onlineDiscount&&G(a))return z(i*a.price.price*(1-t.onlineDiscount/100),!0);if(t.discount)return z(i*a.price.price*(1-t.discount/100),!0)}let o=a.partnerDiscountPrice?a.partnerDiscountPrice.price:n?a.price.price:void 0;return o===void 0?void 0:z(i*o)}function G(e){return!(`sku`in e)&&!(`price_factor`in e)&&`main_category`in e&&e.main_category===`N`}function K({productRowsTotal:e,priceFactor:t}){return z(e*t)}function q({user:e,partnerInfo:t}){return{...structuredClone(P),deliveryDetails:{...P.deliveryDetails,companyName:t.partnerName,receiverName:`${e.firstName} ${e.lastName}`,email:e.email,phoneNumber:t.phoneNumber,shipToAddress:{...P.deliveryDetails.shipToAddress,streetAddress:t.address,streetAddress2:t.address2,zipCode:t.zipCode,countryCode:t.country}}}}function J({rows:e,categories:t}){return e.filter(e=>e.product.categories.every(e=>!t.includes(e)))}function Y(e){let t=H({productRows:e.productRows,serviceProductRows:e.serviceProductRows,additionalFeesRows:[],discounts:e.discounts});return{...e,productRows:t.updatedProductRows,serviceProductRows:t.updatedServiceProductRows}}
1function X(e,t,n){t({shoppingCart:Y(n(e().shoppingCart))}),e().saveShoppingCartToLocalStorage()}var Z=(e,t,n)=>({cartHydrated:!1,storageKey:null,defaultShoppingCart:null,shoppingCart:P,initializeShoppingCart:({user:n,partnerInfo:r,serviceProducts:i})=>{let a=w(n.email,n.partnerId),{cartHydrated:o,storageKey:s}=t();if(o&&s===a)return;let c=s!==null&&s!==a;c&&o&&t().saveShoppingCartToLocalStorage();let l=q({user:n,partnerInfo:r});e({storageKey:a,defaultShoppingCart:l,...c?{shoppingCart:structuredClone(l),cartHydrated:!1}:{}});let u=R({storageKey:a,serviceProducts:i});if(u.status!==`need-service-products`){if(u.status===`empty`){e({shoppingCart:structuredClone(l),cartHydrated:!0});return}e({shoppingCart:Y(F({defaults:l,loaded:u.cart})),cartHydrated:!0})}},setShoppingCart:n=>X(t,e,()=>n),patchShoppingCart:n=>{X(t,e,e=>({...e,...n}))},addProductToShoppingCart:n=>{X(t,e,e=>e.productRows.find(e=>e.product.id===n.product.id)?{...e,productRows:e.productRows.map(e=>e.product.id===n.product.id?{...e,quantity:e.quantity+n.quantity}:e)}:{...e,productRows:[...e.productRows,n]})},setProductQuantity:(n,r)=>{if(r===0){t().removeProductFromShoppingCart(n.product.id);return}X(t,e,e=>e.productRows.some(e=>e.product.id===n.product.id)?{...e,productRows:e.productRows.map(e=>e.product.id===n.product.id?{...e,quantity:r}:e)}:{...e,productRows:[...e.productRows,{...n,quantity:r}]})},removeProductFromShoppingCart:n=>{t().shoppingCart.productRows.some(e=>e.product.id===n)&&X(t,e,e=>({...e,productRows:e.productRows.filter(e=>e.product.id!==n)}))},addServiceProductToShoppingCart:n=>{let r=J({rows:t().shoppingCart.serviceProductRows,categories:n.product.categories});r.push({...n,quantity:1}),X(t,e,e=>({...e,serviceProductRows:r}))},removeServiceProductFromShoppingCart:n=>{let r=J({rows:t().shoppingCart.serviceProductRows,categories:n.categories});X(t,e,e=>({...e,serviceProductRows:r}))},setDiscounts:n=>{X(t,e,e=>({...e,discounts:n??{projectDiscountCode:void 0}}))},clearShoppingCart:()=>{let{storageKey:n,defaultShoppingCart:r}=t();n&&D(n),e({shoppingCart:r?structuredClone(r):P,cartHydrated:!0})},unloadCart:()=>{let{cartHydrated:r,storageKey:i}=t();r&&i&&t().saveShoppingCartToLocalStorage(),e(n.getInitialState())},saveShoppingCartToLocalStorage:()=>{let{cartHydrated:e,storageKey:n}=t();if(!e||!n)return;let r={productRows:t().shoppingCart.productRows,serviceProductRows:t().shoppingCart.serviceProductRows,deliveryDetails:t().shoppingCart.deliveryDetails,projectIdDisabled:t().shoppingCart.projectIdDisabled,discounts:t().shoppingCart.discounts?{projectDiscountCode:t().shoppingCart.discounts?.projectDiscountCode}:void 0};localStorage.setItem(n,JSON.stringify(r))}}),Q=t()((...e)=>{let[t,n,r]=e;return{...Z(...e),reset:()=>{t(r.getInitialState())},invalidSteps:{1:!1,2:!1,3:!1,4:!1},showAllErrors:{1:!1,2:!1,3:!1,4:!1},isInvalidStep:e=>n().invalidSteps[e]===!0,setInvalidSteps:e=>t(t=>({invalidSteps:{...t.invalidSteps,...e}})),showAllErrorsForStep:e=>n().showAllErrors[e]===!0,setShowAllErrors:e=>t(t=>({showAllErrors:{...t.showAllErrors,...e}})),isOrderConfirmed:!1,setConfirmOrder:e=>t({isOrderConfirmed:e}),isCustomerReferenceConfirmed:!1,setConfirmCustomerReference:e=>t({isCustomerReferenceConfirmed:e})}});export{x as a,h as c,u as d,V as i,m as l,W as n,b as o,H as r,d as s,Q as t,p as u}; 2//# sourceMappingURL=use-ordering-store.hook-DIAjjCHa.js.map
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.