import{cls as e,convertDecimalToNumber as t,formatMoney as r,makeStyleResponsive as i,getResponsiveValueByScreen as n}from"@gem-sdk/core";import{applyBundleDiscountAmount as o}from"../../../helpers/product-bundle.js";import{DiscountType as u}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,t,i)=>removeTrailingZeros(r(t?(t-e).toFixed(2):"0",i)),getMinPrice=(e,i)=>{let n=e?.edges?.length&&e.edges.length>0?1/0:0;return e?.edges.forEach(({node:e})=>{if(!e)return;let r=t(e?.price);void 0!==r&&r<n&&(n=r)}),removeTrailingZeros(r(n.toString(),i))},checkNoDiscountState=(e,t)=>{let{discountPercentAmount:r}=o({currentVariant:e?.currentVariant,bundleItem:e?.bundleItem,options:{moneyFormat:t,useProductCompareAtPrice:e?.useProductCompareAtPrice}});return!(e?.bundleItem?.discountType===u.NoDiscount&&e?.useProductCompareAtPrice||Number(e?.bundleItem?.discountValue)&&r)&&!e?.currentVariant?.salePrice},getBadgeContent=(e,i,n)=>{if(!e.detail||!i?.trim()?.length)return i;let{detail:c,currentVariant:l}=e,{discountPercentAmount:a,discountAmount:d}=o({currentVariant:l,bundleItem:e?.bundleItem,options:{moneyFormat:n,useProductCompareAtPrice:e?.useProductCompareAtPrice}}),s=()=>e?.bundleItem?.discountType!==u.NoDiscount||e?.useProductCompareAtPrice?Number(e?.bundleItem?.discountValue)>0?`${a}%`:`${getPriceDiffByPercent(t(l?.price)??0,t(l?.salePrice)??0)||0}%`:"0%",p=()=>e?.bundleItem?.discountType!==u.NoDiscount||e?.useProductCompareAtPrice?Number(e?.bundleItem?.discountValue)>0?d:getPriceDiffByValue(t(l?.price)??0,t(l?.salePrice)??0,n):r("0",n),g=new Map([["{percent_discount}",s],["{amount_discount}",p],["{min_price}",()=>getMinPrice(c.variants,n)||0],["{inventory_quantity}",()=>l?.inventoryQuantity||0]]);return[...g.entries()].reduce((e,[t,r])=>e.replaceAll(t,r()),i)},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={},i=["desktop","mobile","tablet"];return i.forEach(i=>{let o=n(e,i,null),u=o?.width||t?.wrapperWidth;u&&(r={...r,[i]:u})}),r},getHeightByShapeSize=(e,t)=>{let r={},i=["desktop","mobile","tablet"];return i.forEach(i=>{let o=n(e,i,null);r={...r,[i]:o?.height||t?.wrapperHeight}}),r},getSize=(e,t)=>{let r=i("w",getWidthByShapeSize(t,e)),n=i("h",getHeightByShapeSize(t,e));return{...r,...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};
