"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:t,...u}=e,{customContent:r}=t??{},o=u["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&&r?.unit!=="percentage"?a??1:1,[d,r?.unit,a]),l=i?.price??0,m=i?.salePrice??0,g=(m-l)*p,M=core.useFormatMoney(g<0?0:g,t?.moneyWithCurrentFormat||!1),y=React.useMemo(()=>{if(!m&&0!==m||!l&&0!==l)return`${r?.unit==="percentage"?"0%":M}`;if(r?.unit==="percentage"){let e=Math.round(g/(m/100));return`${e<0?0:e}%`}return`${M}`},[r?.unit,M,l,g,m]),{useProductCompareAtPrice:D}=core.useProductBundleDiscount(),{discountPercentAmount:B}=productBundle.applyBundleDiscountAmount({currentVariant:i,bundleItem:o,options:{moneyFormat:n,useProductCompareAtPrice:D}}),R=React.useMemo(()=>{if(!o)return 0;let{discountPercentAmount:e,discountAmount:t}=productBundle.applyBundleDiscountAmount({currentVariant:i,bundleItem:o,options:{moneyFormat:n,useProductCompareAtPrice:D}}),{discountType:u}=o,{unit:c}=r||{};return u!==productBundle$1.DiscountType.NoDiscount||D?"percentage"===c?`${e}%`:t:"percentage"===c?"0%":core.formatMoney("0",n)},[o,i,n,D,r]),$=React.useMemo(()=>o?R:y,[R,o,y]),f=s?.baseID?.replace("gid://shopify/Product/",""),b=React.useMemo(()=>{let e=o?B<=0:g<=0;return"edit"===c&&e},[o,B,c,g]);return{mode:c,product:s,salePrice:m,priceSave:g,currentProductId:f,unitCustomDisplay:$,shouldPlaceholderNoDiscount:b}};exports.useGpDiscountTag=useGpDiscountTag;
