"use strict";var core=require("@gem-sdk/core"),React=require("react"),productBundle=require("../../../helpers/product-bundle.js"),productBundle$1=require("../../constants/product-bundle.js");const useGpDiscountTag=e=>{let{setting:r,...t}=e,{customContent:u}=r??{},o=t["bundle-item"],{moneyFormat:n}=core.useMoneyFormat(),c=core.useEditorMode(),s=core.useProduct(),i=core.useCurrentVariant(),{quantity:a,hasUpdatePrice:d}=core.useQuantity(),p=React.useMemo(()=>d&&u?.unit!=="percentage"?a??1:1,[d,u?.unit,a]),l=core.convertDecimalToNumber(i?.price)??0,m=core.convertDecimalToNumber(i?.salePrice)??0,D=(m-l)*p,g=core.useFormatMoney(D<0?0:D,r?.moneyWithCurrentFormat||!1),M=React.useMemo(()=>{if(!m&&0!==m||!l&&0!==l)return`${u?.unit==="percentage"?"0%":g}`;if(u?.unit==="percentage"){let e=Math.round(D/(m/100));return`${e<0?0:e}%`}return`${g}`},[u?.unit,g,l,D,m]),{useProductCompareAtPrice:y}=core.useProductBundleDiscount(),{discountPercentAmount:B}=productBundle.applyBundleDiscountAmount({currentVariant:i,bundleItem:o,options:{moneyFormat:n,useProductCompareAtPrice:y}}),b=React.useMemo(()=>{if(!o)return 0;let{discountPercentAmount:e,discountAmount:r}=productBundle.applyBundleDiscountAmount({currentVariant:i,bundleItem:o,options:{moneyFormat:n,useProductCompareAtPrice:y}}),{discountType:t}=o,{unit:c}=u||{};return t!==productBundle$1.DiscountType.NoDiscount||y?"percentage"===c?`${e}%`:r:"percentage"===c?"0%":core.formatMoney("0",n)},[o,i,n,y,u]),R=React.useMemo(()=>o?b:M,[b,o,M]),T=s?.baseID?.replace("gid://shopify/Product/",""),$=React.useMemo(()=>{let e=o?B<=0:D<=0;return"edit"===c&&e},[o,B,c,D]);return{mode:c,product:s,salePrice:m,priceSave:D,currentProductId:T,unitCustomDisplay:R,shouldPlaceholderNoDiscount:$}};exports.useGpDiscountTag=useGpDiscountTag;
