import{cls as e,formatMoney as t,makeStyleResponsive as r,getResponsiveValueByScreen as i}from"@gem-sdk/core";import{applyBundleDiscountAmount as n}from"../../../helpers/product-bundle.js";import{DiscountType as o}from"../../constants/product-bundle.js";let removeTrailingZeros=e=>e.replace(/\.00$/,""),getPriceDiffByPercent=(e,t)=>{if(!t)return"0";let r=1e3*t-1e3*e;return Math.round(100*r/(1e3*t))},getPriceDiffByValue=(e,r,i)=>removeTrailingZeros(t(r?(r-e).toFixed(2):"0",i)),getMinPrice=(e,r)=>{let i=e?.edges?.length&&e.edges.length>0?1/0:0;return e?.edges.forEach(({node:e})=>{if(!e)return;let t=e?.price;void 0!==t&&t<i&&(i=t)}),removeTrailingZeros(t(i.toString(),r))},checkNoDiscountState=(e,t)=>{let{discountPercentAmount:r}=n({currentVariant:e?.currentVariant,bundleItem:e?.bundleItem,options:{moneyFormat:t,useProductCompareAtPrice:e?.useProductCompareAtPrice}});return!(e?.bundleItem?.discountType===o.NoDiscount&&e?.useProductCompareAtPrice||Number(e?.bundleItem?.discountValue)&&r)&&!e?.currentVariant?.salePrice},getBadgeContent=(e,r,i)=>{if(!e.detail||!r?.trim()?.length)return r;let{detail:u,currentVariant:c}=e,{discountPercentAmount:l,discountAmount:a}=n({currentVariant:c,bundleItem:e?.bundleItem,options:{moneyFormat:i,useProductCompareAtPrice:e?.useProductCompareAtPrice}}),d=()=>e?.bundleItem?.discountType!==o.NoDiscount||e?.useProductCompareAtPrice?Number(e?.bundleItem?.discountValue)>0?`${l}%`:`${getPriceDiffByPercent(c?.price||0,c?.salePrice||0)||0}%`:"0%",s=()=>e?.bundleItem?.discountType!==o.NoDiscount||e?.useProductCompareAtPrice?Number(e?.bundleItem?.discountValue)>0?a:getPriceDiffByValue(c?.price||0,c?.salePrice||0,i):t("0",i),p=new Map([["{percent_discount}",d],["{amount_discount}",s],["{min_price}",()=>getMinPrice(u.variants,i)||0],["{inventory_quantity}",()=>c?.inventoryQuantity||0]]);return[...p.entries()].reduce((e,[t,r])=>e.replaceAll(t,r()),r)},checkDiscountContentProductBadge=e=>{if(!e)return!1;let t=/\{percent_discount\}|\{amount_discount\}/;return t.test(e)},getShapePlacementClass=(e,t,r="desktop")=>e?t?.[`--pos${deviceWithSurfix(r)}`]?"w-full h-full":"!gp-absolute":t?.[`--d${deviceWithSurfix(r)}`]?"":"!gp-inline-block gp-w-fit",getAlignShape=(t,r)=>r?"":e("gp-flex",{"gp-justify-start":t?.desktop==="left","gp-justify-center":t?.desktop==="center","gp-justify-end":t?.desktop==="right","tablet:gp-justify-start":t?.tablet==="left","tablet:gp-justify-center":t?.tablet==="center","tablet:gp-justify-end":t?.tablet==="right","mobile:gp-justify-start":t?.mobile==="left","mobile:gp-justify-center":t?.mobile==="center","mobile:gp-justify-end":t?.mobile==="right"}),convertToStyle=e=>Object.entries(e||{}).reduce((e,[t,r])=>{let i=new Map([["clipPath","clip-path"],["writingMode","writing-mode"],["borderRadius","border-radius"],["transform","transform"],["alignItems","align-items"],["maxWidth","max-width"]]),n=i.get(t)||t;return{...e,[n]:r}},{}),getWrapperStyle=e=>({[e?"z-index":"zIndex"]:2}),getWidthByShapeSize=(e,t)=>{let r={},n=["desktop","mobile","tablet"];return n.forEach(n=>{let o=i(e,n,null),u=o?.width||t?.wrapperWidth;u&&(r={...r,[n]:u})}),r},getHeightByShapeSize=(e,t)=>{let r={},n=["desktop","mobile","tablet"];return n.forEach(n=>{let o=i(e,n,null);r={...r,[n]:o?.height||t?.wrapperHeight}}),r},getSize=(e,t)=>{let i=r("w",getWidthByShapeSize(t,e)),n=r("h",getHeightByShapeSize(t,e));return{...i,...n}},getShapeWrapperPadding=e=>{let t={};if(1!==e)return t;let r=["desktop","mobile","tablet"];return r.forEach(e=>{t={...t,height:0,[`--p${"desktop"!==e?`-${e}`:""}`]:"50% 0"}}),t},deviceWithSurfix=e=>"desktop"===e?"":`-${e}`,getDeviceSpecificStyle=(e,t)=>{for(let r of({desktop:["desktop"],tablet:["tablet","desktop"],mobile:["mobile","tablet","desktop"]})[t])if(e?.[r])return e[r]},getIsNoDiscountState=({props:e,product:t,currentVariant:r,moneyFormat:i,useProductCompareAtPrice:n})=>{let{setting:o,"bundle-item":u}=e,c=checkDiscountContentProductBadge(o?.displayContent);return c&&checkNoDiscountState({detail:t,currentVariant:r,bundleItem:u,useProductCompareAtPrice:n},i)};export{checkDiscountContentProductBadge,checkNoDiscountState,convertToStyle,deviceWithSurfix,getAlignShape,getBadgeContent,getDeviceSpecificStyle,getIsNoDiscountState,getShapePlacementClass,getShapeWrapperPadding,getSize,getWidthByShapeSize,getWrapperStyle};
