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