import{useMoneyFormat as e,useEditorMode as t,useProduct as r,useCurrentVariant as n,useQuantity as o,convertDecimalToNumber as i,useFormatMoney as u,useProductBundleDiscount as p,formatMoney as c}from"@gem-sdk/core";import{useMemo as s}from"react";import{applyBundleDiscountAmount as a}from"../../../helpers/product-bundle.js";import{DiscountType as m}from"../../constants/product-bundle.js";let l=l=>{let{setting:d,...f}=l,{customContent:g}=d??{},b=f["bundle-item"],{moneyFormat:h}=e(),$=t(),D=r(),j=n(),{quantity:y,hasUpdatePrice:P}=o(),k=s(()=>P&&g?.unit!=="percentage"?y??1:1,[P,g?.unit,y]),x=i(j?.price)??0,C=i(j?.salePrice)??0,F=(C-x)*k,G=u(F<0?0:F,d?.moneyWithCurrentFormat||!1),I=s(()=>{if(!C&&0!==C||!x&&0!==x)return`${g?.unit==="percentage"?"0%":G}`;if(g?.unit==="percentage"){let e=Math.round(F/(C/100));return`${e<0?0:e}%`}return`${G}`},[g?.unit,G,x,F,C]),{useProductCompareAtPrice:M}=p(),{discountPercentAmount:N}=a({currentVariant:j,bundleItem:b,options:{moneyFormat:h,useProductCompareAtPrice:M}}),T=s(()=>{if(!b)return 0;let{discountPercentAmount:e,discountAmount:t}=a({currentVariant:j,bundleItem:b,options:{moneyFormat:h,useProductCompareAtPrice:M}}),{discountType:r}=b,{unit:n}=g||{};return r!==m.NoDiscount||M?"percentage"===n?`${e}%`:t:"percentage"===n?"0%":c("0",h)},[b,j,h,M,g]),W=s(()=>b?T:I,[T,b,I]),q=D?.baseID?.replace("gid://shopify/Product/",""),v=s(()=>{let e=b?N<=0:F<=0;return"edit"===$&&e},[b,N,$,F]);return{mode:$,product:D,salePrice:C,priceSave:F,currentProductId:q,unitCustomDisplay:W,shouldPlaceholderNoDiscount:v}};export{l as useGpDiscountTag};
