"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,l=r?.priceType==="compare",{trigger:m}=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]),v=React.useMemo(()=>s?.discountValue?n?(p||d)*h:d*h:p*h,[s?.discountValue,d,h,p,n]),M=React.useMemo(()=>{let e=d*h;return l?v:b?Math.max(0,e-b):e},[d,h,b,v,l]),R=(e,r)=>{m({event:"price"===r?"gp:rollback:price-change":"gp:rollback:compare-price-change",selector:`[data-id="${t?.uid}"]`,element:c.current}),m({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&&R(d,"price")},[d]),common.useTransition(e=>{e!==p&&R(p,"compare")},[p]);let q=()=>{if("edit"!==o)return;let e=new CustomEvent("editor:product-source-no-data-warning",{bubbles:!0,detail:{uid:t?.uid,value:!M&&l,tag:"ProductPrice"}});window.dispatchEvent(e)},w=core.useFormatMoney(M??0,P||!1),T=l&&!M,V="edit"!==o&&T;return{elementRef:c,moneyFormatted:w,currentProductId:y,isNoComparePrice:T,isNoComparePriceILP:V,emitNoDataSignal:q}};exports.useGpPrice=useGpPrice;
