1import{g as V,r as o,j as e,L as X}from"./vendor-BYDWwPae.js";import{a2 as q,V as f,c_ as N,a6 as J,a8 as Q,a7 as m,aa as Z,cL as O,c$ as ee,d0 as ae,d1 as te,bE as se,d2 as ne,d3 as re,d4 as oe,d5 as ce,d6 as ie,d7 as le,ae as S,af as A}from"./index-DJOi_ihA.js";import{B as de}from"./Breadcrumbs-C13DS0Uc.js";import"./query-DAfX1kxE.js";import"./ui-DI4_AqlD.js";import"./utils-CXlbsO6u.js";import"./book-open-BPuiQdRL.js";function ye(){const u=V(),{refreshUser:y}=q(),[B,v]=o.useState(!1),[T,U]=o.useState(!0),[k,E]=o.useState("card"),[t,d]=o.useState(null),[s,P]=o.useState(null),[D,F]=o.useState(!1),[I,i]=o.useState(null);o.useEffect(()=>{R()},[]);const R=async()=>{var L;const n=new URLSearchParams(window.location.search),c=n.get("orderId"),p=n.get("method"),r=n.get("plan"),j=n.get("type"),w=parseInt(n.get("extra"),10)||0;try{if(c){const a=await f.getOrder(c);if(!a){i("Order not found. Please try again.");return}if(a.status!=="PENDING"&&a.status!=="EXPIRED"){i(`Order is ${a.status.toLowerCase()}. Please create a new order.`);return}p&&E(p),P(N(a)),a.type==="TOKEN_PURCHASE"?d({type:"tokens",orderId:a.id,name:`${a.tokens} Token${a.tokens>1?"s":""}`,price:a.amount,currency:a.currency||"USD",tokens:a.tokens,accounts:a.tokens}):d({type:"plan",orderId:a.id,name:((L=a.metadata)==null?void 0:L.plan)||"Subscription",price:a.amount,currency:a.currency||"USD"});return}if(j==="tokens"){const a=parseInt(n.get("tokens"),10)||0,h=(await f.getTokenPackages()).find(C=>C.tokens===a);if(!h){a>0?d({type:"tokens",name:`${a} Token${a>1?"s":""}`,price:a*100,currency:"USD",tokens:a,accounts:a}):i(`Invalid token package: ${a}. Please select a valid package.`);return}d({type:"tokens",name:`${a} Token${a>1?"s":""}`,price:h.price,currency:h.currency||"USD",tokens:a,accounts:a});return}if(r){const g=(await f.getPlans()).find(C=>C.plan.toLowerCase()===r.toLowerCase());if(!g){i(`Invalid plan: ${r}. Please select a valid plan.`);return}d({type:"plan",id:r,name:{startup:"Startup Plan",basic:"Basic Plan",business:"Business Plan",professional:"Professional Plan",premium:"Premium Plan",enterprise:"Enterprise Plan",free:"Free Plan"}[r.toLowerCase()]||g.plan,price:g.price,extraAccounts:w,savings:w>0?300:0}),F(w>0);return}i("Invalid checkout URL. Please go back to pricing page.")}catch(a){console.error("Failed to load pricing:",a),i("Failed to load pricing information. Please try again.")}finally{U(!1)}},M=n=>P(c=>N({...c||{},...n})),z=async()=>{if(s!=null&&s.id)try{P(N(await f.getOrder(s.id)))}catch(n){console.error("Failed to reload the order:",n)}},l=s?s.amount:(t==null?void 0:t.type)==="tokens"?t.price:((t==null?void 0:t.price)||0)+((t==null?void 0:t.extraAccounts)||0)*100,x=(s==null?void 0:s.currency)||(t==null?void 0:t.currency)||"USD",b=x==="GBP"?"£":"$",$=(s==null?void 0:s.type)==="TOKEN_PURCHASE",W=$&&!!s.promoCodeId&&Math.round(s.amount*100)===0,H=async n=>{var c,p;v(!0);try{const r=t&&{...t,price:l},j=await ie({orderId:t==null?void 0:t.orderId,paymentMethod:k,paymentData:n,planDetails:r});await le({result:j,paymentMethod:k,planDetails:r,displayPrice:l}),await y(),u(m("Companies"))}catch(r){console.error("Payment error:",r),S.error(((p=(c=r.response)==null?void 0:c.data)==null?void 0:p.message)||"Payment failed. Please try again.")}finally{v(!1)}},Y=async n=>{await A(),S.success((n==null?void 0:n.message)||`Successfully completed payment of ${b}${l}`),await y(),u(m("Companies"))},_=async n=>{await A(),S.success((n==null?void 0:n.message)||"Order completed with your promo code"),await y(),u(m("Pricing")+"?tab=history")},{home:G}=J({roots:["tokenStore","legalSupport"],fallback:"tokenStore"});if(T)return e.jsx(Q,{});if(I)return e.jsx("div",{className:"flex min-h-full items-center justify-center bg-gray-50",children:e.jsxs("div",{className:"max-w-md rounded-lg bg-white p-8 text-center shadow-lg",children:[e.jsx("h2",{className:"mb-2 text-xl font-bold text-gray-900",children:"Pricing Error"}),e.jsx("p",{className:"mb-4 text-gray-600",children:I}),e.jsx(X,{to:m("Pricing"),className:"inline-block rounded-lg bg-blue-600 px-6 py-2 text-white hover:bg-blue-700",children:"Back to Pricing"})]})});if(!t)return e.jsx("div",{className:"flex min-h-full items-center justify-center bg-gray-50",children:e.jsx(Z,{className:"h-8 w-8"})});const K=t.type==="tokens"?[{label:"Payment"}]:[{label:t.name},{label:"Payment"}];return e.jsx("div",{className:"p-4",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-[1920px] flex-col gap-4",children:[e.jsx(de,{home:G,items:K}),e.jsxs("div",{className:"flex flex-1 flex-col gap-[22px] rounded-2xl bg-white",style:{padding:"22px 22px 32px",boxShadow:"-2px 20px 50px -10px rgba(18,49,96,0.1)"},children:[e.jsxs("div",{className:"flex items-end justify-between",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:t.type==="tokens"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[18px] font-bold leading-[140%] text-[#16111C]",children:"Your purchase:"}),e.jsx("span",{className:"text-[18px] font-bold leading-[140%]",style:{background:"linear-gradient(58.82deg, #E74E1D 14.83%, #FD9834 94.3%)",WebkitBackgroun
1dClip:"text",WebkitTextFillColor:"transparent"},children:t.name}),(s==null?void 0:s.discountAmount)>0?e.jsx("span",{className:"text-[16px] font-semibold leading-[140%] text-[#9CA3AF] line-through",children:O(s.listAmount,x)}):null,e.jsx("span",{className:"text-[18px] font-bold leading-[140%] text-[#F7862E]",children:O(l,x)}),e.jsxs("span",{className:"text-[16px] leading-[140%] text-blue-600",children:["(",t.tokens," tokens)"]}),e.jsx("button",{type:"button",onClick:()=>u(m("Pricing")),className:"ml-1 flex size-6 items-center justify-center rounded-full transition-opacity hover:opacity-70","aria-label":"Edit token amount",children:e.jsx(ee,{className:"size-5"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[18px] font-bold leading-[140%] text-[#16111C]",children:"Your chosen plan is"}),e.jsx("span",{className:"text-[18px] font-bold leading-[140%]",style:{background:"linear-gradient(58.82deg, #E74E1D 14.83%, #FD9834 94.3%)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent"},children:t.name}),e.jsxs("span",{className:"text-[18px] font-bold leading-[140%] text-[#F7862E]",children:[b,l,t.savings>0?` (Save -${b}${t.savings})`:""]})]})}),t.type==="plan"?e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:"text-[16px] leading-[140%] text-[#6B7280]",children:"Per 3 extra accounts"}),e.jsx(ae,{checked:D,onCheckedChange:F})]}):null]}),$?e.jsxs("div",{className:"flex w-full max-w-[640px] flex-col gap-3",children:[s.status==="EXPIRED"&&te(s)&&!s.promoCodeId?e.jsxs("div",{role:"note",className:"flex items-start gap-2 rounded-xl border border-[#C1E0FF] bg-[#F0F7FF] px-4 py-3 text-[14px] leading-[140%] text-[#1F2937]",children:[e.jsx(se,{className:"mt-0.5 size-4 shrink-0 text-[#305DFF]","aria-hidden":"true"}),e.jsx("span",{children:"This order expired, and its promo code went back to you. You can put it on this order again below."})]}):null,e.jsx(ne,{order:s,onOrderChange:M}),e.jsx(re,{order:s})]}):null,W?e.jsx(oe,{order:s,onCompleted:_,className:"max-w-[640px]"}):e.jsx(ce,{paymentMethod:k,onPaymentMethodChange:E,orderId:t.orderId,amount:l,currency:x,promoCode:(s==null?void 0:s.promoCodeText)??null,onInvoiceIssued:z,onConfirm:H,onStripeSuccess:Y,onStripeError:n=>console.error("Stripe payment error:",n),isSubmitting:B},s?`v${s.pricingVersion}`:"plan")]})]})})}export{ye as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.