import{w as U,j as s,c6 as E,ag as W,r as u,c_ as z,a0 as G,T as b,N as K,b2 as Q,c$ as Y,ab as h,v as H,bT as Z,e as N,m as q,cl as V,d0 as X,cV as J,o as ee,Y as y,ck as D,f as C,ac as te,c7 as F,a7 as se,bK as T,d as p,cW as re,cX as w}from"./main-78369d74.js";import{S as ne,l as ae,B as I}from"./billing-redirect-message-6a15a7ad.js";import"./TaskAlt-90bac44f.js";function S({children:t}){const{isLoggedIn:e,isSubscribed:r}=U();return e?e&&r?s.jsx(E,{to:"/billing",replace:!0}):t||s.jsx(W,{}):s.jsx(E,{to:"/register",replace:!0})}function _({children:t}){const[e,r]=t;return u.useEffect(()=>{z("be.onboarding.selected")},[]),s.jsxs(u.Fragment,{children:[s.jsx(G,{children:s.jsx(b,{message:"Checkout"})}),s.jsx(K,{size:"sm",color:"transparent",className:"z-10 mb-20 md:mb-0",textColor:"text-main",logoColor:"dark",darkModeColor:"transparent",menuPosition:"checkout-page-navbar"}),s.jsxs("div",{className:"md:flex w-full mx-auto justify-between px-20 md:px-0 md:pt-128 md:max-w-950",children:[s.jsx("div",{className:"hidden md:block fixed right-0 top-0 w-1/2 h-full bg-alt shadow-[15px_0_30px_0_rgb(0_0_0_/_18%)]"}),s.jsxs("div",{className:"md:w-400 overflow-hidden",children:[e,s.jsx(Q,{menu:"checkout-page-footer",className:"text-xs mt-50 text-muted overflow-x-auto"}),s.jsx("div",{className:"mt-40",children:s.jsx(Y,{})})]}),s.jsx("div",{className:"hidden md:block w-384",children:s.jsx("div",{className:"relative z-10",children:r})})]})]})}const O=t=>`billing/products/${t}`;function ie(){var c;const{productId:t,priceId:e}=h(),r=H({queryKey:[O(t)],queryFn:()=>ce(t),placeholderData:Z,enabled:t!=null&&e!=null}),n=(c=r.data)==null?void 0:c.product,i=(n==null?void 0:n.prices.find(a=>a.id===parseInt(e)))||(n==null?void 0:n.prices[0]);return{status:r.status,product:n,price:i}}function ce(t){return N.get(O(t)).then(e=>e.data)}function L({showBillingLine:t=!0}){const{status:e,product:r,price:n}=ie();return e==="error"||e!=="pending"&&(!r||!n)?null:s.jsxs("div",{children:[s.jsx("h2",{className:"text-2xl mb-30",children:s.jsx(b,{message:"Summary"})}),e==="pending"?s.jsx(ue,{},"loading-skeleton"):s.jsx(oe,{product:r,price:n,showBillingLine:t})]})}function oe({product:t,price:e,showBillingLine:r}){return s.jsxs(q.div,{children:[s.jsx("div",{className:"text-xl font-semibold mb-6",children:t.name}),t.description&&s.jsx("div",{className:"text-sm text-muted",children:t.description}),s.jsx(V,{priceClassName:"font-bold text-4xl",periodClassName:"text-muted text-xs",variant:"separateLine",price:e,className:"mt-32"}),s.jsx(X,{product:t}),r&&s.jsxs("div",{className:"flex items-center justify-between gap-24 border-t pt-24 mt-32 font-medium",children:[s.jsx("div",{children:s.jsx(b,{message:"Billed today"})}),s.jsx("div",{children:s.jsx(J,{value:e.amount,currency:e.currency})})]})]})}function ue(){return s.jsxs(q.div,{...ee,className:"max-w-180",children:[s.jsx(y,{className:"text-xl mb-6"}),s.jsx(y,{className:"text-sm"}),s.jsx(y,{className:"text-4xl mt-32"})]})}/*!
 * paypal-js v7.1.1 (2023-11-27T14:12:58.587Z)
 * 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 le(t,e){var r=document.querySelector('script[src="'.concat(t,'"]'));if(r===null)return null;var n=A(t,e),i=r.cloneNode();if(delete i.dataset.uidAuto,Object.keys(i.dataset).length!==Object.keys(n.dataset).length)return null;var c=!0;return Object.keys(i.dataset).forEach(function(a){i.dataset[a]!==n.dataset[a]&&(c=!1)}),c?r:null}function de(t){var e=t.url,r=t.attributes,n=t.onSuccess,i=t.onError,c=A(e,r);c.onerror=i,c.onload=n,document.head.insertBefore(c,document.head.firstElementChild)}function pe(t){var e="https://www.paypal.com/sdk/js";t.sdkBaseUrl&&(e=t.sdkBaseUrl,delete t.sdkBaseUrl);var r=t,n=Object.keys(r).filter(function(a){return typeof r[a]<"u"&&r[a]!==null&&r[a]!==""}).reduce(function(a,o){var l=r[o].toString();return o=fe(o),o.substring(0,4)==="data"||o==="crossorigin"?a.attributes[o]=l:a.queryParams[o]=l,a},{queryParams:{},attributes:{}}),i=n.queryParams,c=n.attributes;return i["merchant-id"]&&i["merchant-id"].indexOf(",")!==-1&&(c["data-merchant-id"]=i["merchant-id"],i["merchant-id"]="*"),{url:"".concat(e,"?").concat(me(i)),attributes:c}}function fe(t){var e=function(r,n){return(n?"-":"")+r.toLowerCase()};return t.replace(/[A-Z]+(?![a-z])|[A-Z]/g,e)}function me(t){var e="";return Object.keys(t).forEach(function(r){e.length!==0&&(e+="&"),e+=r+"="+t[r]}),e}function A(t,e){e===void 0&&(e={});var r=document.createElement("script");return r.src=t,Object.keys(e).forEach(function(n){r.setAttribute(n,e[n]),n==="data-csp-nonce"&&r.setAttribute("nonce",e["data-csp-nonce"])}),r}function be(t,e){if(e===void 0&&(e=Promise),M(t,e),typeof document>"u")return e.resolve(null);var r=pe(t),n=r.url,i=r.attributes,c=i["data-namespace"]||"paypal",a=P(c);return le(n,i)&&a?e.resolve(a):xe({url:n,attributes:i},e).then(function(){var o=P(c);if(o)return o;throw new Error("The window.".concat(c," global variable is not available."))})}function xe(t,e){e===void 0&&(e=Promise),M(t,e);var r=t.url,n=t.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 e(function(i,c){if(typeof document>"u")return i();de({url:r,attributes:n,onSuccess:function(){return i()},onError:function(){var a=new Error('The script "'.concat(r,'" failed to load. Check the HTTP status code and response body in DevTools to learn more.'));return c(a)}})})}function P(t){return window[t]}function M(t,e){if(typeof t!="object"||t===null)throw new Error("Expected an options object.");if(typeof e<"u"&&typeof e!="function")throw new Error("Expected PromisePonyfill to be a function.")}function he({productId:t,priceId:e}){const{data:r}=D(),n=u.useRef(!1),i=u.useRef(!1),[c,a]=u.useState(!1),o=u.useRef(null),{base_url:l,billing:{stripe:{enable:f},paypal:{enable:x,public_key:d}}}=C();return u.useEffect(()=>{!x||!d||n.current||(be({clientId:d,intent:"subscription",vault:!0,disableFunding:f?"card":void 0}).then(()=>{a(!0)}),n.current=!0)},[d,x,f]),u.useEffect(()=>{var $;if(!c||!(($=window.paypal)!=null&&$.Buttons)||!o.current||!(r!=null&&r.products.length)||!t||!e||i.current)return;const g=r.products.find(m=>m.id===parseInt(t)),j=g==null?void 0:g.prices.find(m=>m.id===parseInt(e));window.paypal.Buttons({style:{label:"pay"},createSubscription:(m,v)=>v.subscription.create({application_context:{shipping_preference:"NO_SHIPPING"},plan_id:j==null?void 0:j.paypal_id}),onApprove:(m,v)=>(v.redirect(`${l}/checkout/${t}/${e}/paypal/done?subscriptionId=${m.subscriptionID}&status=success`),Promise.resolve()),onError:m=>{location.href=`${l}/checkout/${t}/${e}/paypal/done?status=error`}}).render(o.current).then(()=>{i.current=!0})},[t,e,r,c,l]),{paypalElementRef:o,stripeIsEnabled:d!=null&&x}}function ge(){var l;const{productId:t,priceId:e}=h(),r=D(),{paypalElementRef:n}=he({productId:t,priceId:e}),{base_url:i,billing:{stripe:c}}=C();if(r.isLoading)return s.jsx(te,{screen:!0});const a=(l=r.data)==null?void 0:l.products.find(f=>f.id===parseInt(t)),o=a==null?void 0:a.prices.find(f=>f.id===parseInt(e));return!a||!o||r.status==="error"?s.jsx(E,{to:"/pricing",replace:!0}):s.jsxs(_,{children:[s.jsxs(u.Fragment,{children:[s.jsx("h1",{className:"mb-40 text-4xl",children:s.jsx(b,{message:"Checkout"})}),c.enable?s.jsxs(u.Fragment,{children:[s.jsx(ne,{productId:t,priceId:e,submitLabel:s.jsx(b,{message:"Upgrade"}),type:"subscription",returnUrl:`${i}/checkout/${t}/${e}/stripe/done`}),s.jsx(je,{})]}):null,s.jsx("div",{ref:n}),s.jsx("div",{className:"mt-30 text-xs text-muted",children:s.jsx(b,{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."})})]}),s.jsx(L,{})]})}function je(){return s.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:s.jsx("span",{className:"relative z-10 bg px-10 text-sm text-muted",children:s.jsx(b,{message:"or"})})})}function ve(){const{invalidateBootstrapData:t}=F(),{productId:e,priceId:r}=h(),n=se(),{billing:{stripe_public_key:i}}=C(),[c]=T(),a=c.get("payment_intent_client_secret"),[o,l]=u.useState(),f=u.useRef();return u.useEffect(()=>{f.current||(ae(i).then(async x=>{if(!x||!a){l(k());return}x.retrievePaymentIntent(a).then(async({paymentIntent:d})=>{(d==null?void 0:d.status)==="succeeded"?(await ye(d.id),l(k("succeeded",e,r)),window.location.href="/billing"):l(k(d==null?void 0:d.status,e,r))})}),f.current=!0)},[i,a,r,e,t]),a?s.jsxs(_,{children:[s.jsx(I,{config:o}),s.jsx(L,{showBillingLine:!1})]}):(n("/"),null)}function k(t,e,r){switch(t){case"succeeded":return{message:p("Subscription successful!"),status:"success",buttonLabel:p("Return to site"),link:"/billing"};case"processing":return{message:p("Payment processing. We'll update you when payment is received."),status:"success",buttonLabel:p("Return to site"),link:"/billing"};case"requires_payment_method":return{message:p("Payment failed. Please try another payment method."),status:"error",buttonLabel:p("Go back"),link:R(e,r)};default:return{message:p("Something went wrong"),status:"error",buttonLabel:p("Go back"),link:R(e,r)}}}function R(t,e){return t&&e?`/checkout/${t}/${e}`:"/"}function ye(t){return N.post("billing/stripe/store-subscription-details-locally",{payment_intent_id:t})}function we(){const{invalidateBootstrapData:t}=F(),{productId:e,priceId:r}=h(),[n]=T(),[i,c]=u.useState();return u.useEffect(()=>{const a=n.get("subscriptionId"),o=n.get("status");a&&o==="success"?ke(a).then(()=>{c(B("success",e,r)),window.location.href="/billing"}):c(B(o,e,r))},[r,e,n,t]),s.jsxs(_,{children:[s.jsx(I,{config:i}),s.jsx(L,{showBillingLine:!1})]})}function B(t,e,r){switch(t){case"success":return{message:p("Subscription successful!"),status:"success",buttonLabel:p("Return to site"),link:"/billing"};default:return{message:p("Something went wrong. Please try again."),status:"error",buttonLabel:p("Go back"),link:Se(e,r)}}}function Se(t,e){return t&&e?`/checkout/${t}/${e}`:"/"}function ke(t){return N.post("billing/paypal/store-subscription-details-locally",{paypal_subscription_id:t})}function _e(){return s.jsxs(re,{children:[s.jsx(w,{path:":productId/:priceId",element:s.jsx(S,{children:s.jsx(ge,{})})}),s.jsx(w,{path:":productId/:priceId/stripe/done",element:s.jsx(S,{children:s.jsx(ve,{})})}),s.jsx(w,{path:":productId/:priceId/paypal/done",element:s.jsx(S,{children:s.jsx(we,{})})})]})}export{_e as default};
//# sourceMappingURL=checkout-routes-4d617a5a.js.map
