1import{j as e}from"./vendor-radix-BnNg3BH5.js";import{d as V,h as ee,r as i}from"./vendor-react-67mgcWXU.js";import{M as se}from"./metric-DK0Tcl4m.js";import{b as te,u as re,s as R,B as u,L as U,C as B,X as ae}from"./index-Epr9psQo.js";import{C as b,a as C,b as S,c as k,e as Y,d as D}from"./card-DpKBVi42.js";import{B as P}from"./badge-Cl7apleB.js";import{u as ie}from"./useSubscription-FuoKqSQZ.js";import{S as w}from"./skeleton-CXDkv5zX.js";import{S as z}from"./shield-BI9NGrnO.js";import{S as ne}from"./sparkles-BcySMUTB.js";import{m as ce}from"./vendor-motion-CSzk-Fqg.js";import{U as le}from"./users-uAR6_Qvs.js";import{M as oe}from"./minus-CdxVbKUw.js";import{P as de}from"./plus-DRTmwF2W.js";import{Z as me}from"./zap-DC4LlnWT.js";import{C as ue}from"./clock-BYWbH6MV.js";import"./vendor-supabase-CTlrDMdV.js";import"./vendor-charts-Dck3qfzI.js";import"./vendor-query-PMAhJHCS.js";const O=[{id:"starter",name:"Starter",price:29,description:"Core PSA tools for small teams up to 10 users",features:[{text:"Up to 10 users",included:!0},{text:"5 active projects",included:!0},{text:"Time tracking & timesheets",included:!0},{text:"Basic invoicing",included:!0},{text:"Client management",included:!0},{text:"Basic proposals",included:!0},{text:"Email support",included:!0}],excluded:["AI battlecards","Revenue Intelligence","Knowledge Hub","Compose (AI documents)"],highlighted:!1},{id:"pro",name:"Pro",price:49,description:"Full AI-powered platform for growing firms",features:[{text:"Unlimited users",included:!0},{text:"Everything in Starter",included:!0},{text:"Unlimited projects",included:!0},{text:"Unlimited proposals + e-signatures",included:!0},{text:"AI briefings & battlecards",included:!0},{text:"Competitive intelligence",included:!0},{text:"Revenue Intelligence",included:!0},{text:"Knowledge Hub",included:!0},{text:"Compose (AI documents)",included:!0},{text:"Priority support",included:!0}],excluded:[],highlighted:!0}];function Me(){const{subscription:n,loading:x,error:H,isActive:h,isTrialing:A,isNFR:l,trialDaysLeft:f,refetch:j}=ie(),{currentMembership:G}=te(),r=V(),{toast:p}=re(),[o,K]=ee(),W=o.get("plan")==="starter"?"starter":"pro",[c,Z]=i.useState(W),[a,E]=i.useState(n?.seat_count||1),[v,I]=i.useState(!1),[_,M]=i.useState(!1),[T,q]=i.useState(!1),g=G?.role==="owner",d=!!n?.nfr_acknowledged_at,N=O.find(s=>s.id===c),Q=a*N.price;i.useEffect(()=>{if(!x){if(h){r("/dashboard",{replace:!0});return}if(l&&(d||!g)){r("/dashboard",{replace:!0});return}}},[x,h,l,d,g,r]),i.useEffect(()=>{const s=o.get("success"),t=o.get("canceled");s==="true"?(p({title:"Subscription Activated!",description:"Welcome to CommandOS. Your subscription is now active."}),j(),r("/subscribe",{replace:!0})):t==="true"&&(p({title:"Checkout Canceled",description:"No worries! You can subscribe whenever you're ready.",variant:"destructive"}),r("/subscribe",{replace:!0}))},[o,p,r,j]),i.useEffect(()=>{if(x||T||h||l&&d||o.get("autostart")!=="1")return;const s=o.get("plan")==="starter"?"starter":"pro";q(!0),K({},{replace:!0}),F(s,1)},[x,h,l,d,T]);const $=s=>{const t=c==="starter"?10:1/0;E(y=>Math.max(1,Math.min(t,y+s)))},F=async(s,t)=>{const y=s??c,J=t??a;I(!0);try{const{data:m,error:L}=await R.functions.invoke("create-checkout-session",{body:{plan:y,seatCount:J}});if(L)throw L;if(!m?.url)throw new Error("No checkout URL returned");s?window.location.href=m.url:window.open(m.url,"_blank")}catch(m){console.error("Checkout error:",m),p({title:"Checkout Error",description:m.message||"Failed to start checkout. Please try again.",variant:"destructive"})}finally{I(!1)}},X=async()=>{if(n?.id){M(!0);try{const{error:s}=await R.from("subscriptions").update({nfr_acknowledged_at:new Date().toISOString()}).eq("id",n.id);if(s)throw s;await j(),r("/dashboard")}catch(s){console.error("Error acknowledging NFR:",s),p({title:"Error",description:"Failed to acknowledge. Please try again.",variant:"destructive"})}finally{M(!1)}}};return x?e.jsx("div",{className:"flex min-h-[80vh] items-center justify-center px-4",children:e.jsxs("div",{className:"w-full max-w-4xl space-y-6",children:[e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(w,{className:"h-8 w-64 mx-auto"}),e.jsx(w,{className:"h-4 w-48 mx-auto"})]}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-6",children:[e.jsx(w,{className:"h-[500px] w-full rounded-lg"}),e.jsx(w,{className:"h-[500px] w-full rounded-lg"})]})]})}):H&&!n?e.jsx("div",{className:"flex min-h-[80vh] items-center justify-center px-4",children:e.jsxs(b,{className:"max-w-md text-center",children:[e.jsxs(C,{children:[e.jsx("div",{className:"mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-full bg-destructive/10",children:e.jsx(z,{className:"h-7 w-7 text-destructive"})}),e.jsx(S,{children:"Unable to Load Subscription"}),e.jsx(k,{children:"We couldn't verify your account status. This is likely a temporary network issue."})]}),e.jsxs(Y,{className:"flex flex-col gap-2",children:[e.jsx(u,{onClick:()=>j(),className:"w-full",children:"Try Again"}),e.jsx(u,{variant:"ghost",onClick:()=>
1r("/dashboard"),className:"w-full",children:"Go to Dashboard"})]})]})}):l&&!d&&g?e.jsx("div",{className:"flex min-h-[80vh] items-center justify-center",children:e.jsxs(b,{className:"max-w-md text-center",children:[e.jsxs(C,{children:[e.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-primary/10",children:e.jsx(ne,{className:"h-8 w-8 text-primary"})}),e.jsx(P,{variant:"secondary",className:"mx-auto mb-2",children:"Partner Account"}),e.jsx(S,{children:"NFR License Active"}),e.jsx(k,{children:n?.nfr_partner_name?`Partner: ${n.nfr_partner_name}`:"You have a complimentary partner license with full access."})]}),e.jsx(Y,{className:"justify-center",children:e.jsxs(u,{onClick:X,disabled:_,children:[_?e.jsx(U,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Go to Dashboard"]})})]})}):h||l&&(d||!g)?null:e.jsx("div",{className:"flex min-h-[80vh] items-center justify-center px-4 py-8",children:e.jsxs(ce.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"w-full max-w-4xl",children:[e.jsxs("div",{className:"mb-8 text-center",children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:A&&f>0?"Choose Your Plan":"Subscribe to CommandOS"}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:A&&f>0?`You have ${f} day${f===1?"":"s"} left in your trial. Pick a plan to continue.`:"Your trial has ended. Choose a plan to continue using CommandOS."})]}),e.jsx("div",{className:"grid md:grid-cols-2 gap-6 mb-8",children:O.map(s=>e.jsxs(b,{className:`relative cursor-pointer transition-all ${c===s.id?"border-primary ring-2 ring-primary/20":"border-border hover:border-muted-foreground/30"} ${s.highlighted?"shadow-lg":""}`,onClick:()=>{Z(s.id),s.id==="starter"&&a>10&&E(10)},children:[s.highlighted&&e.jsx("div",{className:"absolute -top-3 left-1/2 -translate-x-1/2",children:e.jsx(P,{className:"bg-primary text-primary-foreground",children:"Most Popular"})}),e.jsxs(C,{className:"pb-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(S,{className:"text-xl",children:s.name}),c===s.id&&e.jsx("div",{className:"h-5 w-5 rounded-full bg-primary flex items-center justify-center",children:e.jsx(B,{className:"h-3 w-3 text-primary-foreground"})})]}),e.jsxs("div",{className:"mt-2",children:[e.jsxs("span",{className:"text-4xl font-bold",children:["$",s.price]}),e.jsx("span",{className:"text-muted-foreground",children:"/user/month"})]}),e.jsx(k,{className:"mt-1",children:s.description})]}),e.jsxs(D,{className:"space-y-2",children:[s.features.map(t=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(B,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("span",{children:t.text})]},t.text)),s.excluded.map(t=>e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground/50",children:[e.jsx(ae,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"line-through",children:t})]},t))]})]},s.id))}),e.jsx(b,{className:"border-primary/30",children:e.jsxs(D,{className:"pt-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:"Team Seats"}),c==="starter"&&e.jsx(P,{variant:"outline",className:"text-xs",children:"Max 10"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(u,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:s=>{s.stopPropagation(),$(-1)},disabled:a<=1,children:e.jsx(oe,{className:"h-4 w-4"})}),e.jsx("span",{className:"w-8 text-center text-lg font-semibold",children:a}),e.jsx(u,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:s=>{s.stopPropagation(),$(1)},disabled:c==="starter"&&a>=10,children:e.jsx(de,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center justify-between border-t pt-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[N.name," · ",a," seat",a>1?"s":""," à $",N.price,"/mo"]}),e.jsxs(se,{size:"md",children:["$",Q,"/mo"]})]}),e.jsxs(u,{onClick:()=>F(),size:"lg",className:"gap-2",disabled:v,children:[v?e.jsx(U,{className:"h-4 w-4 animate-spin"}):e.jsx(me,{className:"h-4 w-4"}),v?"Starting Checkout...":`Subscribe to ${N.name}`]})]}),e.jsxs("div",{className:"flex items-center justify-center gap-4 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(z,{className:"h-3 w-3"}),"Secure checkout via Stripe"]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ue,{className:"h-3 w-3"}),"Cancel anytime"]})]})]})}),e.jsxs("p",{className:"mt-6 text-center text-sm text-muted-foreground",children:["Questions? Contact us at"," ",e.jsx("a",{href:"mailto:[email protected]",className:"text-primary hover:underline",children:"[email protected]"})]})]})})}export{Me 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.