'use client';
import{jsx as e,jsxs as r}from"react/jsx-runtime";import{useCurrentVariant as t,useProduct as i,useProductStore as o,convertDecimalToNumber as l,shopifyPriceRounding as s,useProductOfferDiscount as p,useI18nStore as a,useRenderMode as n,useFormatMoney as c,cls as g}from"@gem-sdk/core";import{useMemo as m}from"react";import d from"../../text/components/Text.js";import{useDynamicProduct as u}from"../hooks/useDynamicProduct.js";import f from"../../../common/components/TooltipHover.js";import{calculateSellingPlanDiscount as h}from"../helpers/product-price-breakdown/getPrice.js";import{useSubscriptionSellingType as P}from"../hooks/useSubscriptionSellingType.js";let y=({styles:y,style:x,builderAttrs:b,builderProps:N,children:j,setting:S})=>{let k=t(),D=i(),{isOneTime:F}=P(),v=o(e=>e.selectedSellingPlan),w=l(k?.price)??0,G=l(k?.salePrice)??0,T=parseFloat(s(p(),2)),{isDynamicProduct:I}=u(),{t:J}=a(),{isEditMode:O}=n(),{priceType:$,source:H}=S??{},q="compare"===$,z="offer"===$,A="price"===H,B="compare-price"===H,C=k?.sellingPlanGroups,E=D?.sellingPlanGroups,K=m(()=>{if(!v||F)return null;let e=k?.sellingPlanGroups??D?.sellingPlanGroups??[];for(let r of e)if(r?.sellingPlans){for(let e of r.sellingPlans)if(e?.baseID===v)return e}return null},[JSON.stringify(C),JSON.stringify(E),v,F]),L=JSON.stringify(K?.pricingPolicies),M=K?.baseID,Q=m(()=>!K||w<=0||F?0:h({variantPrice:w,pricingPolicies:K.pricingPolicies}),[L,w,F]),R=m(()=>{let e=z&&!F&&v&&M;if(e){let e=parseFloat(s(w-Q,2)),r=parseFloat(s(e-T,2));return r>0?r:0}let r=parseFloat(s(w-T,2));return r>0?r:0},[z,F,v,M,w,Q,T]),U=m(()=>q?A?w:G:z?R:w,[q,A,z,w,G,R]),V=c(parseFloat(s(Number(U)||0,2)),!1),W=D?.baseID?.replace("gid://shopify/Product/",""),X=m(()=>q&&(!T&&G<w||B&&!G||A&&w<=0),[q,T,w,G,B,A]);return(!U&&!z||X)&&O?e(f,{enable:!0,text:J("Not be displayed when published"),width:"205px",position:"bottom",className:"gp-arrow-left-offset-10",children:e("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("span",{className:"gp-text-dark-400 gp-text-[12px] gp-leading-5",children:J("No compare price")})})}):X&&!O?null:r("div",{...b,className:g(N?.uid),style:{...x},id:`shopify-text-element-${N?.uid}`,"data-product-id":W,children:[e(d,{styles:y,setting:{text:I?"$???":V},className:g({"gp-money":z,"gp-product-compare-price":q,"gp-line-through":q&&y?.lineThrough})}),j]})};export{y as default};
