"use strict";var React=require("react"),common=require("../../product-variants/common/common.js"),core=require("@gem-sdk/core");const useGpPrice=e=>{let{setting:r,builderProps:c}=e,t=React.useRef(null),o=core.useEditorMode(),{quantity:u,hasUpdatePrice:i}=core.useQuantity(),a=core.useCurrentVariant(),{useProductCompareAtPrice:n}=core.useProductBundleDiscount(),s=e["bundle-item"],d=core.convertDecimalToNumber(a?.price)??0,m=core.convertDecimalToNumber(a?.salePrice)??0,p=r?.priceType==="compare",{trigger:l}=core.useInteraction(),g=core.useProduct(),b=g?.baseID?.replace("gid://shopify/Product/",""),y=core.useShopStore(e=>e.showPriceCurrency),P=React.useMemo(()=>s?.quantity?s.quantity:i&&u||1,[u,i,s?.quantity]),h=React.useMemo(()=>{let e=Number(s?.discountValue);return s?.discountType==="percentage"?d*P*e/100:e},[s?.discountType,s?.discountValue,d,P]),v=React.useMemo(()=>s?.discountValue?n?(m||d)*P:d*P:m*P,[s?.discountValue,d,P,m,n]),M=React.useMemo(()=>{let e=d*P;return p?v:h?Math.max(0,e-h):e},[d,P,h,v,p]),R=React.useMemo(()=>!!p&&(!(m>d)||!(m>=0)),[p,m,d]),T=(e,r)=>{l({event:"price"===r?"gp:rollback:price-change":"gp:rollback:compare-price-change",selector:`[data-id="${c?.uid}"]`,element:t.current}),l({event:"price"===r?"gp:price-change":"gp:compare-price-change",data:e,selector:`[data-id="${c?.uid}"]`,element:t.current})};common.useTransition(e=>{e!==d&&T(d,"price")},[d]),common.useTransition(e=>{e!==m&&T(m,"compare")},[m]);let q=()=>{if("edit"!==o)return;let e=new CustomEvent("editor:product-source-no-data-warning",{bubbles:!0,detail:{uid:c?.uid,value:!M&&p,tag:"ProductPrice"}});window.dispatchEvent(e)},w=core.useFormatMoney(M??0,y||!1),V=p&&!M,D="edit"!==o&&V;return{elementRef:t,moneyFormatted:w,currentProductId:b,isNoComparePrice:V,isNoComparePriceILP:D,emitNoDataSignal:q,shouldHiddenComparePrice:R}};exports.useGpPrice=useGpPrice;
