(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[228],{4153:function(e,t,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/buy",function(){return n(1486)}])},1486:function(e,t,n){"use strict";n.r(t),n.d(t,{__N_SSG:function(){return O}});var i=n(5893),o=n(822),c=n(9417),r=n(8629),a=n(5861),s=n(5551),l=n(2761),u=n(7294),d=n(7022),h=n(5605),p=n(8090),v=n(1286),m=n(8456),g=n(2584),_=n(1040),k=n(6925),b=n(1482),f=n(5817),x=n(4790),w=n(4134),C=n(2830),y=n(3960),j=n(4710),N=n(6601);let E=(0,s.ZL)()(e=>({title:{margin:"2em auto",textTransform:"uppercase",[e.breakpoints.down("sm")]:{margin:"0 auto 1em"}},productInfo:{margin:"auto","& h5":{padding:"16px"}},tableRow:{border:"none"},paddleContainer:{display:"block",margin:"2em"},thanksText:{margin:"2em 0",[e.breakpoints.down("sm")]:{margin:".5em 0"}},button:{[e.breakpoints.down("sm")]:{margin:"2em 0"}},hideCheckout:{display:"none"},periodPrice:{textAlign:"right",marginRight:".9em"}})),S=()=>{let{t:e}=(0,l.$G)(),{classes:t}=E(),[n,s]=(0,u.useState)("authenticate"),[C,S]=(0,u.useState)(),[Z,O]=(0,u.useState)(!0),[P,T]=(0,u.useState)(!1),{redirectUrl:L}=(0,f.bp)(),{name:D,updateDiscount:U,updatePrices:I}=(0,w.Z)();function F(){try{let e=JSON.parse(window.localStorage.getItem("currentUser"))||void 0;return console.log("extracted user: ",e),e}catch(e){console.log("user undefined");return}}function R(){window.localStorage.removeItem("currentUser"),O(!1),s("authenticate")}(0,u.useEffect)(()=>{"redirect"===n?(0,x.ab)()?window.location.href=(0,x.ab)()||"":window.location.href=L:"poll-subscription"===n&&void 0!==C&&(0,x.UV)(C).then(()=>{s("redirect")}).finally(()=>{s("redirect")})},[n,C]),(0,u.useEffect)(()=>{"not-allowed"===n&&setTimeout(()=>{s("redirect")},7e3)},[n]),(0,u.useEffect)(()=>{let e=new URLSearchParams(window.location.search),t=e.get("product_id");if(t&&"check-purchase"===n&&!P){let e=F();if(void 0===e){s("authenticate");return}h.f.TOKEN=e.token||void 0,p.d.buyCanPurchaseProduct(t).then(e=>{s(e.canPurchase?"checkout":"not-allowed")}).catch(e=>{e instanceof v.M&&401===e.status&&R(),console.log("cannot purchase product due to error:"),console.error(e),s("not-allowed")})}},[n,P]),(0,u.useEffect)(()=>{"poll-subscription"===n&&(console.log("Check subscriptions: ",C||[]),(0,x.UV)(C||[]).then(()=>{s("redirect")}).catch(e=>{console.error(e),e.message.includes("poll")?s("error-retry"):s("error")}))},[n]),(0,u.useEffect)(()=>{if("authenticate"===n){let e=F();void 0!==e&&(S(null!==e.subscriptions?e.subscriptions:[]),s("check-purchase"))}},[n]),(0,u.useEffect)(()=>{if("authenticate"===n)return;let e=new URLSearchParams(window.location.search),t=e.get("product_id"),i=e.get("code")||void 0,o=e.get("campaign_id")||(0,x.JK)("klrccd")||void 0,c=F();if(void 0===c){s("authenticate");return}if(t&&"checkout"===n&&!P){window.Paddle.Setup({vendor:129508,eventCallback:e=>{if(console.log(e.event,JSON.stringify(e,null,2)),e.event!==d.YI.CHECKOUT_LOADED||P||(d.Ng.event(d.FS.Buy,"action_inline_checkout_loaded"),I(e.eventData),T(!0)),e.event===d.YI.CHECKOUT_COUPON_APPLIED&&(d.Ng.event(d.FS.Buy,"action_inline_checkout_coupon_applied"),U(e.eventData)),e.event===d.YI.CHECKOUT_COMPLETE&&(d.Ng.event(d.FS.Buy,"action_inline_checkout_completed"),d.Ng.event(d.FS.Checkout,"action_checkout_success_b"),s("poll-subscription")),e.event===d.YI.CHECKOUT_LOCATION_SUBMIT&&(d.Ng.event(d.FS.Buy,"action_inline_checkout_submit_first_screen"),window.pii=e.eventData.user.email,I(e.eventData)),e.event===d.YI.CHECKOUT_PAYMENT_COMPLETE){var t,n,c,r,a,l;d.Ng.event(d.FS.Buy,d.Mr.CHECKOUT_PADDLE_SUBSCRIPTION_SUCCESS),d.Ng.purchase((null===(t=e.eventData.checkout)||void 0===t?void 0:t.id)||"",(null===(n=e.eventData.product)||void 0===n?void 0:n.id)||"",(null===(c=e.eventData.product)||void 0===c?void 0:c.name)||"",(null===(r=e.eventData.checkout)||void 0===r?void 0:r.prices.customer.total)||0,(null===(a=e.eventData.checkout)||void 0===a?void 0:a.prices.customer.currency)||"",{coupon:i,tax:(null===(l=e.eventData.checkout)||void 0===l?void 0:l.prices.customer.total_tax)||void 0,affiliation:o})}}}),window.location.host.includes("localhost")&&window.Paddle.Environment.set("sandbox");let e={passthrough:JSON.stringify({user_id:c.id,bucket:(0,x.DO)(),campaign_id:o}),email:c.email||void 0,product:t,coupon:i,...N.kz};window.pii=c.email,(0,d.i8)().then(t=>{e={...e,postcode:t.postCode,country:t.country,marketingConsent:(0,x.L_)(t.country)?"1":"0"}}).finally(()=>{window.Paddle.Checkout.open(e)})}},[n,P]);let K=()=>{s("poll-subscription")},M=()=>{s("redirect")},B=()=>s("check-purchase"),A=(0,u.useMemo)(()=>D&&!["redirect","authenticate","poll-subscription","error-retry","error","not-allowed"].includes(n),[D,n]),[H,Y]=(0,u.useMemo)(()=>"authenticate"!==n?[!1,!1]:[Z,!Z],[n,Z]);return(0,i.jsxs)(k.Z,{showLoginLink:Z&&"authenticate"===n,showRegisterLink:!Z&&"authenticate"===n,twoColumns:"checkout"===n||"redirect"===n||"poll-subscription"===n,onClickLogin:()=>O(!1),onClickRegister:()=>O(!0),showLogoutLink:"authenticate"!==n,onClickLogout:R,title:"Checkout | Klangio",children:[(0,i.jsx)(r.Z,{style:{position:"absolute",top:0,left:0,width:"100vw",height:"100vh",display:"flex",justifyContent:"center",alignItems:"center"},disablePortal:!0,open:"check-purchase"===n,children:(0,i.jsx)(a.Z,{children:e("buy.checking_product_msg")})}),"not-allowed"===n&&(0,i.jsxs)(o.Z,{display:"flex",flexDirection:"column",justifyContent:"center",alignContent:"center",mt:8,children:[(0,i.jsx)(j.Z,{}),(0,i.jsx)(c.Z,{sx:{mt:8},onClick:()=>s("redirect"),children:e("buy.go_back")})]}),(0,i.jsxs)("div",{className:t.productInfo,children:[A&&(0,i.jsx)(y.Z,{}),"poll-subscription"===n&&(0,i.jsxs)("div",{children:[(0,i.jsx)(a.Z,{className:t.thanksText,variant:"h5",children:e("buy.validating_subscription")}),(0,i.jsx)(m.Z,{color:"primary"})]}),"redirect"===n&&(0,i.jsxs)("div",{children:[(0,i.jsx)(a.Z,{className:t.thanksText,variant:"h5",children:e("buy.thanks")}),(0,i.jsx)(g.Z,{}),(0,i.jsx)(c.Z,{className:t.button,variant:"outlined",href:L,children:e("buy.continue")})]})]}),(0,i.jsx)("div",{className:"checkout"===n||"poll-subscription"===n?t.paddleContainer:t.hideCheckout,children:(0,i.jsx)("div",{className:"checkout-container"})}),H&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:t.title,children:(0,i.jsx)(a.Z,{variant:"h1",component:"h1",children:e("register.title")})}),(0,i.jsx)(b.Z,{noRedirect:!0,onRegister:B})]}),Y&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:t.title,children:(0,i.jsx)(a.Z,{variant:"h1",component:"h1",children:e("login.title")})}),(0,i.jsx)(_.Z,{onLogin:B,noRedirect:!0})]}),"error"===n&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:t.title,children:(0,i.jsx)(a.Z,{variant:"h1",component:"h1",children:e("buy.validation_error_msg")})}),(0,i.jsx)(c.Z,{onClick:K,className:t.button,variant:"outlined",children:e("buy.retry")}),(0,i.jsx)(c.Z,{onClick:M,className:t.button,variant:"outlined",children:e("buy.go_back")})]}),"error-retry"===n&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:t.title,children:(0,i.jsx)(a.Z,{variant:"h1",component:"h1",children:e("buy.timeout_error_msg")})}),(0,i.jsx)(c.Z,{onClick:K,className:t.button,variant:"outlined",children:e("buy.retry")}),(0,i.jsx)(c.Z,{onClick:M,className:t.button,variant:"outlined",children:e("buy.go_back")})]})]})},Z=()=>(0,i.jsx)(C.v,{children:(0,i.jsx)(S,{})});var O=!0;t.default=Z}},function(e){e.O(0,[675,167,113,922,525,774,888,179],function(){return e(e.s=4153)}),_N_E=e.O()}]);