1import{c as R,b as P,r as l,j as e}from"./vendor-C05Yzltl.js";import{a as N,d as w,t as S}from"./index-QmvZqL7_.js";import"./query-DHDyGzqa.js";import"./zustand-DEL2VzFa.js";import"./ui-DEhm1nHf.js";import"./strings-en-506xq7Cb.js";const C={resolve:r=>N.post("/marketplace/resolve",{token:r}).then(c=>c.data),activate:(r,c)=>N.post("/marketplace/activate",{subscriptionId:r,choice:c}).then(i=>i.data)},y="onplana.marketplaceToken";function E(r,c){var i,u,d,n;return((u=(i=r==null?void 0:r.response)==null?void 0:i.data)==null?void 0:u.message)||((n=(d=r==null?void 0:r.response)==null?void 0:d.data)==null?void 0:n.error)||c}function z(r){if(!r)return"";const i=(r.split("@")[1]??"").split(".")[0]??"";return i?i.charAt(0).toUpperCase()+i.slice(1):""}function q(){const[r]=R(),c=P(),i=w(t=>t.token),u=w(t=>t.organizations),d=l.useMemo(()=>{const a=r.get("token")||sessionStorage.getItem(y);return a&&sessionStorage.setItem(y,a),a},[r]),[n,o]=l.useState("init"),[g,m]=l.useState(""),[s,I]=l.useState(null),[x,h]=l.useState("create"),[k,f]=l.useState(""),[b,A]=l.useState(""),[v,M]=l.useState(null),p=l.useMemo(()=>u.filter(t=>t.role==="OWNER"&&!t.isSandbox),[u]);l.useEffect(()=>{if(!d){o("resolve-error"),m("No purchase token was provided. Reopen this subscription from the Azure portal or Microsoft 365 Admin Center and select Configure Account.");return}if(!i){c(`/login?redirect=${encodeURIComponent("/marketplace/welcome")}`);return}let t=!1;return o("resolving"),C.resolve(d).then(a=>{t||(I(a),S("marketplace_purchase_resolved",{plan:a.onplanaPlan??"unknown",alreadyMapped:a.alreadyMapped,planRecognized:a.planRecognized}),a.alreadyMapped?o("already"):(f(z(a.beneficiaryEmail||a.purchaserEmail)),h((p.length>0,"create")),o("choose")))}).catch(a=>{t||(m(E(a,"We could not resolve this purchase. Please try again.")),o("resolve-error"))}),()=>{t=!0}},[d,i]);async function O(){if(!s)return;const t=x==="create"?{mode:"create",name:k.trim()}:{mode:"link",orgId:b};if(x==="create"&&t.mode==="create"&&t.name.length<2){m("Enter a workspace name (at least 2 characters).");return}if(x==="link"&&!b){m("Choose a workspace to attach the subscription to.");return}m(""),o("activating");try{const a=await C.activate(s.subscriptionId,t);sessionStorage.removeItem(y),S("marketplace_subscription_activated",{plan:a.planCode,created:a.created,quantity:a.quantity??0}),M({orgSlug:a.orgSlug,created:a.created}),o("success")}catch(a){m(E(a,"Activation failed. Please try again.")),o("activate-error")}}function j(){window.location.assign("/dashboard")}return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900 px-4 py-10",children:e.jsxs("div",{className:"card w-full max-w-lg p-8",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"h-10 w-10 rounded-lg bg-indigo-600 text-white flex items-center justify-center font-bold",children:"O"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"Onplana on Microsoft Marketplace"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Set up your subscription"})]})]}),(n==="init"||n==="resolving"||n==="activating")&&e.jsxs("div",{className:"py-8 text-center text-gray-600 dark:text-gray-300",children:[e.jsx("div",{className:"inline-block h-6 w-6 animate-spin rounded-full border-2 border-indigo-500 border-t-transparent mb-3"}),e.jsx("p",{children:n==="activating"?"Activating your subscriptionâ¦":"Confirming your purchaseâ¦"})]}),(n==="resolve-error"||n==="activate-error")&&e.jsxs("div",{className:"py-4",children:[e.jsx("div",{className:"rounded-md bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 p-4 text-sm text-red-700 dark:text-red-300",children:g}),n==="activate-error"&&e.jsx("button",{className:"btn-secondary mt-4",onClick:()=>o("choose"),children:"Back"})]}),n==="already"&&s&&e.jsxs("div",{className:"py-2",children:[e.jsxs("p",{className:"text-gray-700 dark:text-gray-200 mb-4",children:["This subscription is already set up",s.mappedOrg?e.jsxs(e.Fragment,{children:[" for ",e.jsx("span",{className:"font-semibold",children:s.mappedOrg.name})]}):null,"."]}),e.jsx("button",{className:"btn-primary w-full",onClick:j,children:"Go to your workspace"})]}),n==="choose"&&s&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-md bg-gray-50 dark:bg-gray-800 p-4 text-sm",children:[e.jsxs("div",{className:"flex justify-between py-1",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Plan"}),e.jsxs("span",{className:"font-medium text-gray-900 dark:text-white",children:[s.onplanaPlan??s.planId??"Unknown",s.billingInterval?` · ${s.billingInterval==="year"?"Annual":"Monthly"}`:""]})]}),s.quantity!=null&&e.jsxs("div",{className:"flex justify-between py-1",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Seats"}),e.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:s.quantity})]}),s.purchaserEmail&&e.jsxs("div",{className:"flex justify-between py-1",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Purchased by"}),e.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:s.purchaserEmail})]})]}),!s.planRecognized&&e.jsxs("div",{className:"rounded-md bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 p-3 text-xs text-amber-700 dark:text-amber-300",children:["We could not match this plan to an Onplana tier. You can still continue; our team will reconcile it. (planId: ",s.planId,")"]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex gap-2 mb-3",children:[e.jsx("button",{className:`flex-1 rounded-md border px-3 py-2 text-sm font-medium ${x==="create"?"border-indigo-500 bg-indigo-50 dark:bg-indigo-900/30 text-indigo-700 dark:text-indigo-300":"border-gray-300 dark:border-gray-700 text-gray-600 dark:text-gray-300"}`,onClick:()=>h("create"),children:"Create new workspace"}),e.jsx("button",{className:`flex-1 rounded-md border px-3 py-2 text-sm font-medium ${x==="link"?"border-indigo-500 bg-indigo-50 dark:bg-indigo-900/30 text-indigo-700 dark:text-indigo-300":"border-gray-300 dark:border-gray-700 text-gray-600 dark:text-gray-300"} ${p.length===0?"opacity-50 cursor-not-allowed":""}`,onClick:()=>p.length>0&&h("link"),disabled:p.length===0,children:"Use an existing one"})]}),x==="create"?e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-600 dark:text-gray-300 mb-1",children:"Worksp
1ace name"}),e.jsx("input",{className:"input w-full",value:k,onChange:t=>f(t.target.value),placeholder:"Acme Inc.",autoFocus:!0})]}):e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-gray-600 dark:text-gray-300 mb-1",children:"Workspace"}),e.jsxs("select",{className:"input w-full",value:b,onChange:t=>A(t.target.value),children:[e.jsx("option",{value:"",children:"Select a workspace you ownâ¦"}),p.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]}),e.jsx("p",{className:"mt-1 text-xs text-gray-400",children:"Only workspaces you own with no active plan are eligible."})]})]}),g&&e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:g}),e.jsx("button",{className:"btn-primary w-full",onClick:O,children:"Activate subscription"}),e.jsx("p",{className:"text-xs text-gray-400 text-center",children:"You will not be billed until activation completes."})]}),n==="success"&&v&&e.jsxs("div",{className:"py-2 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 h-12 w-12 rounded-full bg-emerald-100 dark:bg-emerald-900/30 text-emerald-600 dark:text-emerald-400 flex items-center justify-center text-2xl",children:"â"}),e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-1",children:"You're all set"}),e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-300 mb-5",children:["Your subscription is active",v.created?" and your new workspace is ready":"","."]}),e.jsx("button",{className:"btn-primary w-full",onClick:j,children:"Go to your workspace"})]})]})})}export{q 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.