import{e as w,r as f,g as j,b3 as $,j as i,bt as k,bn as C,T as m}from"./main-TIUJvpaR.js";import{b as E}from"./billing-queries-D1QXfRse.js";import{C as N,a as B}from"./checkout-product-summary-CrBTjCGM.js";import{S as T}from"./stripe-elements-form-Bon11s_f.js";import"./formatted-price-BnJL0Dzb.js";import"./skeleton-uSF3jNnm.js";import"./product-feature-list-jOnIJ0MT.js";import"./index-U9JJOqTM.js";/*!
 * paypal-js v8.4.2 (2025-09-04T17:21:30.135Z)
 * Copyright 2020-present, PayPal, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function _(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(r[n[a]]=e[n[a]]);return r}function L(e,t){var r=document.querySelector('script[src="'.concat(e,'"]'));if(r===null)return null;var n=S(e,t),a=r.cloneNode();if(delete a.dataset.uidAuto,Object.keys(a.dataset).length!==Object.keys(n.dataset).length)return null;var s=!0;return Object.keys(a.dataset).forEach(function(o){a.dataset[o]!==n.dataset[o]&&(s=!1)}),s?r:null}function q(e){var t=e.url,r=e.attributes,n=e.onSuccess,a=e.onError,s=S(t,r);s.onerror=a,s.onload=n,document.head.insertBefore(s,document.head.firstElementChild)}function A(e){var t=e.sdkBaseUrl,r=e.environment,n=_(e,["sdkBaseUrl","environment"]),a=t||U(r),s=n,o=Object.keys(s).filter(function(c){return typeof s[c]<"u"&&s[c]!==null&&s[c]!==""}).reduce(function(c,p){var b=s[p].toString();return p=I(p),p.substring(0,4)==="data"||p==="crossorigin"?c.attributes[p]=b:c.queryParams[p]=b,c},{queryParams:{},attributes:{}}),u=o.queryParams,l=o.attributes;return u["merchant-id"]&&u["merchant-id"].indexOf(",")!==-1&&(l["data-merchant-id"]=u["merchant-id"],u["merchant-id"]="*"),{url:"".concat(a,"?").concat(R(u)),attributes:l}}function I(e){var t=function(r,n){return(n?"-":"")+r.toLowerCase()};return e.replace(/[A-Z]+(?![a-z])|[A-Z]/g,t)}function R(e){var t="";return Object.keys(e).forEach(function(r){t.length!==0&&(t+="&"),t+=r+"="+e[r]}),t}function U(e){return e==="sandbox"?"https://www.sandbox.paypal.com/sdk/js":"https://www.paypal.com/sdk/js"}function S(e,t){t===void 0&&(t={});var r=document.createElement("script");return r.src=e,Object.keys(t).forEach(function(n){r.setAttribute(n,t[n]),n==="data-csp-nonce"&&r.setAttribute("nonce",t["data-csp-nonce"])}),r}function F(e,t){if(t===void 0&&(t=Promise),O(e,t),typeof document>"u")return t.resolve(null);var r=A(e),n=r.url,a=r.attributes,s=a["data-namespace"]||"paypal",o=g(s);return a["data-js-sdk-library"]||(a["data-js-sdk-library"]="paypal-js"),L(n,a)&&o?t.resolve(o):P({url:n,attributes:a},t).then(function(){var u=g(s);if(u)return u;throw new Error("The window.".concat(s," global variable is not available."))})}function P(e,t){t===void 0&&(t=Promise),O(e,t);var r=e.url,n=e.attributes;if(typeof r!="string"||r.length===0)throw new Error("Invalid url.");if(typeof n<"u"&&typeof n!="object")throw new Error("Expected attributes to be an object.");return new t(function(a,s){if(typeof document>"u")return a();q({url:r,attributes:n,onSuccess:function(){return a()},onError:function(){var o=new Error('The script "'.concat(r,'" failed to load. Check the HTTP status code and response body in DevTools to learn more.'));return s(o)}})})}function g(e){return window[e]}function O(e,t){if(typeof e!="object"||e===null)throw new Error("Expected an options object.");var r=e.environment;if(r&&r!=="production"&&r!=="sandbox")throw new Error('The `environment` option must be either "production" or "sandbox".');if(typeof t<"u"&&typeof t!="function")throw new Error("Expected PromisePonyfill to be a function.")}function Q({productId:e,priceId:t}){const{data:r}=w(E.products.index()),n=f.useRef(!1),a=f.useRef(!1),[s,o]=f.useState(!1),u=f.useRef(null),{base_url:l,billing:{stripe:{enable:c},paypal:{enable:p,public_key:b}}}=j();return f.useEffect(()=>{!p||!b||n.current||(F({clientId:b,intent:"subscription",vault:!0,disableFunding:c?"card":void 0}).then(()=>{o(!0)}),n.current=!0)},[b,p,c]),f.useEffect(()=>{var x;if(!s||!((x=window.paypal)!=null&&x.Buttons)||!u.current||!(r!=null&&r.products.length)||!e||!t||a.current)return;const h=r.products.find(d=>d.id===parseInt(e)),y=h==null?void 0:h.prices.find(d=>d.id===parseInt(t));window.paypal.Buttons({style:{label:"pay"},createSubscription:(d,v)=>v.subscription.create({application_context:{shipping_preference:"NO_SHIPPING",return_url:`${l}/checkout/${e}/${t}/paypal/done?subscriptionId=${d.subscriptionID}&status=success`,cancel_url:`${l}/checkout/${e}/${t}/paypal/done?status=error`},plan_id:y==null?void 0:y.paypal_id}),onApprove:(d,v)=>(v.redirect(`${l}/checkout/${e}/${t}/paypal/done?subscriptionId=${d.subscriptionID}&status=success`),Promise.resolve()),onError:d=>{location.href=`${l}/checkout/${e}/${t}/paypal/done?status=error`}}).render(u.current).then(()=>{a.current=!0})},[e,t,r,s,l]),{paypalElementRef:u,stripeIsEnabled:b!=null&&p}}function J(){var l;const{productId:e,priceId:t}=$(),r=w(E.products.index()),{paypalElementRef:n}=Q({productId:e,priceId:t}),{base_url:a,billing:{stripe:s}}=j();if(r.isLoading)return i.jsx(k,{screen:!0});const o=(l=r.data)==null?void 0:l.products.find(c=>c.id===parseInt(e)),u=o==null?void 0:o.prices.find(c=>c.id===parseInt(t));return!o||!u||r.status==="error"?i.jsx(C,{to:"/pricing",replace:!0}):i.jsxs(N,{children:[i.jsxs(f.Fragment,{children:[i.jsx("h1",{className:"mb-40 text-4xl",children:i.jsx(m,{message:"Checkout"})}),s.enable?i.jsxs(f.Fragment,{children:[i.jsx(T,{productId:e,priceId:t,submitLabel:i.jsx(m,{message:"Upgrade"}),type:"subscription",returnUrl:`${a}/checkout/${e}/${t}/stripe/done`}),i.jsx(W,{})]}):null,i.jsx("div",{ref:n}),i.jsx("div",{className:"mt-30 text-xs text-muted",children:i.jsx(m,{message:"You’ll be charged until you cancel your subscription. Previous charges won’t be refunded when you cancel unless it’s legally required. Your payment data is encrypted and secure. By subscribing your agree to our terms of service and privacy policy."})})]}),i.jsx(B,{})]})}function W(){return i.jsx("div",{className:"relative my-20 text-center before:absolute before:left-0 before:top-1/2 before:h-1 before:w-full before:-translate-y-1/2 before:bg-divider",children:i.jsx("span",{className:"relative z-10 bg px-10 text-sm text-muted",children:i.jsx(m,{message:"or"})})})}export{J as Component};
