Liferay.Loader.define("commerce-frontend-js@4.0.75/components/mini_cart/util/index",["module","exports","require","frontend-js-web","./constants"],(function(e,t,a){window;Object.defineProperty(t,"__esModule",{value:!0}),t.parseOptions=function parseOptions(e){let t;try{t=JSON.parse(e)||""}catch(e){t=""}return Array.isArray(t)?t.map((({value:e})=>"".concat(e))).join(", "):t},t.regenerateOrderDetailURL=function regenerateOrderDetailURL(e,t){if(!e||!t)throw new Error('Cannot generate a new Order Detail URL. Invalid "'.concat(t?"orderUUID":"siteDefaultURL",'"'));const a=new URL("".concat(t).concat(r.ORDER_DETAILS_ENDPOINT));return a.searchParams.append("p_p_id",r.DEFAULT_ORDER_DETAILS_PORTLET_ID),a.searchParams.append("p_p_lifecycle","0"),a.searchParams.append("_".concat(r.DEFAULT_ORDER_DETAILS_PORTLET_ID,"_mvcRenderCommandName"),"/commerce_open_order_content/edit_commerce_order"),a.searchParams.append("_".concat(r.DEFAULT_ORDER_DETAILS_PORTLET_ID,"_").concat(r.ORDER_UUID_PARAMETER),e),a.toString()},t.generateProductPageURL=function generateProductPageURL(e,t,a){const n=themeDisplay.getLanguageId();let r=t[n];if(!r){const e=themeDisplay.getDefaultLanguageId();r=t[e]}return[e,a,r].map((e=>e.replace(/^\//,"").replace(/\/$/,""))).join("/")},t.summaryDataMapper=function summaryDataMapper({itemsQuantity:e,subtotalDiscountValueFormatted:t,subtotalFormatted:a,totalDiscountValueFormatted:n,totalFormatted:r}){return[{label:Liferay.Language.get("quantity"),value:e},{label:Liferay.Language.get("subtotal"),value:a},{label:Liferay.Language.get("subtotal-discount"),value:t},{label:Liferay.Language.get("order-discount"),value:n},{label:Liferay.Language.get("total"),style:"big",value:r}]},t.hasErrors=function hasErrors(e){return e.some((({errorMessages:e})=>Boolean(null==e?void 0:e.length)))},t.getCorrectedQuantity=function getCorrectedQuantity(e,t,a,o){const{allowedOrderQuantities:s,maxOrderQuantity:u,minOrderQuantity:i,multipleOrderQuantity:_}=o?o.productConfiguration:e.productConfiguration;let c;!o&&s.length||(c=i);const l=a.find((t=>t.productId===e.productId||t.sku===e.sku)),d=s[s.length-1];if(l){if(s.length){const e=s.find((e=>_>1?e>l.quantity&&e%_==0:e>l.quantity));if(s.forEach((t=>{t>l.quantity&&(c=e-l.quantity)})),_>1&&!e)return(0,n.openToast)({message:(0,n.sub)(r.PRODUCT_QUANTITY_NOT_VALID_ERROR),type:"danger"}),0;l.quantity>=d&&(c=0)}else l.quantity>=_&&(c=_);if(l.quantity+c>u)return(0,n.openToast)({message:(0,n.sub)(r.MAXIMUM_PRODUCT_QUANTITY_NOT_VALID_ERROR,u),type:"danger"}),0}else if(s.length){if(c=s.find((e=>e>=i&&e%_==0)),u<s[0])return(0,n.openToast)({message:(0,n.sub)(r.MAXIMUM_PRODUCT_QUANTITY_NOT_VALID_ERROR,u),type:"danger"}),0;if(i>d)return(0,n.openToast)({message:(0,n.sub)(r.MINIMUM_PRODUCT_QUANTITY_NOT_VALID_ERROR,i),type:"danger"}),0}else if(_>i){if(c=_,_>u)return(0,n.openToast)({message:(0,n.sub)(r.MAXIMUM_PRODUCT_QUANTITY_NOT_VALID_ERROR,u),type:"danger"}),0}else if(_<i)for(c=_;c<i;)c+=_;if(_>1&&c%_!=0)return(0,n.openToast)({message:(0,n.sub)(r.PRODUCT_MULTIPLE_OF_QUANTITY_NOT_VALID_ERROR,_),type:"danger"}),0;0===c&&(0,n.openToast)({message:(0,n.sub)(r.MAXIMUM_ALLOWED_QUANTITY_NOT_VALID_ERROR,t,d>1?d:u),type:"danger"});return c};var n=a("frontend-js-web"),r=a("./constants")}));
//# sourceMappingURL=index.js.map