import{bz as z,j as s,aB as E,O as U,r as u,cO as W,L as G,T as b,bA as H,C as Q,cP as J,aH as h,a as K,k as Y,b as N,o as A,ba as Z,cQ as V,cJ as X,H as ee,J as y,b9 as O,u as C,aM as te,aJ as q,aI as se,bR as D,m as p,cK as re,cL as w}from"./main-d4af3e3c.js";import{S as ne,l as ae,B as F}from"./billing-redirect-message-703a8e38.js";import"./TaskAlt-c6a46604.js";function S({children:t}){const{isLoggedIn:e,isSubscribed:r}=z();return e?e&&r?s.jsx(E,{to:"/billing",replace:!0}):t||s.jsx(U,{}):s.jsx(E,{to:"/register",replace:!0})}function L({children:t}){const[e,r]=t;return u.useEffect(()=>{W("be.onboarding.selected")},[]),s.jsxs(u.Fragment,{children:[s.jsx(G,{children:s.jsx(b,{message:"Checkout"})}),s.jsx(H,{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(J,{})})]}),s.jsx("div",{className:"hidden md:block w-384",children:s.jsx("div",{className:"relative z-10",children:r})})]})]})}const I=t=>`billing/products/${t}`;function ie(){var c;const{productId:t,priceId:e}=h(),r=K({queryKey:[I(t)],queryFn:()=>ce(t),placeholderData:Y,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(I(t)).then(e=>e.data)}function _({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(A.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(Z,{priceClassName:"font-bold text-4xl",periodClassName:"text-muted text-xs",variant:"separateLine",price:e,className:"mt-32"}),s.jsx(V,{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(X,{value:e.amount,currency:e.currency})})]})]})}function ue(){return s.jsxs(A.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.0.3 (2023-09-19T14:17:47.731Z)
 * 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=T(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=T(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"?a.dataAttributes[o]=l:a.queryParams[o]=l,a},{queryParams:{},dataAttributes:{}}),i=n.queryParams,c=n.dataAttributes;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)),dataAttributes: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 T(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.dataAttributes,c=i["data-namespace"]||"paypal",a=R(c);return le(n,i)&&a?e.resolve(a):xe({url:n,attributes:i},e).then(function(){var o=R(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 R(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}=O(),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 P;if(!c||!((P=window.paypal)!=null&&P.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=O(),{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(L,{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(_,{})]})}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}=q(),{productId:e,priceId:r}=h(),n=se(),{billing:{stripe_public_key:i}}=C(),[c]=D(),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(L,{children:[s.jsx(F,{config:o}),s.jsx(_,{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:B(e,r)};default:return{message:p("Something went wrong"),status:"error",buttonLabel:p("Go back"),link:B(e,r)}}}function B(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}=q(),{productId:e,priceId:r}=h(),[n]=D(),[i,c]=u.useState();return u.useEffect(()=>{const a=n.get("subscriptionId"),o=n.get("status");a&&o==="success"?ke(a).then(()=>{c($("success",e,r)),window.location.href="/billing"}):c($(o,e,r))},[r,e,n,t]),s.jsxs(L,{children:[s.jsx(F,{config:i}),s.jsx(_,{showBillingLine:!1})]})}function $(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 Le(){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{Le as default};
//# sourceMappingURL=checkout-routes-bb758a52.js.map
