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