'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("@gem-sdk/core"),i=require("react"),s=require("../../text/components/Text.js"),o=require("../hooks/useDynamicProduct.js"),t=require("../../../common/components/TooltipHover.js"),l=require("../helpers/product-price-breakdown/getPrice.js"),n=require("../hooks/useSubscriptionSellingType.js");exports.default=({styles:u,style:p,builderAttrs:a,builderProps:c,children:d,setting:g})=>{let m=r.useCurrentVariant(),f=r.useProduct(),{isOneTime:P}=n.useSubscriptionSellingType(),h=r.useProductStore(e=>e.selectedSellingPlan),y=r.convertDecimalToNumber(m?.price)??0,x=r.convertDecimalToNumber(m?.salePrice)??0,b=parseFloat(r.shopifyPriceRounding(r.useProductOfferDiscount(),2)),{isDynamicProduct:j}=o.useDynamicProduct(),{t:N}=r.useI18nStore(),{isEditMode:S}=r.useRenderMode(),{priceType:D,source:q}=g??{},v="compare"===D,M="offer"===D,T="price"===q,k="compare-price"===q,F=m?.sellingPlanGroups,R=f?.sellingPlanGroups,O=i.useMemo(()=>{if(!h||P)return null;let e=m?.sellingPlanGroups??f?.sellingPlanGroups??[];for(let r of e)if(r?.sellingPlans){for(let e of r.sellingPlans)if(e?.baseID===h)return e}return null},[JSON.stringify(F),JSON.stringify(R),h,P]),w=JSON.stringify(O?.pricingPolicies),G=O?.baseID,I=i.useMemo(()=>!O||y<=0||P?0:l.calculateSellingPlanDiscount({variantPrice:y,pricingPolicies:O.pricingPolicies}),[w,y,P]),J=i.useMemo(()=>{let e=M&&!P&&h&&G;if(e){let e=parseFloat(r.shopifyPriceRounding(y-I,2)),i=parseFloat(r.shopifyPriceRounding(e-b,2));return i>0?i:0}let i=parseFloat(r.shopifyPriceRounding(y-b,2));return i>0?i:0},[M,P,h,G,y,I,b]),$=i.useMemo(()=>v?T?y:x:M?J:y,[v,T,M,y,x,J]),_=r.useFormatMoney(parseFloat(r.shopifyPriceRounding(Number($)||0,2)),!1),C=f?.baseID?.replace("gid://shopify/Product/",""),H=i.useMemo(()=>v&&(!b&&x<y||k&&!x||T&&y<=0),[v,b,y,x,k,T]);return(!$&&!M||H)&&S?e.jsx(t.default,{enable:!0,text:N("Not be displayed when published"),width:"205px",position:"bottom",className:"gp-arrow-left-offset-10",children:e.jsx("div",{className:"gp-h-[28px] gp-px-1.5 gp-py-1 gp-flex gp-border gp-border-light-200 gp-items-center gp-justify-center gp-rounded-lg",style:{borderStyle:"dashed",strokeDasharray:"2,2"},children:e.jsx("span",{className:"gp-text-dark-400 gp-text-[12px] gp-leading-5",children:N("No compare price")})})}):H&&!S?null:e.jsxs("div",{...a,className:r.cls(c?.uid),style:{...p},id:`shopify-text-element-${c?.uid}`,"data-product-id":C,children:[e.jsx(s.default,{styles:u,setting:{text:j?"$???":_},className:r.cls({"gp-money":M,"gp-product-compare-price":v,"gp-line-through":v&&u?.lineThrough})}),d]})};
