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