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