1import{j as e}from"./vendor-radix-eVIgfZQS.js";import{r as i,i as $s,h as Ds,f as As}from"./vendor-react-DJrKDxOS.js";import{c as te,T as Bt,g as Ut,h as Kt,i as Yt,d as Je,k as Qt,L as ht,a as C,f as q,B as D,b as ze,u as Ps,j as Ls,S as Fs,E as es,X as Ms}from"./index-Bysc37QK.js";import{I as Qe}from"./input-DjGAtg8M.js";import{L as Se}from"./label-Dff2s8Y7.js";import{D as yt,a as jt,b as bt,c as vt,d as Nt}from"./dialog-BHuq8vlR.js";import{T as Es,a as Is,b as Ht,c as ie,d as Rs,e as le}from"./table-Cl8skZvh.js";import{A as zs,P as Os,h as Bs,a as Us}from"./PaymentForm-B1yV9i-L.js";import{g as Ks,b as Ys,d as ts,c as ss,h as Hs,m as Gs,f as qs}from"./constants-sjZtt7xQ.js";import{I as as,A as rs}from"./AddCreditsModal-BaSooLbq.js";import{E as ns,a as is,B as ls,C as Ue,T as Gt}from"./trending-up-CsEOBII_.js";import{C as pt,K as Vs}from"./key-round-ymrOyCNe.js";import{A as De}from"./alert-triangle-C6GSyi_8.js";import{G as Ws}from"./globe-D8T77IBH.js";import{Z as et,P as ft}from"./zap-DvwP6Ghn.js";import{F as ds}from"./file-text-CKCBK9hv.js";import{C as os}from"./clock-DQ30FKsw.js";import{R as be,B as Te,C as ke,X as _e,Y as Ce,T as he,a as Oe,b as tt,P as cs,d as ms,L as wt,e as qt,A as xs,f as Xs,g as us}from"./vendor-recharts-B_xQ_1SR.js";import{C as hs}from"./ConfirmDialog-ChP9GlVc.js";import{d as Zs}from"./planFeatures-BvpUq6TH.js";import{S as Js,T as Qs}from"./ServiceTeamPanel-D3aNdlqK.js";import{L as W}from"./loader-2-PWFJrQrr.js";import{P as ps}from"./plus-DCejlEei.js";import{R as ea}from"./refresh-cw-DDloX34g.js";import{A as ta}from"./arrow-left-BTRYz0GZ.js";import{R as sa}from"./rotate-ccw-llC10gIc.js";import{S as Vt}from"./sparkles-CG2euAiS.js";import{C as aa}from"./check-circle-BN29KEsy.js";import"./vendor-stripe-CqMkR2Rf.js";import"./creditPricing-CMbhpQUE.js";import"./mail-CfxI_pyQ.js";/** 2 * @license lucide-react v0.300.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ra=te("ArrowRightLeft",[["path",{d:"m16 3 4 4-4 4",key:"1x1c3m"}],["path",{d:"M20 7H4",key:"zbl0bi"}],["path",{d:"m8 21-4-4 4-4",key:"h9nckh"}],["path",{d:"M4 17h16",key:"g4d7ey"}]]);/** 7 * @license lucide-react v0.300.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const xt=te("CalendarDays",[["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",ry:"2",key:"eu3xkr"}],["line",{x1:"16",x2:"16",y1:"2",y2:"6",key:"m3sa8f"}],["line",{x1:"8",x2:"8",y1:"2",y2:"6",key:"18kwsl"}],["line",{x1:"3",x2:"21",y1:"10",y2:"10",key:"xt86sb"}],["path",{d:"M8 14h.01",key:"6423bh"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 18h.01",key:"lrp35t"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M16 18h.01",key:"kzsmim"}]]);/** 12 * @license lucide-react v0.300.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const na=te("Calendar",[["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",ry:"2",key:"eu3xkr"}],["line",{x1:"16",x2:"16",y1:"2",y2:"6",key:"m3sa8f"}],["line",{x1:"8",x2:"8",y1:"2",y2:"6",key:"18kwsl"}],["line",{x1:"3",x2:"21",y1:"10",y2:"10",key:"xt86sb"}]]);/** 17 * @license lucide-react v0.300.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const ia=te("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/** 22 * @license lucide-react v0.300.0 - ISC 23 * 24 * This source code is licensed under the ISC license. 25 * See the LICENSE file in the root directory of this source tree. 26 */const la=te("Gauge",[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]]);/** 27 * @license lucide-react v0.300.0 - ISC 28 * 29 * This source code is licensed under the ISC license. 30 * See the LICENSE file in the root directory of this source tree. 31 */const da=te("Key",[["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["path",{d:"m15.5 7.5 3 3L22 7l-3-3",key:"1rn1fs"}]]);/** 32 * @license lucide-react v0.300.0 - ISC 33 * 34 * This source code is licensed under the ISC license. 35 * See the LICENSE file in the root directory of this source tree. 36 */const fs=te("Palette",[["circle",{cx:"13.5",cy:"6.5",r:".5",key:"1xcu5"}],["circle",{cx:"17.5",cy:"10.5",r:".5",key:"736e4u"}],["circle",{cx:"8.5",cy:"7.5",r:".5",key:"clrty"}],["circle",{cx:"6.5",cy:"12.5",r:".5",key:"1s4xz9"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]]);/** 37 * @license lucide-react v0.300.0 - ISC 38 * 39 * This source code is licensed under the ISC license. 40 * See the LICENSE file in the root directory of this source tree. 41 */const oa=te("ShieldAlert",[["path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",key:"1irkt0"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);/** 42 * @license lucide-react v0.300.0 - ISC 43 * 44 * This source code is licensed under the ISC license. 45 * See the LICENSE file in the root directory of this source tree. 46 */const ca=te("Shield",[["path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",key:"1irkt0"}]]);/** 47 * @license lucide-react v0.300.0 - ISC 48 * 49 * This source code is licensed under the ISC license. 50 * See the LICENSE file in the root directory of this source tree. 51 */const ma=te("ShoppingCart",[["circle",{cx:"8",cy:"21",r:"1",key:"jimo8o"}
51],["circle",{cx:"19",cy:"21",r:"1",key:"13723u"}],["path",{d:"M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12",key:"9zh506"}]]);function xa({value:t}){const[a,s]=i.useState(!1),[r,o]=i.useState(!1),p=()=>{navigator.clipboard.writeText(t),o(!0),setTimeout(()=>o(!1),2e3)},N=`${t.slice(0,8)}${"â¢".repeat(Math.min(Math.max(t.length-8,0),24))}`;return e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide mb-0.5",children:"API Key"}),e.jsx("p",{className:`text-sm font-mono ${a?"break-all":"truncate"}`,children:a?t:N})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Bt,{delayDuration:0,children:e.jsxs(Ut,{children:[e.jsx(Kt,{asChild:!0,children:e.jsx("button",{onClick:()=>s(c=>!c),className:"rounded-md p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",children:a?e.jsx(ns,{className:"h-3.5 w-3.5"}):e.jsx(is,{className:"h-3.5 w-3.5"})})}),e.jsx(Yt,{children:a?"Hide":"Reveal"})]})}),e.jsx(Bt,{delayDuration:0,children:e.jsxs(Ut,{children:[e.jsx(Kt,{asChild:!0,children:e.jsx("button",{onClick:p,className:"rounded-md p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",children:r?e.jsx(Je,{className:"h-3.5 w-3.5 text-emerald-500"}):e.jsx(pt,{className:"h-3.5 w-3.5"})})}),e.jsx(Yt,{children:r?"Copied!":"Copy API Key"})]})})]})]})}const gs=new Intl.NumberFormat(void 0,{notation:"compact",maximumFractionDigits:1}),Ze=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),Wt=new Intl.NumberFormat(void 0,{maximumFractionDigits:2});function $e(t,a){if(!Number.isFinite(t))return"â";switch(a){case"compact":return Math.abs(t)>=1e4?gs.format(t):Ze.format(t);case"percent":return`${Math.round(t)}%`;case"money":return Wt.format(t);case"integer":return Ze.format(t);default:return Number.isInteger(t)?Ze.format(t):Wt.format(t)}}const ys=t=>Math.abs(t)>=1e3?gs.format(t):Ze.format(t),de={blue:"#3b82f6",violet:"#8b5cf6",emerald:"#10b981",amber:"#f59e0b",red:"#ef4444",cyan:"#06b6d4",orange:"#f97316",lime:"#84cc16",success:"#10b981",warning:"#f59e0b",destructive:"#ef4444",secondary:"#94a3b8"},ve=[de.blue,de.violet,de.emerald,de.amber,de.red,de.cyan,de.orange,de.lime],Be=(t,a=ve[0])=>t&&de[t]||a,Xt={blue:"bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/20",violet:"bg-violet-500/10 text-violet-600 dark:text-violet-400 border-violet-500/20",emerald:"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/20",amber:"bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20",red:"bg-red-500/10 text-red-600 dark:text-red-400 border-red-500/20",cyan:"bg-cyan-500/10 text-cyan-600 dark:text-cyan-400 border-cyan-500/20",orange:"bg-orange-500/10 text-orange-600 dark:text-orange-400 border-orange-500/20",lime:"bg-lime-500/10 text-lime-600 dark:text-lime-400 border-lime-500/20",success:"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/20",warning:"bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20",destructive:"bg-red-500/10 text-red-600 dark:text-red-400 border-red-500/20",secondary:"bg-muted text-muted-foreground border-border"},rt=t=>t&&Xt[t]||Xt.secondary;function ua(t){if(/^\d{4}-\d{2}-\d{2}$/.test(t)){const[,s,r]=t.split("-");return`${r}/${s}`}const a=new Date(t);return Number.isNaN(a.getTime())?t:a.toLocaleDateString()}function ha(t){if(typeof t!="string"||!t)return"â";const a=new Date(t);return Number.isNaN(a.getTime())?t:a.toLocaleString()}const st={coins:Ue,key:da,shield:ca,chart:ls,calendar:na,clock:os,layers:ht,file:ds,package:ft,zap:et,alert:De,check:Je,info:as,users:Qt,globe:Ws,database:ia};function Q({block:t,children:a}){const s=t.icon?st[t.icon]:void 0;return e.jsxs("div",{className:"rounded-xl border bg-card shadow-sm",children:[t.title&&e.jsxs("div",{className:"flex items-center justify-between gap-3 px-5 py-3 border-b",children:[e.jsxs("p",{className:"text-sm font-semibold flex items-center gap-2",children:[s&&e.jsx(s,{className:"h-4 w-4 text-muted-foreground"}),t.title]}),t.subtitle&&e.jsx("span",{className:"text-xs text-muted-foreground",children:t.subtitle})]}),a]})}function Ae({text:t}){return e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:t||"Nothing to show yet."})}function gt({active:t,payload:a,label:s}){return!t||!(a!=null&&a.length)?null:e.jsxs("div",{className:"rounded-lg border bg-popover px-3 py-2 shadow-md text-xs",children:[s!=null&&e.jsx("p",{className:"font-medium mb-1",children:String(s)}),a.map(r=>e.jsxs("p",{className:"flex items-center gap-2 tabular-nums",children:[e.jsx("span",{className:"h-2 w-2 rounded-full",style:{background:r.color}}),e.jsx("span",{className:"text-muted-foreground",children:r.name}),e.jsx("span",{className:"font-medium",children:$e(r.value)})]},r.dataKey))]})}
51const at={tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickLine:!1,axisLine:!1};function pa({block:t}){const a=t.items??[];return a.length?e.jsx(Q,{block:t,children:e.jsx("div",{className:"grid divide-x divide-border",style:{gridTemplateColumns:`repeat(${Math.min(a.length,4)}, minmax(0, 1fr))`},children:a.map((s,r)=>e.jsxs("div",{className:"px-5 py-4 space-y-0.5",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:s.label}),e.jsx("p",{className:"text-xl font-bold tabular-nums",style:{color:s.tone?Be(s.tone):void 0},children:$e(s.value,s.format)}),s.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.hint})]},s.key??r))})}):e.jsx(Q,{block:t,children:e.jsx(Ae,{text:t.empty_text})})}function fa({block:t}){const a=t.rows??[];return a.length?e.jsx(Q,{block:t,children:e.jsx("div",{className:"divide-y",children:a.map((s,r)=>{var o;return e.jsxs("div",{className:"px-5 py-4",children:[s.secret&&s.value?e.jsx(xa,{value:s.value}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide mb-1",children:s.label}),s.value&&e.jsx("p",{className:`text-sm ${s.mono?"font-mono break-all":""}`,children:s.value}),!!((o=s.badges)!=null&&o.length)&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1",children:s.badges.map((p,N)=>e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-md border ${rt(p.tone)}`,children:p.text},N))})]}),s.note&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1.5",children:s.note})]},r)})})}):e.jsx(Q,{block:t,children:e.jsx(Ae,{text:t.empty_text})})}function ga({block:t}){const a=t.items??[],s=t.summary??[];return!a.length&&!s.length?e.jsx(Q,{block:t,children:e.jsx(Ae,{text:t.empty_text})}):e.jsxs(Q,{block:t,children:[!!s.length&&e.jsx("div",{className:"grid divide-x divide-border border-b bg-muted/20",style:{gridTemplateColumns:`repeat(${s.length}, minmax(0, 1fr))`},children:s.map((r,o)=>e.jsxs("div",{className:"px-5 py-3 space-y-0.5",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:r.label}),e.jsx("p",{className:"text-xl font-bold tabular-nums",children:$e(r.value,r.format)})]},r.key??o))}),e.jsx("div",{className:"divide-y",children:a.map((r,o)=>e.jsx(ya,{item:r},r.key??o))})]})}function ya({item:t}){const a=t.total??0,s=t.used??0,r=a>0?Math.min(100,Math.max(0,s/a*100)):0,o=Math.max(0,a-s),p=t.tone==="secondary";return e.jsxs("div",{className:"px-5 py-3.5 space-y-2",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsxs("p",{className:`text-sm font-medium ${p?"text-muted-foreground":""}`,children:[t.label,t.badge&&e.jsx("span",{className:`ml-2 text-xs px-1.5 py-0.5 rounded border ${rt(t.tone)}`,children:t.badge})]}),e.jsxs("p",{className:"text-sm tabular-nums text-muted-foreground",children:[e.jsx("span",{className:"font-semibold text-foreground",children:$e(o,"compact")}),a>0&&e.jsxs(e.Fragment,{children:[" / ",$e(a,"compact")]})]})]}),e.jsx("div",{className:"h-1.5 w-full rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${r}%`,background:p?"hsl(var(--muted-foreground))":Be(t.tone)}})}),(t.hint||t.note)&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-xs text-muted-foreground",children:[t.hint&&e.jsx("span",{children:t.hint}),t.note&&e.jsx("span",{children:t.note})]})]})}function ja({block:t}){var j,h,T;const a=i.useMemo(()=>{const x=[];for(const y of t.points??[])y.group&&!x.includes(y.group)&&x.push(y.group);return x},[t.points]),[s,r]=i.useState(()=>{var x;return((x=t.selector)==null?void 0:x.default)||a[a.length-1]||""}),o=i.useMemo(()=>(t.points??[]).filter(y=>!a.length||y.group===s).map(y=>({x:y.x,...y.values})),[t.points,s,a.length]),p=t.series??[];if(!o.length||!p.length)return e.jsx(Q,{block:t,children:e.jsx(Ae,{text:t.empty_text})});const N=t.chart==="line"?qt:t.chart==="bar"?Te:xs,c=/^\d{4}-\d{2}-\d{2}$/.test(o[0].x);return e.jsxs("div",{className:"rounded-xl border bg-card shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-5 py-3 border-b",children:[e.jsxs("p",{className:"text-sm font-semibold flex items-center gap-2",children:[t.icon&&st[t.icon]&&(()=>{const x=st[t.icon];return e.jsx(x,{className:"h-4 w-4 text-muted-foreground"})})(),t.title]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.subtitle&&e.jsx("span",{className:"text-xs text-muted-foreground",children:t.subtitle}),a.length>1&&e.jsx("select",{value:s,onChange:x=>r(x.target.value),"aria-label":((j=t.selector)==null?void 0:j.label)||"Filter",className:"h-7 rounded-md border bg-background px-2 text-xs text-foreground",children:(((T=(h=t.selector)==null?void 0:h.options)==null?void 0:T.map(x=>x.text))??a).map(x=>e.jsx("option",{value:x,children:x},x))})]})]}),e.jsx("div",{className:"p-5",children:e.jsx(be,{width:"100%",height:220,children:e.jsxs(N,{data:o,margin:{top:4,right:8,left:0,bottom:0},children:[e.jsx("defs",{children:p.map(x=>e.jsxs("linearGradient",{id:`grad-${t.id}-${x.key}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",
51stopColor:Be(x.tone),stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:Be(x.tone),stopOpacity:0})]},x.key))}),e.jsx(ke,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(_e,{dataKey:"x",...at,tickFormatter:c?ua:void 0,interval:o.length>24?Math.floor(o.length/12):0}),e.jsx(Ce,{...at,tickFormatter:ys,width:40,allowDecimals:!1}),e.jsx(he,{content:e.jsx(gt,{})}),p.length>1&&e.jsx(wt,{wrapperStyle:{fontSize:11}}),p.map((x,y)=>{const S=Be(x.tone,ve[y%ve.length]),P=x.label||x.key;return N===Te?e.jsx(Oe,{dataKey:x.key,name:P,fill:S,radius:[3,3,0,0]},x.key):N===qt?e.jsx(Xs,{type:"monotone",dataKey:x.key,name:P,stroke:S,strokeWidth:2,dot:!1},x.key):e.jsx(us,{type:"monotone",dataKey:x.key,name:P,stroke:S,strokeWidth:2,fill:`url(#grad-${t.id}-${x.key})`},x.key)})]})})})]})}function ba({block:t}){const a=(t.items??[]).filter(r=>r.value>0);if(!a.length)return e.jsx(Q,{block:t,children:e.jsx(Ae,{text:t.empty_text})});const s=a.map(r=>({name:r.label,value:r.value,hint:r.hint}));return e.jsx(Q,{block:t,children:e.jsx("div",{className:"p-5",children:e.jsx(be,{width:"100%",height:220,children:t.chart==="bar"?e.jsxs(Te,{data:s,layout:"vertical",margin:{top:4,right:16,left:0,bottom:0},children:[e.jsx(ke,{strokeDasharray:"3 3",stroke:"hsl(var(--border))",horizontal:!1}),e.jsx(_e,{type:"number",...at,tickFormatter:ys}),e.jsx(Ce,{type:"category",dataKey:"name",...at,width:110}),e.jsx(he,{content:e.jsx(gt,{})}),e.jsx(Oe,{dataKey:"value",name:"Credits",radius:[0,3,3,0],children:s.map((r,o)=>e.jsx(tt,{fill:ve[o%ve.length]},o))})]}):e.jsxs(cs,{children:[e.jsx(ms,{data:s,dataKey:"value",nameKey:"name",innerRadius:50,outerRadius:80,paddingAngle:2,children:s.map((r,o)=>e.jsx(tt,{fill:ve[o%ve.length]},o))}),e.jsx(he,{content:e.jsx(gt,{})}),e.jsx(wt,{wrapperStyle:{fontSize:11}})]})})})})}function va(t,a){return t.type==="date"?ha(a):t.type==="number"?typeof a=="number"?$e(a):"â":a==null||a===""?"â":String(a)}function Na({block:t}){const a=t.columns??[],s=t.records??[];if(!a.length||!s.length)return e.jsx(Q,{block:t,children:e.jsx(Ae,{text:t.empty_text})});const r=o=>o.align==="right"?"text-right":o.align==="center"?"text-center":"text-left";return e.jsx(Q,{block:t,children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsx("tr",{className:"border-b bg-muted/20",children:a.map(o=>e.jsx("th",{className:`px-4 py-2 text-xs font-medium text-muted-foreground uppercase tracking-wider whitespace-nowrap ${r(o)}`,children:o.label},o.key))})}),e.jsx("tbody",{className:"divide-y",children:s.map((o,p)=>{const N=t.row_tone&&o[t.row_tone.key]===t.row_tone.when;return e.jsx("tr",{className:N?"bg-red-500/5":void 0,children:a.map(c=>{const j=o[c.key];if(c.type==="bool_badge"){const h=j?c.true_label:c.false_label;return e.jsx("td",{className:`px-4 py-2 ${r(c)}`,children:h?e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded border ${rt(j?"success":"secondary")}`,children:h}):e.jsx("span",{className:"text-muted-foreground",children:"â"})},c.key)}return e.jsx("td",{className:`px-4 py-2 ${r(c)} ${c.type==="mono"?"font-mono text-xs":""} ${c.type==="number"?"tabular-nums":""}`,children:va(c,j)},c.key)})},p)})})]})})})}function wa({block:t}){const a=t.icon&&st[t.icon]||as;return e.jsxs("div",{className:`rounded-xl border px-5 py-4 flex gap-3 ${rt(t.tone)}`,children:[e.jsx(a,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsxs("div",{className:"space-y-0.5",children:[t.title&&e.jsx("p",{className:"text-sm font-semibold",children:t.title}),t.body&&e.jsx("p",{className:"text-sm",children:t.body})]})]})}function ka(t){switch(t.type){case"stats":return e.jsx(pa,{block:t});case"key_value":return e.jsx(fa,{block:t});case"meter":return e.jsx(ga,{block:t});case"series":return e.jsx(ja,{block:t});case"breakdown":return e.jsx(ba,{block:t});case"table":return e.jsx(Na,{block:t});case"notice":return e.jsx(wa,{block:t});default:return null}}function _a({document:t}){const a=[];for(const s of t.blocks){const r=a[a.length-1];s.span==="half"&&(r==null?void 0:r.length)===1&&r[0].span==="half"?r.push(s):a.push([s])}return e.jsx("div",{className:"space-y-4",children:a.map((s,r)=>e.jsx("div",{className:s.length>1?"grid grid-cols-1 lg:grid-cols-2 gap-4 items-start":void 0,children:s.map(o=>e.jsx("div",{children:ka(o)},o.id))},r))})}function Ca({data:t,serviceName:a}){return t.status==="not_configured"?null:t.status!=="ok"||!t.document?e.jsxs("div",{className:"rounded-xl border bg-card shadow-sm px-5 py-8 text-center space-y-1",children:[e.jsx(De,{className:"h-5 w-5 mx-auto text-muted-foreground"}),e.jsx("p",{className:"text-sm font-medium",children:"Usage data is unavailable"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[a||"This service"," did not respond. Your subscription and credits are unaffected."]})]}):t.document.blocks.length?e.jsx(_a,{document:t.document}):e.jsxs("div",{className:"rounded-xl border bg-card shadow-sm px-5 py-8 text-center space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"Nothing to show yet"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Usage will appear here once you start making requests."})]})}const Ve=t=>
51Math.round(t).toLocaleString();function Sa({serviceKey:t,serviceName:a}){const[s,r]=i.useState([]),[o,p]=i.useState(!0),[N,c]=i.useState(""),[j,h]=i.useState(null),[T,x]=i.useState(null),[y,S]=i.useState(""),[P,F]=i.useState(!1),[U,w]=i.useState(""),[V,K]=i.useState(""),se=i.useCallback(async()=>{var m,Z;c("");try{const I=await C.get(`/services/${t}/credits/team`);r(I.data??[])}catch(I){const Y=I;c(((Z=(m=Y==null?void 0:Y.response)==null?void 0:m.data)==null?void 0:Z.error)??"Could not read your teamâs credits.")}},[t]);i.useEffect(()=>{se().finally(()=>p(!1))},[se]);const O=s.find(m=>m.role==="owner"),ae=s.filter(m=>m.role!=="owner");async function X(){var Z,I;if(!j)return;const m=Number(y);if(!Number.isFinite(m)||m<=0){w("Enter how many credits to move.");return}F(!0),w("");try{await C.post(`/services/${t}/credits/transfer`,{user_id:j.user_id,credits:m}),K(`${Ve(m)} credits moved to ${j.email}.`),h(null),S(""),await se()}catch(Y){const ce=Y;w(((I=(Z=ce==null?void 0:ce.response)==null?void 0:Z.data)==null?void 0:I.error)??"Could not move the credits.")}finally{F(!1)}}return o?e.jsxs("div",{className:"flex items-center justify-center py-10 text-muted-foreground gap-2",children:[e.jsx(W,{className:"h-4 w-4 animate-spin"})," Loading creditsâ¦"]}):e.jsxs("div",{className:"space-y-4",children:[N&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:N}),V&&e.jsx("p",{className:"rounded-lg bg-emerald-500/10 px-3 py-2 text-xs text-emerald-700 dark:text-emerald-400",children:V}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[a," charges each key against its own holderâs credits, so everyone who calls it needs their own. Move some of yours, or buy some for them."]}),e.jsx("div",{className:"overflow-hidden rounded-lg border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/40 text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left font-medium",children:"Member"}),e.jsx("th",{className:"px-4 py-2 text-right font-medium",children:"Remaining"}),e.jsx("th",{className:"px-4 py-2 text-right font-medium",children:"Of"}),e.jsx("th",{className:"px-4 py-2 text-right font-medium",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y",children:s.map(m=>e.jsxs("tr",{className:m.role==="owner"?"bg-muted/20":void 0,children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:m.name||m.email}),m.role==="owner"&&e.jsx(q,{variant:"secondary",className:"text-xs",children:"You"}),m.role!=="owner"&&!m.has_account&&e.jsx(q,{variant:"secondary",className:"text-xs",children:"No account yet"}),m.role!=="owner"&&m.has_account&&m.remaining<=0&&e.jsxs(q,{variant:"warning",className:"gap-1 text-xs",children:[e.jsx(De,{className:"h-3 w-3"})," Calls refused"]})]}),m.name&&e.jsx("p",{className:"text-xs text-muted-foreground",children:m.email})]}),e.jsx("td",{className:"px-4 py-3 text-right font-medium tabular-nums",children:m.has_account?Ve(m.remaining):"â"}),e.jsx("td",{className:"px-4 py-3 text-right text-muted-foreground tabular-nums",children:m.has_account?Ve(m.total):"â"}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[m.role!=="owner"&&e.jsxs(D,{size:"sm",variant:"outline",className:"gap-1.5",disabled:!O||O.remaining<=0,title:!O||O.remaining<=0?"You have no credits to move":void 0,onClick:()=>{w(""),K(""),S(""),h(m)},children:[e.jsx(ra,{className:"h-3.5 w-3.5"})," Move mine"]}),e.jsx(D,{size:"sm",variant:m.role==="owner"?"outline":"default",className:"gap-1.5",onClick:()=>{K(""),x(m)},children:m.role==="owner"?e.jsxs(e.Fragment,{children:[e.jsx(ps,{className:"h-3.5 w-3.5"})," Buy credits"]}):e.jsxs(e.Fragment,{children:[e.jsx(ma,{className:"h-3.5 w-3.5"})," Buy for them"]})})]})})]},m.user_id))})]})}),ae.length===0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Nobody else has ",a," yet. Give a colleague access on the Team tab and they will appear here."]}),e.jsx(yt,{open:!!j,onOpenChange:m=>{m||h(null)},children:e.jsxs(jt,{className:"max-w-md",children:[e.jsx(bt,{children:e.jsxs(vt,{className:"flex items-center gap-2",children:[e.jsx(Ue,{className:"h-5 w-5 text-primary"}),"Move credits to ",(j==null?void 0:j.name)||(j==null?void 0:j.email)]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Se,{htmlFor:"move-credits",children:"Credits"}),e.jsx(Qe,{id:"move-credits",type:"number",min:1,value:y,onChange:m=>S(m.target.value),placeholder:"1000"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["You have ",e.jsx("span",{className:"font-medium text-foreground",children:Ve((O==null?void 0:O.remaining)??0)})," ","remaining. They come out of your balance and keep the expiry date of the pool they are taken from."]}),U&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:U})]}),e.jsxs(Nt,{children:[e.jsx(D,{variant:"outline",onClick:()=>h(null),disabled:P,children:"Cancel"}),e.jsxs(D,{onClick:X,disabled:P,className:"gap-2",children:[P&&e.jsx(W,{className:"h-4 w-4 animate-spin"}),"Move credits"]})]})]})}),e.jsx(rs,{open:!!T,onClose:()=>{x(null),se()},serviceKey:t,forUserID:T&&T.role!=="owner"?T.user_id:void 0,forLabel:T&&T.role!=="owner"?T.name||T.email:void 0})]})}const Zt={delivered:{text:"Active",variant:"success"},pending:{text:"Activatingâ¦",variant:"warning"},failed:{text:"Not delivered",variant:"destructive"},unknown:{text:"Not delivered",variant:"destructive"}},Ta=[{id:"team",label:"Team",icon:Qt},{id:"usage",label:"Usage",icon:la},{id:"keys",label:"API keys",icon:Vs},{id:"credits",label:"Credits",icon:Ue},{id:"whitelabel",label:"Whitelabel",icon:fs}];function js(t){const a=t==="credits"||t==="usage";return Ta.filter(s=>a?s.id==="team"||s.id==="keys"||s.id==="credits":s.id!=="credits")}function Jt({serviceKey:t,serviceName:a,billingModel:s,tab:r,hideTabs:o,features:p,planFeatures:N,canManage:c}){const j=js(s),[h,T]=i.useState("team"),x=r??h,[y,S]=i.useState(null),[P,F]=i.useState(!0);
51async function U(){const w=await C.get("/organization").catch(()=>null);w&&S(w.data)}return i.useEffect(()=>{U().finally(()=>F(!1))},[]),c?e.jsxs("div",{children:[!o&&e.jsx("div",{className:"flex gap-1 overflow-x-auto border-b",children:j.map(w=>{const V=w.icon,K=x===w.id;return e.jsxs("button",{type:"button",onClick:()=>T(w.id),className:ze("flex shrink-0 items-center gap-1.5 rounded-t-md px-3 py-2 text-sm font-medium transition-colors",K?"-mb-px border border-b-0 border-border bg-card text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx(V,{className:"h-3.5 w-3.5"}),w.label]},w.id)})}),P?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(W,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:o?"":"rounded-b-xl rounded-tr-xl border border-t-0 bg-card p-5 shadow-sm",children:[x==="team"&&(y?e.jsx(Js,{serviceKey:t,serviceName:a,team:y,onChanged:U,showHeader:!1,flat:!0}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Could not load your team."})),x==="usage"&&e.jsx($a,{features:p,planFeatures:N}),x==="keys"&&e.jsx(Da,{serviceKey:t,serviceName:a}),x==="credits"&&e.jsx(Sa,{serviceKey:t,serviceName:a}),x==="whitelabel"&&e.jsx(Aa,{serviceName:a})]})]}):e.jsx("div",{className:"rounded-xl border bg-card p-6 shadow-sm",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["You have access to ",a," through your organization. Team, API keys and billing are managed by the account owner and its admins."]})})}function $a({features:t,planFeatures:a}){const s=Zs(t,a),r=s.filter(o=>o.value!=="");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-md border bg-muted/30 px-4 py-3",children:[e.jsx(De,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Allowances below come from your plan. Live consumption is not being reported yet â it appears here once this service publishes a usage endpoint."})]}),s.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"This plan declares no features."}):e.jsx("div",{className:"overflow-hidden",children:e.jsxs("ul",{className:"divide-y",children:[r.map(o=>e.jsxs("li",{className:"flex items-center justify-between gap-4 px-4 py-3",children:[e.jsx("span",{className:"min-w-0 truncate text-sm font-medium",children:o.name}),e.jsxs("span",{className:"shrink-0 text-sm tabular-nums",children:[e.jsx("span",{className:"text-muted-foreground",children:"â / "}),e.jsx("span",{className:"font-semibold",children:o.value})]})]},o.key)),s.filter(o=>o.value==="").map(o=>e.jsxs("li",{className:"flex items-center justify-between gap-4 px-4 py-3",children:[e.jsx("span",{className:"min-w-0 truncate text-sm font-medium",children:o.name}),o.included?e.jsx(q,{variant:"success",className:"shrink-0 text-xs",children:"Included"}):e.jsx(q,{variant:"secondary",className:"shrink-0 text-xs",children:"Not included"})]},o.key))]})})]})}function Da({serviceKey:t,serviceName:a}){const[s,r]=i.useState([]),[o,p]=i.useState(!0),[N,c]=i.useState(""),[j,h]=i.useState(!1),[T,x]=i.useState(""),[y,S]=i.useState([]),[P,F]=i.useState(""),[U,w]=i.useState(!1),[V,K]=i.useState(""),[se,O]=i.useState(!1),[ae,X]=i.useState(""),[m,Z]=i.useState(null),[I,Y]=i.useState(""),[ce,Ke]=i.useState(""),[$,Ye]=i.useState(null);async function pe(){const d=await C.get(`/services/${t}/api-keys`).catch(()=>null);d&&r(d.data??[])}async function re(d){var k,b;if((m==null?void 0:m.id)===d.key_id){Z(null);return}Y(d.key_id),c("");try{const M=await C.post(`/services/${t}/api-keys/${d.key_id}/reveal`);Z({id:d.key_id,key:M.data.key})}catch(M){const L=M;c(((b=(k=L==null?void 0:L.response)==null?void 0:k.data)==null?void 0:b.error)??"Could not show that key.")}finally{Y("")}}i.useEffect(()=>{C.get("/organization").then(d=>{const k=(d.data.members??[]).filter(b=>b.role==="owner"||(b.services??[]).includes(t));S(k),F(b=>{var M;return b||((M=k.find(L=>L.role==="owner"))==null?void 0:M.user_id)||""})}).catch(()=>S([]))},[t]),i.useEffect(()=>{pe().finally(()=>p(!1))},[t]);async function Pe(){var d,k;w(!0),c("");try{const b=await C.post(`/services/${t}/api-keys`,{name:T.trim(),user_id:P});K(b.data.key),O(!1),await pe()}catch(b){const M=b;c(((k=(d=M==null?void 0:M.response)==null?void 0:d.data)==null?void 0:k.error)??"Could not create a key."),h(!1)}finally{w(!1)}}async function He(d){var k,b;X(d.key_id),c("");try{await C.post(`/services/${t}/api-keys/${d.key_id}/resend`),await pe()}catch(M){const L=M;c(((b=(k=L==null?void 0:L.response)==null?void 0:k.data)==null?void 0:b.error)??"Could not send that key again.")}finally{X("")}}async function me(d){var k,b;X(d.key_id),c("");try{await C.delete(`/services/${t}/api-keys/${d.key_id}`),await pe()}catch(M){const L=M;c(((b=(k=L==null?void 0:L.response)==null?void 0:k.data)==null?void 0:b.error)??"Could not revoke that key.")}finally{X("")}}return o?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(W,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(hs,{open:!!$,onOpenChange:d=>{d||Ye(null)},title:`Revoke ${($==null?void 0:$.name)||"this key"}?`,description:$!=null&&$.user_name||$!=null&&$.user_email?`Issued to ${$.user_name||$.user_email}.`:void 0,consequences:[`Anything calling ${a} with this key stops working as soon as ${a} is told â usually within a minute.`,"The key cannot be restored. Issuing a replacement means updating whatever uses it.",$!=null&&$.last_used_at?`This key was last used on ${new Date($.last_used_at).toLocaleDateString()}.`:"It has never been used, so this is unlikely to break anything."],confirmLabel:"Revoke the key",cancelLabel:"Keep it",onConfirm:async()=>{$&&await me($)}
51}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["A key per person, for ",a," alone â so a key that leaks cannot reach anything else you subscribe to, and every call it makes is attributable to whoever holds it. Issuing a key to someone who already has one replaces theirs; everyone else is unaffected."]}),e.jsxs(D,{size:"sm",className:"shrink-0 gap-2",onClick:()=>{x(""),K(""),c(""),h(!0)},children:[e.jsx(ps,{className:"h-4 w-4"})," New key"]})]}),y.length<=1&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Only you can hold a key so far. To give a colleague their own, grant them"," ",a," on the ",e.jsx("span",{className:"font-medium",children:"Team"})," tab first."]}),N&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:N}),e.jsx("div",{className:"overflow-hidden",children:s.length===0?e.jsx("p",{className:"px-4 py-6 text-center text-sm text-muted-foreground",children:"No keys yet."}):e.jsx("ul",{className:"divide-y",children:s.map(d=>{const k=Zt[d.delivery]??Zt.unknown;return e.jsxs("li",{className:"flex items-start justify-between gap-3 px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex items-center gap-2 truncate text-sm font-medium",children:[d.name,e.jsx(q,{variant:k.variant,className:"text-[10px]",children:k.text})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("code",{className:ze("min-w-0 truncate rounded font-mono text-xs text-muted-foreground transition-all",(m==null?void 0:m.id)===d.key_id?"bg-muted px-1.5 py-0.5 text-foreground select-all":"blur-[3px] select-none"),children:(m==null?void 0:m.id)===d.key_id?m.key:`${d.prefix}${"â¦".repeat(1)}${"x".repeat(28)}`}),d.revealable!==!1&&e.jsx("button",{type:"button",title:(m==null?void 0:m.id)===d.key_id?"Hide":"Show this key",className:"shrink-0 rounded p-0.5 text-muted-foreground hover:text-foreground",onClick:()=>re(d),disabled:I===d.key_id,children:I===d.key_id?e.jsx(W,{className:"h-3.5 w-3.5 animate-spin"}):(m==null?void 0:m.id)===d.key_id?e.jsx(ns,{className:"h-3.5 w-3.5"}):e.jsx(is,{className:"h-3.5 w-3.5"})}),(m==null?void 0:m.id)===d.key_id&&e.jsx("button",{type:"button",title:"Copy",className:"shrink-0 rounded p-0.5 text-muted-foreground hover:text-foreground",onClick:()=>{var b;(b=navigator.clipboard)==null||b.writeText(m.key),Ke(d.key_id),window.setTimeout(()=>Ke(""),2e3)},children:ce===d.key_id?e.jsx(Je,{className:"h-3.5 w-3.5 text-emerald-600"}):e.jsx(pt,{className:"h-3.5 w-3.5"})})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:d.user_name||d.user_email||"Unassigned"}),e.jsxs("p",{className:"text-xs text-muted-foreground/70",children:["Created ",new Date(d.created_at).toLocaleDateString()," · ",d.last_used_at?`last used ${new Date(d.last_used_at).toLocaleDateString()}`:"never used"]}),d.delivery==="pending"&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Waiting for ",a," to accept it. The key works there once it arrives."]}),d.delivery==="failed"&&e.jsxs("p",{className:"mt-1 text-xs text-destructive",children:[a," has not accepted this key yet",d.delivery_error?`: ${d.delivery_error}`:"."]}),d.delivery==="unknown"&&e.jsx("p",{className:"mt-1 text-xs text-destructive",children:"This key was never sent and cannot be sent now. Create a new one to replace it."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[d.delivery==="failed"&&e.jsxs(D,{variant:"outline",size:"sm",className:"h-7 gap-1 text-xs",disabled:ae===d.key_id,onClick:()=>He(d),children:[e.jsx(ea,{className:"h-3 w-3"})," Resend"]}),e.jsxs(D,{variant:"ghost",size:"sm",className:"h-7 gap-1 text-xs text-destructive hover:text-destructive",disabled:ae===d.key_id,onClick:()=>Ye(d),children:[e.jsx(Qs,{className:"h-3 w-3"})," Revoke"]})]})]},d.key_id)})})}),e.jsx(yt,{open:j,onOpenChange:d=>{d||(h(!1),K(""))},children:e.jsxs(jt,{className:"sm:max-w-lg",children:[e.jsx(bt,{children:e.jsx(vt,{children:V?"Copy your key now":`New ${a} key`})}),V?e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsxs("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/5 p-3",children:[e.jsx("p",{className:"text-xs font-medium text-amber-700 dark:text-amber-400",children:"This is the only time it is shown."}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:"We store only a hash, so it cannot be recovered. If you lose it, revoke this key and create another."}),e.jsxs("p",{className:"mt-1.5 text-xs text-muted-foreground",children:["It starts as ",e.jsx("span",{className:"font-medium",children:"Activating"})," and becomes usable once ",a," has accepted it â usually within a minute. If that service is down, the key waits rather than failing."]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"min-w-0 flex-1 truncate rounded-md border bg-muted px-3 py-2 font-mono text-xs",children:V}),e.jsx(D,{variant:"outline",size:"sm",className:"shrink-0 gap-1",onClick:()=>{var d;(d=navigator.clipboard)==null||d.writeText(V),O(!0)},children:se?e.jsxs(e.Fragment,{children:[e.jsx(Je,{className:"h-3.5 w-3.5"})," Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(pt,{className:"h-3.5 w-3.5"})," Copy"]})})]})]}):e.jsxs("div",{className:"space-y-4 py-2",children:[s.some(d=>d.user_id===P)&&e.jsxs("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/5 p-3",children:[e.jsx("p",{className:"text-xs font-medium text-amber-700 dark:text-amber-400",children:"This replaces their current key"}),e.jsxs("p",{className:"mt-0.5 text-xs text-muted-foreground",children:[a," holds one key per person. Their existing key stops working as soon as this one reaches it. Everyone else is unaffected."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Se,{htmlFor:"key-seat",children:"Issue to"}),e.jsx("select",{id:"key-seat",className:"h-9 w-full rounded-md border bg-background px-3 text-sm",value:P,onChange:d=>F(d.target.value),children:y.map(d=>e.jsxs("option",{value:d.user_id,children:[d.name?`${d.name} (${d.email})`:d.email,d.role==="owner"?" â owner":""]}
51,d.user_id))}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Calls made with this key are attributed to them and carry their access. Only colleagues granted ",a," can be chosen."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Se,{htmlFor:"key-name",children:"Name"}),e.jsx(Qe,{id:"key-name",placeholder:"e.g. Production server",value:T,onChange:d=>x(d.target.value),onKeyDown:d=>{d.key==="Enter"&&!U&&Pe()},autoFocus:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"For your own reference, so you can tell keys apart when revoking one."})]})]}),e.jsx(Nt,{children:V?e.jsx(D,{onClick:()=>{h(!1),K("")},children:"Done"}):e.jsxs(e.Fragment,{children:[e.jsx(D,{variant:"outline",onClick:()=>h(!1),disabled:U,children:"Cancel"}),e.jsx(D,{onClick:Pe,disabled:U,children:U?e.jsxs(e.Fragment,{children:[e.jsx(W,{className:"h-4 w-4 animate-spin mr-2"}),"Creatingâ¦"]}):"Create key"})]})})]})})]})}function Aa({serviceName:t}){return e.jsxs("div",{className:"rounded-xl border border-dashed p-8 text-center",children:[e.jsx(fs,{className:"mx-auto h-8 w-8 text-muted-foreground/40"}),e.jsx("p",{className:"mt-3 text-sm font-medium",children:"Whitelabel is not available yet"}),e.jsxs("p",{className:"mx-auto mt-1 max-w-md text-xs text-muted-foreground",children:["This is where you will brand ",t,"'s client-facing pages and reports with your own logo, colours and domain."]})]})}const Re=qs;function je(t){return t.toLocaleString()}function Ne(t){return new Date(t*1e3).toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})}function ut(t){return t.current_period_end?` · ${t.complimentary?"until":t.status==="trialing"?"first charge":"renews"} ${Ne(t.current_period_end)}`:""}function Pa(t){return(t.includes("T")?new Date(t):new Date(t+"T12:00:00")).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function ye(t){return t.toISOString().slice(0,10)}function oe(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:t.toFixed(0)}const We=["#3b82f6","#8b5cf6","#10b981","#f59e0b","#ef4444","#06b6d4","#f97316","#84cc16"],La=[{label:"7d",days:7},{label:"14d",days:14},{label:"30d",days:30},{label:"90d",days:90}];function Xe({active:t,payload:a,label:s}){return!t||!(a!=null&&a.length)?null:e.jsxs("div",{className:"rounded-lg border bg-card px-3 py-2 shadow-md text-xs",children:[s&&e.jsx("p",{className:"mb-1 font-semibold text-foreground",children:s}),a.map(r=>e.jsxs("p",{style:{color:r.color},children:[r.name,": ",e.jsx("span",{className:"font-semibold",children:oe(r.value)})]},r.name))]})}function Fa({sub:t,isUsage:a,onCancel:s,onTopUp:r,cancelling:o}){return!t.active&&t.status!=="incomplete"?null:t.status==="incomplete"?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-xl border border-amber-200 bg-amber-50 dark:bg-amber-950/20 dark:border-amber-800 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(De,{className:"h-5 w-5 text-amber-600 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-amber-800 dark:text-amber-300",children:"Payment incomplete"}),e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-400",children:"Your subscription is pending payment confirmation."})]})]}),t.hosted_invoice_url&&e.jsx(D,{size:"sm",variant:"outline",className:"border-amber-300 text-amber-800 gap-1.5",asChild:!0,children:e.jsxs("a",{href:t.hosted_invoice_url,target:"_blank",rel:"noreferrer",children:[e.jsx(es,{className:"h-3.5 w-3.5"})," Complete payment"]})})]}):e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-xl border border-emerald-200 bg-emerald-50 dark:bg-emerald-950/20 dark:border-emerald-800 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(aa,{className:"h-5 w-5 text-emerald-600 shrink-0"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-semibold text-emerald-800 dark:text-emerald-300",children:[t.complimentary?"Complimentary subscription":t.status==="trialing"?"Free trial":"Active subscription",t.cancel_at_period_end&&e.jsx("span",{className:"ml-2 text-amber-600 font-normal text-xs",children:"(cancelling at period end)"})]}),e.jsx("p",{className:"text-xs text-emerald-700 dark:text-emerald-400",children:a?`${je(t.credits??0)} credits${ut(t)}`:t.complimentary?`${t.plan_name??""} · managed by GeoRanker, no charge${ut(t)}`:`${t.plan_name??""} · ${ts(t.price_cents??0,t.interval_months)}${ut(t)}`})]})]}),e.jsxs("div",{className:"flex gap-2",children:[a&&e.jsxs(D,{size:"sm",className:"gap-1.5",onClick:r,children:[e.jsx(et,{className:"h-3.5 w-3.5"})," Top up"]}),!t.cancel_at_period_end&&!t.complimentary&&e.jsxs(D,{size:"sm",variant:"ghost",className:"text-muted-foreground gap-1.5",onClick:s,disabled:o,children:[o?e.jsx(W,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ms,{className:"h-3.5 w-3.5"}),"Cancel"]})]})]})}function Ma(t,a,s){var c,j;const r=t.find(h=>h.service_plan_id===s.plan_id);if(r){if(r.active&&r.complimentary)return{kind:"complimentary"};if(r.status==="incomplete")return{kind:"pay",url:r.hosted_invoice_url};if(r.status==="past_due")return{kind:"past_due",url:r.hosted_invoice_url};if(r.status==="trialing")return{kind:"trial",endsAt:r.current_period_end};if(r.active&&r.cancel_at_period_end)return{kind:"cancelling",endsAt:r.current_period_end};if(r.active)return{kind:"current"}}const o=t.find(h=>h.active&&h.complimentary);if(o)return{kind:"comped_elsewhere",planName:o.plan_name||"a complimentary plan"};const p=[(c=a.monthly)==null?void 0:c.plan_id,(j=a.yearly)==null?void 0:j.plan_id].filter(
51Boolean);if(t.some(h=>h.active&&h.service_plan_id!==s.plan_id&&p.includes(h.service_plan_id??"")))return{kind:"switch"};const N=t.find(h=>h.status==="incomplete");return N?{kind:"blocked",planName:N.plan_name||"another plan"}:{kind:"new"}}function Ea({group:t,period:a,state:s,onSubscribe:r,onPay:o,subscribing:p,serviceFeatures:N}){const c=ss(t,a),j=!Hs(t,a),h=!!(c.trial_eligible&&c.trial_days),T=Bs(N,c.features),x=s.kind==="current"||s.kind==="trial"||s.kind==="cancelling"||s.kind==="pay"||s.kind==="past_due"||s.kind==="complimentary",y=s.kind==="complimentary"?{text:"Complimentary",variant:"success"}:s.kind==="current"?{text:"Current plan",variant:"success"}:s.kind==="trial"?{text:"Free trial",variant:"success"}:s.kind==="cancelling"?{text:"Cancelling",variant:"warning"}:s.kind==="pay"?{text:"Payment pending",variant:"warning"}:s.kind==="past_due"?{text:"Payment failed",variant:"destructive"}:h?{text:`${c.trial_days} days free`,variant:"success"}:null,S=s.kind==="pay"&&s.url?{label:"Complete payment",run:()=>o(s.url)}:s.kind==="past_due"&&s.url?{label:"Pay outstanding invoice",run:()=>o(s.url)}:s.kind==="switch"?{label:`Switch to ${a==="yearly"?"annual":"monthly"}`,run:()=>r(c)}:s.kind==="new"&&h?{label:`Start ${c.trial_days}-day free trial`,run:()=>r(c)}:s.kind==="new"?{label:"Subscribe",run:()=>r(c)}:null,P=s.kind==="complimentary"?"Current plan":s.kind==="comped_elsewhere"?"Unavailable":s.kind==="current"?"Current plan":s.kind==="trial"?`Trial · ends ${Ne(s.endsAt)}`:s.kind==="cancelling"?`Ends ${Ne(s.endsAt)}`:s.kind==="pay"?"Awaiting payment":s.kind==="past_due"?"Payment failed":"Subscribe";return e.jsxs("div",{className:`flex flex-col rounded-xl border p-5 gap-4 transition-shadow ${x?"border-primary bg-primary/5 shadow-md":"bg-card shadow-sm hover:shadow-md"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("h3",{className:"font-semibold text-base",children:c.name}),y&&e.jsx(q,{variant:y.variant,className:"text-xs shrink-0",children:y.text})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-3xl font-bold tracking-tight tabular-nums",children:[Re(Gs(c.price_cents,c.interval_months),c.currency),e.jsx("span",{className:"ml-1 text-sm font-medium text-muted-foreground",children:"/ month"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c.interval_months===1?"Billed monthly, before tax":`Billed ${c.interval_months===12?"yearly":`every ${c.interval_months} months`} at ${Re(c.price_cents,c.currency)}, before tax`}),j&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Available on monthly billing only."}),s.kind==="trial"&&e.jsxs("p",{className:"text-xs text-emerald-600",children:["Free until ",Ne(s.endsAt),", then ",Re(c.price_cents,c.currency),"."]}),s.kind==="cancelling"&&e.jsxs("p",{className:"text-xs text-amber-600",children:["Access continues until ",Ne(s.endsAt),"; it will not renew."]}),s.kind==="past_due"&&e.jsx("p",{className:"text-xs text-destructive",children:"The last payment did not go through. Access continues while we retry it."}),s.kind==="complimentary"&&e.jsx("p",{className:"text-xs text-emerald-600",children:"Provided by GeoRanker at no charge. You are not billed for this plan."}),s.kind==="comped_elsewhere"&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["You are on ",s.planName,", provided by GeoRanker at no charge. Contact us to change it."]}),s.kind==="blocked"&&e.jsxs("p",{className:"text-xs text-amber-600",children:["Finish or discard your pending payment for ",s.planName," first."]}),s.kind==="new"&&h&&e.jsxs("p",{className:"text-xs text-emerald-600",children:["Free for ",c.trial_days," days, then ",Re(c.price_cents,c.currency),". Payment method required, cancel any time."]})]}),T.length>0&&e.jsx("ul",{className:"flex-1 space-y-1.5 border-t border-border pt-4",children:T.map(F=>e.jsx(Us,{feature:F},F.key))}),e.jsxs(D,{className:"w-full mt-auto",variant:!S||x?"outline":"default",disabled:!S||p,onClick:()=>S==null?void 0:S.run(),children:[p?e.jsx(W,{className:"h-4 w-4 animate-spin mr-2"}):null,S?S.label:P]})]})}const Ia=[{id:"pools",label:"Credit pools",icon:Ue},{id:"limits",label:"Rate limits",icon:oa},{id:"analytics",label:"Analytics",icon:ls}];function pr(){var It,Rt;const{key:t}=$s(),a=Ds(),{user:s}=Ps(),[r,o]=i.useState(null),[p,N]=i.useState([]),[c,j]=i.useState([]),[h,T]=i.useState(!0),[x,y]=i.useState(null),[S,P]=i.useState(!1),[F,U]=i.useState("monthly"),w=i.useMemo(()=>Ks(p),[p]),V=w.some(l=>l.yearly!==null),K=i.useMemo(()=>{const l=w.map(u=>u.monthly&&u.yearly?Ys(u.monthly.price_cents,u.yearly.price_cents):null).filter(u=>u!==null);return l.length?Math.max(...l):null},[w]);i.useEffect(()=>{const l=c.find(u=>u.active&&u.service_plan_id);l&&p.some(u=>
51u.plan_id===l.service_plan_id)&&U(l.interval_months===12?"yearly":"monthly")},[p,c]);const se=c.filter(l=>l.active&&l.service_plan_id&&!p.some(u=>u.plan_id===l.service_plan_id)),[O,ae]=i.useState(""),[X,m]=i.useState(""),[Z,I]=i.useState(""),[Y,ce]=As(),[Ke,$]=i.useState(!1),[Ye,pe]=i.useState(!1),[re,Pe]=i.useState(null),[He,me]=i.useState(!1),[d,k]=i.useState("subscription"),[b,M]=i.useState([]),[L,kt]=i.useState([]),[bs,_t]=i.useState(!1),[R,vs]=i.useState(null),[nt,Ct]=i.useState(""),St=ye(new Date),Ns=ye(new Date(Date.now()-29*864e5)),[it,Tt]=i.useState([]),[lt,ws]=i.useState(""),[Le,dt]=i.useState(Ns),[Fe,ot]=i.useState(St),[ee,ks]=i.useState(null),[ct,$t]=i.useState(!1),[mt,Dt]=i.useState(""),[Ge,_s]=i.useState("pools"),[fe,At]=i.useState(null),Pt=(s==null?void 0:s.org_role)==="owner"||(s==null?void 0:s.org_role)==="admin",J=(r==null?void 0:r.billing_model)==="usage"||(r==null?void 0:r.billing_model)==="credits",Cs=Y.get("overview")==="1",[Lt,Ft]=i.useState(null),Me=c.find(l=>l.active)??c.find(l=>l.status==="incomplete")??null,Ee=c.some(l=>l.active),Mt=(()=>{var u;const l=c.find(f=>f.active);if(l!=null&&l.service_plan_id)return(u=p.find(f=>f.plan_id===l.service_plan_id))==null?void 0:u.features})(),ne=i.useCallback(async()=>{if(t)try{const[l,u]=await Promise.all([C.get("/services"),C.get("/payments/subscriptions").catch(()=>({data:[]}))]),f=(l.data??[]).find(xe=>xe.service_key===t);if(!f){a("/services",{replace:!0});return}o(f);const B=(u.data??[]).filter(xe=>xe.service_key===t);j(B);const A=f.billing_model==="usage"||f.billing_model==="credits";A&&_t(!0);const[z,g,H,we]=await Promise.all([f.billing_model==="flat_rate"?C.get(`/services/${t}/plans`):Promise.resolve({data:[]}),A?C.get("/billing/pools").catch(()=>({data:[]})):Promise.resolve({data:[]}),A?C.get("/billing/serps").catch(()=>({data:[]})):Promise.resolve({data:[]}),A?C.get("/billing/pools/charts").catch(()=>({data:null})):Promise.resolve({data:null})]);N(z.data??[]),M(g.data??[]),kt(H.data??[]),vs(we.data),_t(!1),C.get(`/services/${t}/overview`).then(xe=>Ft(xe.data)).catch(()=>Ft({status:"unavailable"}))}finally{T(!1)}},[t,a]),qe=i.useCallback(async(l,u,f=lt)=>{$t(!0),Dt("");const B=f?`&user_id=${encodeURIComponent(f)}`:"";try{const[A,z]=await Promise.all([C.get(`/analytics/credits?from=${l}&to=${u}${B}`),C.get(`/billing/serps${f?`?user_id=${encodeURIComponent(f)}`:""}`).catch(()=>({data:[]}))]);ks(A.data),kt(z.data??[])}catch{Dt("Failed to load analytics.")}finally{$t(!1)}},[lt]);i.useEffect(()=>{ne()},[ne]),i.useEffect(()=>{J&&C.get("/organization").then(l=>{var u;return Tt(((u=l.data)==null?void 0:u.members)??[])}).catch(()=>Tt([]))},[J]),i.useEffect(()=>{if(Y.get("checkout")!=="success")return;const l=Y.get("session_id");let u=!1;$(!0);const f=()=>{u||($(!1),ce({},{replace:!0}))},B=async A=>{if(u)return;const z=l?await C.post("/payments/checkout/confirm",{session_id:l}).then(H=>H.status===200).catch(()=>!1):!1;if(u||(await ne(),u))return;if(z||A===0){f();return}const g=await C.get("/payments/subscriptions").catch(()=>null);if(((g==null?void 0:g.data)??[]).some(H=>H.service_key===t&&H.active)){f();return}setTimeout(()=>void B(A-1),2e3)};return B(5),()=>{u=!0}},[Y,t,ne,ce]),i.useEffect(()=>{if(!J||b.length===0)return;const l=Date.now()/1e3,u=b.find(g=>!g.pool_expires_at||g.pool_expires_at>=l),f=u?new Date(u.pool_created_at*1e3):null,B=new Date(Date.now()-29*864e5),A=f&&f>B?ye(f):ye(B),z=ye(new Date);dt(A),ot(z),qe(A,z)},[J,b]),i.useEffect(()=>{if(!R)return;const l=Object.keys(R.hourly_charts).sort().reverse();Ct(l[0]??Object.keys(R.daily_chart).sort().reverse()[0]??"")},[R]);async function Ss(l){var u,f,B,A;y(l),P(!0),I("");try{const z=!!(s!=null&&s.vat&&(s==null?void 0:s.vat_status)==="verified"),g=await C.post("/payments/subscribe",{service_key:t,service_plan_id:l.plan_id,has_vat:z});if(g.data.checkout_url){window.location.assign(g.data.checkout_url);return}g.data.client_secret?ae(g.data.client_secret):g.data.hosted_invoice_url?(window.open(g.data.hosted_invoice_url,"_blank","noopener,noreferrer"),m(g.data.hosted_invoice_url)):(I("Could not retrieve payment details. Please try again."),y(null))}catch(z){const g=z;if(((u=g==null?void 0:g.response)==null?void 0:u.status)===409){const H=(f=g.response.data)==null?void 0:f.hosted_invoice_url;H?Et(H):I("You already have a pending payment for this service. Discard it from the banner above to start again."),y(null),await ne();return}I(((A=(B=g==null?void 0:g.response)==null?void 0:B.data)==null?void 0:A.error)??"Failed to initiate subscription."),y(null)}finally{P(!1)}}function Et(l){window.open(l,"_blank","noopener,noreferrer"),m(l)}async function Ts(l){pe(!0);try{await C.delete(`/payments/subscription?service_key=${t}&sub_id=${l.sub_id}`),j(u=>u.map(f=>f.sub_id===l.sub_id?{...f,cancel_at_period_end:!0}:f))}catch{alert("Failed to cancel subscription.")}finally{pe(!1)}}return h?e.jsx("div",{className:"flex items-center justify-center py-24",children:e.jsx(W,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):r?e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("button",{onClick:()=>a("/services"),className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(ta,{className:"h-4 w-4"})," All services"]}),e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:r.name}),J?e.jsxs(q,{variant:"secondary",className:"gap-1",children:[e.jsx(et,{className:"h-3 w-3"}),"Usage-based"]}):e.jsxs(q,{variant:"info",className:"gap-1",children:[e.jsx(ft,{className:"h-3 w-3"}),"Flat rate"]})]}),r.description&&e.jsx("p",{className:"text-muted-foreground text-sm max-w-2xl",children:r.description})]}),J&&e.jsxs("div",{className:"flex items-stretch gap-2",children:[!Ee&&e.jsxs("button",{className:"flex items-center gap-2 rounded-lg border bg-card px-3 py-2 text-left hover:bg-muted/50 transition-colors group",onClick:()=>{k("subscription"),me(!0)},children:[e.jsx("span",{className:"flex items-center justify-center rounded-md bg-primary/10 p-1.5",children:e.jsx(sa,{className:"h-3.5 w-3.5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold leading-none",children:"Subscribe"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Auto-renewing"})]})]}),e.jsxs("button",{className:"flex items-center gap-2 rounded-lg border bg-card px-3 py-2 text-left hover:bg-muted/50 transition-colors group",onClick:()=>{k("topup"),me(!0)},children:[e.jsx("span",{className:"flex items-center justify-center rounded-md bg-amber-500/10 p-1.5",children:e.jsx(Vt,{className:"h-3.5 w-3.5 text-amber-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold leading-none",children:"Top-up"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"One-time"})]})]})]})]})]}),c.map(l=>e.jsx(Fa,{sub:l,isUsage:J,onCancel:()=>Pe(l),onTopUp:()=>{k("topup"),me(!0)},cancelling:Ye},l.sub_id)),e.jsx(hs,{open:!!re,onOpenChange:l=>{l||Pe(null)},title:`Cancel ${r.name}?`,description:"Your plan stays active until the end of the peri
51od you have paid for.",consequences:[re!=null&&re.current_period_end?`Access continues until ${Ne(re.current_period_end)}, then stops.`:"Access continues until the end of the current period, then stops.","It will not renew, and no further payment is taken.","API keys for this service stop working once it lapses.","Your reports and data stay where they are."],confirmLabel:"Cancel the plan",cancelLabel:"Keep my plan",onConfirm:async()=>{re&&await Ts(re)}}),Ee&&!J&&e.jsx(Jt,{serviceKey:r.service_key,serviceName:r.name,billingModel:r.billing_model,features:r.features,planFeatures:Mt,canManage:(s==null?void 0:s.org_role)==="owner"||(s==null?void 0:s.org_role)==="admin"}),Cs&&Lt&&e.jsxs("div",{className:"mb-6 space-y-3",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Overview preview â served through the shared service contract"}),e.jsx(Ca,{data:Lt,serviceName:r==null?void 0:r.name})]}),J&&(()=>{var zt;const l=Date.now()/1e3,u=b.filter(n=>!n.pool_expires_at||n.pool_expires_at>=l),f=u.reduce((n,v)=>n+v.credit_pool,0),B=u.reduce((n,v)=>n+v.credit_spent,0),A=f-B,z=f>0?Math.round(A/f*100):0,g=s==null?void 0:s.limits,H=((zt=g==null?void 0:g.rules)==null?void 0:zt.filter(n=>!n.service||n.service===t))??[];g==null||g.allowed_services;const we=Math.max(1,Math.round((new Date(Fe).getTime()-new Date(Le).getTime())/864e5)+1),xe=e.jsxs("div",{className:"rounded-xl border border-dashed bg-muted/20 p-10 flex flex-col items-center gap-5 text-center",children:[e.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-full bg-muted",children:e.jsx(Ue,{className:"h-7 w-7 text-muted-foreground"})}),e.jsxs("div",{className:"space-y-1.5 max-w-sm",children:[e.jsx("h3",{className:"font-semibold text-base",children:"No usage data yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Reports and analytics will appear here once you have an active credit pool. Subscribe or top up to get started."})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 justify-center",children:[e.jsxs(D,{className:"gap-2",onClick:()=>{k("subscription"),me(!0)},children:[e.jsx(Vt,{className:"h-4 w-4"})," Subscribe"]}),e.jsxs(D,{variant:"outline",className:"gap-2",onClick:()=>{k("topup"),me(!0)},children:[e.jsx(et,{className:"h-4 w-4"})," Top up"]})]})]});return e.jsxs("div",{children:[e.jsxs("div",{className:"flex gap-1 overflow-x-auto border-b",children:[Ia.map(n=>{const v=n.icon,E=!fe&&Ge===n.id;return e.jsxs("button",{type:"button",onClick:()=>{At(null),_s(n.id)},className:ze("flex shrink-0 items-center gap-1.5 rounded-t-md px-3 py-2 text-sm font-medium transition-colors",E?"-mb-px border border-b-0 border-border bg-card text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx(v,{className:"h-3.5 w-3.5"}),n.label]},n.id)}),Ee&&Pt&&js(r.billing_model).map(n=>{const v=n.icon,E=fe===n.id;return e.jsxs("button",{type:"button",onClick:()=>At(n.id),className:ze("flex shrink-0 items-center gap-1.5 rounded-t-md px-3 py-2 text-sm font-medium transition-colors",E?"-mb-px border border-b-0 border-border bg-card text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx(v,{className:"h-3.5 w-3.5"}),n.label]},n.id)})]}),e.jsxs("div",{className:"rounded-b-xl rounded-tr-xl border border-t-0 bg-card p-5 shadow-sm",children:[fe&&e.jsx(Jt,{serviceKey:r.service_key,serviceName:r.name,billingModel:r.billing_model,features:r.features,planFeatures:Mt,canManage:Pt,tab:fe,hideTabs:!0}),!fe&&Ge==="pools"&&e.jsxs("div",{className:"space-y-6",children:[b.length>0&&e.jsxs("div",{children:[(Me==null?void 0:Me.active)&&!!Me.current_period_end&&e.jsxs("p",{className:"px-5 pb-3 text-right text-xs text-muted-foreground",children:["Subscription renews ",Ne(Me.current_period_end)]}),e.jsxs("div",{className:"grid grid-cols-1 divide-y divide-border border-b bg-muted/20 sm:grid-cols-3 sm:divide-x sm:divide-y-0",children:[e.jsxs("div",{className:"px-4 py-3 space-y-0.5 sm:px-5",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Total remaining"}),e.jsx("p",{className:"text-xl font-bold tabular-nums",children:je(Math.max(0,A))})]}),e.jsxs("div",{className:"px-4 py-3 space-y-0.5 sm:px-5",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Total pool"}),e.jsx("p",{className:"text-xl font-bold tabular-nums",children:je(f)})]}),e.jsxs("div",{className:"px-4 py-3 space-y-1.5 sm:px-5",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Used"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-2 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary transition-all",style:{width:`${100-z}%`}})}),e.jsxs("span",{className:"text-sm font-semibold tabular-nums",children:[100-z,"%"]})]})]})]}),b.map((n,v)=>{const E=n.credit_pool-n.credit_spent,ue=100-(n.credit_pool>0?Math.round(E/n.credit_pool*100):0),_=n.pool_expires_at?new Date(n.pool_expires_at*1e3):null,G=_?_<new Date:!1,ge=n.pool_created_at?new Date(n.pool_created_at*1e3):null;return e.jsxs("div",{className:`px-5 py-3.5 flex items-center gap-4 ${v>0?"border-t":""}`,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:ge?`Pool · ${ge.toLocaleDateString(void 0,{month:"short",year:"numeric"})}`:"Credit pool"}),G?e.jsx(q,{variant:"destructive",className:"text-xs shrink-0",children:"Expired"}):_&&e.jsxs("span",{className:"text-xs text-muted-foreground shrink-0",children:["Expires ",_.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${ue>90?"bg-destructive":ue>70?"bg-amber-500":"bg-primary"}`,style:{width:`${ue}%`}})}),e.jsxs("span",{className:"text-xs text-muted-foreground tabular-nums shrink-0",children:[ue,"% used"]})]}),(n.credit_empty_serp>0||n.credit_faulty_serp>0)&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Empty: ",je(n.credit_empty_serp)," · Faulty: ",je(n.credit_faulty_serp)]})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("p",{className:"text-sm font-bold tabular-nums",children:je(Math.max(0,E))}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["of ",je(n.credit_pool)]})]})]},n.pool_id)})]}),(R==null?void 0:R.pool_id)&&(()=>{const n=[];if(R.pool_start&&R.pool_end){const _=new Date(R.pool_start*1e3),G=new Date(Math.min(R.pool_end*1e3,Date.now()));_.setUTCHours(0,0,0,0),G.setUTCHours(0,0,0,0);const ge=new Date(_);for(;ge<=G;){const Ot=ge.toISOString().slice(0,10);n.push({date:Ot,serps:R.daily_chart[Ot]??0}),ge.setUTCDate(ge.getUTCDate()+1)}}else Object.entries(R.daily_chart).sort(([_],[G])=>
51_.localeCompare(G)).forEach(([_,G])=>n.push({date:_,serps:G}));const v=Array.from({length:24},(_,G)=>`${String(G).padStart(2,"0")}:00`),E=nt?R.hourly_charts[nt]??{}:{},Ie=v.map(_=>({hour:_.slice(0,2),serps:E[_]??0})),ue=Object.keys(R.hourly_charts).sort().reverse();return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"font-semibold text-base",children:"Pool activity"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"overflow-hidden rounded-xl border",children:[e.jsxs("div",{className:"flex items-center gap-3 border-b px-6 py-4 bg-muted/20",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-blue-50 text-blue-600",children:e.jsx(xt,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-sm tracking-tight",children:"Daily SERPs"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Requests per day in this pool"})]})]}),e.jsx("div",{className:"p-5",children:n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No data yet."}):e.jsx(be,{width:"100%",height:220,children:e.jsxs(Te,{data:n,margin:{top:4,right:8,left:0,bottom:0},children:[e.jsx(ke,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(_e,{dataKey:"date",tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickLine:!1,axisLine:!1,tickFormatter:_=>{const G=new Date(_+"T00:00:00");return`${G.getDate()}/${G.getMonth()+1}`}}),e.jsx(Ce,{tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickLine:!1,axisLine:!1,tickFormatter:oe,width:36,allowDecimals:!1}),e.jsx(he,{content:e.jsx(Xe,{})}),e.jsx(Oe,{dataKey:"serps",name:"SERPs",fill:"#3b82f6",radius:[3,3,0,0]})]})})})]}),e.jsxs("div",{className:"overflow-hidden rounded-xl border",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b px-6 py-4 bg-muted/20",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-violet-50 text-violet-600",children:e.jsx(os,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-sm tracking-tight",children:"Hourly SERPs"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Requests by hour"})]})]}),ue.length>0&&e.jsx("select",{value:nt,onChange:_=>Ct(_.target.value),className:"h-7 rounded-md border bg-background px-2 text-xs text-foreground",children:ue.map(_=>e.jsx("option",{value:_,children:_},_))})]}),e.jsx("div",{className:"p-5",children:ue.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No data yet."}):e.jsx(be,{width:"100%",height:220,children:e.jsxs(Te,{data:Ie,margin:{top:4,right:8,left:0,bottom:0},children:[e.jsx(ke,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(_e,{dataKey:"hour",tick:{fontSize:10,fill:"hsl(var(--muted-foreground))"},tickLine:!1,axisLine:!1,interval:1}),e.jsx(Ce,{tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickLine:!1,axisLine:!1,tickFormatter:oe,width:36,allowDecimals:!1}),e.jsx(he,{content:e.jsx(Xe,{})}),e.jsx(Oe,{dataKey:"serps",name:"SERPs",fill:"#8b5cf6",radius:[3,3,0,0]})]})})})]})]})]})})(),b.length===0&&xe]}),!fe&&Ge==="limits"&&e.jsxs("div",{className:"space-y-6",children:[g&&H.length>0&&(Ee||A>0)&&e.jsx("div",{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("div",{className:"min-w-[20rem]",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_auto_auto] bg-muted/40 px-4 py-2 text-xs font-medium text-muted-foreground uppercase tracking-wider border-b",children:[e.jsx("span",{children:"Priority"}),e.jsx("span",{className:"px-3 text-right",children:"Per hour"}),e.jsx("span",{className:"pl-3 text-right",children:"Per day"})]}),H.map((n,v)=>{var E,Ie;return e.jsxs("div",{className:`grid grid-cols-[1fr_auto_auto] px-4 py-2.5 text-xs ${v>0?"border-t":""}`,children:[e.jsx("span",{className:"font-medium capitalize",children:n.priority??"Any"}),e.jsx("span",{className:"px-3 tabular-nums text-right text-muted-foreground",children:((E=n.credits_per_hour)==null?void 0:E.toLocaleStr
51ing())??"â"}),e.jsx("span",{className:"pl-3 tabular-nums text-right text-muted-foreground",children:((Ie=n.credits_per_day)==null?void 0:Ie.toLocaleString())??"â"})]},n.id)})]})})}),!(g&&H.length>0&&(Ee||A>0))&&e.jsx("p",{className:"rounded-xl border border-dashed p-10 text-center text-sm text-muted-foreground",children:"No rate limits apply to your account for this service."})]}),!fe&&Ge==="analytics"&&(b.length>0?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[it.length>1?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(Se,{htmlFor:"am",className:"text-xs",children:"Member"}),e.jsxs("select",{id:"am",className:"h-8 rounded-md border bg-background px-2 text-xs",value:lt,onChange:n=>{ws(n.target.value),qe(Le,Fe,n.target.value)},children:[e.jsxs("option",{value:"",children:["All members (",it.length,")"]}),it.map(n=>e.jsxs("option",{value:n.user_id,children:[n.name||n.email,n.role==="owner"?" (owner)":""]},n.user_id))]})]}):e.jsx("div",{}),e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(Se,{htmlFor:"af",className:"text-xs",children:"From"}),e.jsx(Qe,{id:"af",type:"date",value:Le,max:Fe,onChange:n=>dt(n.target.value),className:"h-8 w-36 text-xs"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(Se,{htmlFor:"at",className:"text-xs",children:"To"}),e.jsx(Qe,{id:"at",type:"date",value:Fe,min:Le,max:St,onChange:n=>ot(n.target.value),className:"h-8 w-36 text-xs"})]}),e.jsx(D,{size:"sm",className:"h-8",onClick:()=>qe(Le,Fe),disabled:ct,children:ct?e.jsx(W,{className:"h-3.5 w-3.5 animate-spin"}):"Apply"}),e.jsx("div",{className:"flex gap-1",children:La.map(n=>e.jsx(D,{variant:"outline",size:"sm",className:"h-8 px-2.5 text-xs",onClick:()=>{const v=ye(new Date(Date.now()-(n.days-1)*864e5)),E=ye(new Date);dt(v),ot(E),qe(v,E)},children:n.label},n.label))})]})]}),mt&&e.jsx("p",{className:"text-sm text-destructive",children:mt}),ee&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"rounded-xl border bg-card p-5 shadow-sm space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Credits spent"}),e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-blue-50 text-blue-600",children:e.jsx(Gt,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-2xl font-bold",children:oe(ee.total_credits)}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["over ",we," day",we!==1?"s":""]})]}),e.jsxs("div",{className:"rounded-xl border bg-card p-5 shadow-sm space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Items processed"}),e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-violet-50 text-violet-600",children:e.jsx(ht,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-2xl font-bold",children:oe(ee.total_items)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"requests in period"})]}),e.jsxs("div",{className:"rounded-xl border bg-card p-5 shadow-sm space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Avg credits / day"}),e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-amber-50 text-amber-600",children:e.jsx(xt,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-2xl font-bold",children:oe(we>0?ee.total_credits/we:0)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"daily average"})]})]}),e.jsxs("div",{className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 border-b px-6 py-4 bg-muted/20",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-blue-50 text-blue-600",children:e.jsx(Gt,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-sm tracking-tight",children:"Credits over time"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Daily credit consumption"})]})]}),e.jsx("div",{className:"p-5",children:e.jsx(be,{width:"100%",height:220,children:e.jsxs(xs,{data:ee.timeline,margin:{top:4,right:8,left:0,bottom:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"gradSD",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",
51stopColor:"#3b82f6",stopOpacity:.25}),e.jsx("stop",{offset:"95%",stopColor:"#3b82f6",stopOpacity:0})]})}),e.jsx(ke,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(_e,{dataKey:"date",tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickLine:!1,axisLine:!1,tickFormatter:n=>{const v=new Date(n+"T00:00:00");return`${v.getDate()}/${v.getMonth()+1}`}}),e.jsx(Ce,{tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickLine:!1,axisLine:!1,tickFormatter:oe,width:44}),e.jsx(he,{content:e.jsx(Xe,{})}),e.jsx(us,{type:"monotone",dataKey:"credit_spent",name:"Credits",stroke:"#3b82f6",strokeWidth:2,fill:"url(#gradSD)",dot:!1,activeDot:{r:4}})]})})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"overflow-hidden rounded-xl border",children:[e.jsxs("div",{className:"flex items-center gap-3 border-b px-6 py-4 bg-muted/20",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-violet-50 text-violet-600",children:e.jsx(ht,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-sm tracking-tight",children:"By priority"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Credits per request priority"})]})]}),e.jsx("div",{className:"p-5",children:e.jsx(be,{width:"100%",height:200,children:e.jsxs(Te,{data:ee.by_priority,layout:"vertical",margin:{top:0,right:8,left:0,bottom:0},children:[e.jsx(ke,{strokeDasharray:"3 3",horizontal:!1,stroke:"hsl(var(--border))"}),e.jsx(_e,{type:"number",tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickLine:!1,axisLine:!1,tickFormatter:oe}),e.jsx(Ce,{type:"category",dataKey:"key",tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickLine:!1,axisLine:!1,width:72}),e.jsx(he,{content:e.jsx(Xe,{})}),e.jsx(Oe,{dataKey:"credit_spent",name:"Credits",radius:[0,4,4,0],children:ee.by_priority.map((n,v)=>e.jsx(tt,{fill:We[v%We.length]},v))})]})})})]}),e.jsxs("div",{className:"overflow-hidden rounded-xl border",children:[e.jsxs("div",{className:"flex items-center gap-3 border-b px-6 py-4 bg-muted/20",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-amber-50 text-amber-600",children:e.jsx(xt,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-sm tracking-tight",children:"By service"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Credits per integrated service"})]})]}),e.jsx("div",{className:"p-5",children:e.jsx(be,{width:"100%",height:200,children:e.jsxs(cs,{children:[e.jsx(ms,{data:ee.by_service,dataKey:"credit_spent",nameKey:"key",cx:"50%",cy:"50%",innerRadius:50,outerRadius:80,paddingAngle:3,children:ee.by_service.map((n,v)=>e.jsx(tt,{fill:We[v%We.length]},v))}),e.jsx(he,{formatter:n=>oe(typeof n=="number"?n:Number(n)||0),contentStyle:{borderRadius:"0.5rem",border:"1px solid hsl(var(--border))",fontSize:12}}),e.jsx(wt,{iconType:"circle",iconSize:8,formatter:n=>e.jsx("span",{style:{fontSize:11,color:"hsl(var(--muted-foreground))"},children:n})})]})})})]})]})]}),!ee&&!ct&&!mt&&e.jsx("div",{className:"rounded-xl border border-dashed p-10 text-center",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a date range and click Apply."})})]}),e.jsxs("div",{className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2.5 border-b px-5 py-4",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary",children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-sm",children:"Credit Statement"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Recent SERP activity"})]})]}),bs?e.jsxs("div",{className:"flex items-center gap-2 px-5 py-6 text-sm text-muted-foreground",children:[e.jsx(W,{className:"h-4 w-4 animate-spin"})," Loadingâ¦"]}):L.length===0?e.jsx("div",{className:"px-5 py-6 text-sm text-muted-foreground",children:"No recent SERP activity found."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Es,{children:[e.jsx(Is,{children:e.jsxs(Ht,{children:[e.jsx(ie,{children:"Date"}),L.some(n=>n.member_email)&&e.jsx(ie,{children:"Member"}),e.jsx(ie,{children:"Keyword"}),e.jsx(ie,{children:"Engine"}),e.jsx(ie,{children:"Location"}),e.jsx(ie,{children:"Priority"}),e.jsx(ie,{className:"text-right",children:"Max"}),e.jsx(ie,{className:"text-center",children:"Ready"}),e.jsx(ie,{className:"text-center",children:"Faulty"})]})}),e.jsx(Rs,{children:L.map((n,v)=>e.jsxs(Ht,{className:n.faulty?"bg-red-50/40 dark:bg-red-950/20":"",children:[e.jsx(le,{className:"text-xs text-muted-foreground whitespace-nowrap",children:Pa(n.date)}),L.some(E=>E.member_email)&&e.jsx(le,{className:"text-xs max-w-[160px] truncate",title:n.member_email,children:n.member_name||n.member_email||e.jsx("span",{className:"text-muted-foreground
51/40",children:"â"})}),e.jsx(le,{className:"text-sm font-medium max-w-[200px] truncate",children:n.keyword||e.jsx("span",{className:"text-muted-foreground/40",children:"â"})}),e.jsx(le,{className:"text-sm text-muted-foreground whitespace-nowrap capitalize",children:n.engine||e.jsx("span",{className:"text-muted-foreground/40",children:"â"})}),e.jsx(le,{className:"text-sm text-muted-foreground max-w-[140px] truncate",children:n.location||e.jsx("span",{className:"text-muted-foreground/40",children:"â"})}),e.jsx(le,{className:"text-sm text-muted-foreground",children:n.priority||e.jsx("span",{className:"text-muted-foreground/40",children:"â"})}),e.jsx(le,{className:"text-right tabular-nums text-sm",children:n.max_results??e.jsx("span",{className:"text-muted-foreground/40",children:"â"})}),e.jsx(le,{className:"text-center",children:n.ready?e.jsx(q,{variant:"success",className:"text-xs",children:"Yes"}):e.jsx(q,{variant:"secondary",className:"text-xs",children:"No"})}),e.jsx(le,{className:"text-center",children:n.faulty?e.jsx(q,{variant:"destructive",className:"text-xs",children:"Yes"}):e.jsx("span",{className:"text-muted-foreground/40 text-xs",children:"â"})})]},n.id||v))})]})})]})]}):xe)]})]})})(),!J&&p.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h2",{className:"font-semibold text-base",children:"Available plans"}),V&&e.jsx("div",{className:"flex items-center gap-1 rounded-lg border p-1",children:["monthly","yearly"].map(l=>e.jsxs("button",{type:"button",onClick:()=>U(l),className:`rounded-md px-3 py-1.5 text-sm font-medium transition-colors ${F===l?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,children:[l==="monthly"?"Monthly":"Yearly",l==="yearly"&&K!==null&&e.jsxs("span",{className:`ml-1.5 text-xs ${F===l?"opacity-90":"text-emerald-600"}`,children:["save ",K,"%"]})]},l))})]}),Ke&&e.jsxs("div",{className:"flex items-center gap-2 text-sm rounded-lg border border-primary/30 bg-primary/5 px-4 py-2.5",children:[e.jsx(W,{className:"h-4 w-4 shrink-0 animate-spin"}),"Finishing up â your subscription is being confirmed."]}),Z&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-destructive rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-2.5",children:[e.jsx(De,{className:"h-4 w-4 shrink-0"})," ",Z]}),se.length>0&&e.jsx("div",{className:"rounded-lg border border-amber-300/60 bg-amber-50 dark:bg-amber-950/20 px-4 py-2.5 text-sm text-amber-800 dark:text-amber-300",children:se.map(l=>e.jsxs("p",{children:["Your current plan",l.plan_name?` (${l.plan_name}`:"",l.plan_name?`, ${ts(l.price_cents??0,l.interval_months)})`:""," is no longer offered. It keeps billing until you change or cancel it."]},l.sub_id))}),e.jsx("div",{className:ze("grid grid-cols-1 gap-5",w.length>=4?"sm:grid-cols-2 xl:grid-cols-4":Ls(w.length)),children:w.map(l=>{const u=ss(l,F);return e.jsx(Ea,{group:l,period:F,state:Ma(c,l,u),onSubscribe:Ss,onPay:Et,subscribing:S&&(x==null?void 0:x.plan_id)===u.plan_id,serviceFeatures:r==null?void 0:r.features},l.id)})}),e.jsx(zs,{groups:w,period:F,serviceFeatures:r==null?void 0:r.features})]}),!J&&p.length===0&&!h&&e.jsxs("div",{className:"rounded-xl border border-dashed bg-muted/20 p-8 flex flex-col items-center gap-5 text-center",children:[e.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-full bg-muted",children:e.jsx(ft,{className:"h-7 w-7 text-muted-foreground"})}),e.jsxs("div",{className:"space-y-1.5 max-w-sm",children:[e.jsx("h3",{className:"font-semibold text-base",children:"No plans available yet"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["There are no subscription plans configured for ",r.name," at the moment.",(It=s==null?void 0:s.roles)!=null&&It.includes("admin")?" Create a plan in the admin panel to enable subscriptions for this service.":" Please check back shortly."]})]}),((Rt=s==null?void 0:s.roles)==null?void 0:Rt.includes("admin"))&&e.jsx("div",{className:"flex flex-wrap gap-3 justify-center",children:e.jsxs(D,{variant:"default",className:"gap-2",onClick:()=>a(`/admin/service-plans?service=${t}`),children:[e.jsx(Fs,{className:"h-4 w-4"})," Create plan in Admin"]})})]}),e.jsx(yt,{open:!!O||!!X,onOpenChange:l=>{l||(ae(""),m(""),y(null),ne())},children:e.jsxs(jt,{className:"sm:max-w-md",children:[e.jsx(bt,{children:e.jsx(vt,{children:x?`Subscribe to ${x.name}`:"Complete your payment"})}),X&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-4 text-center",children:[e.jsx(es,{className:"h-9 w-9 text-primary"}),e.jsx("p",{className:"text-sm font-semibold",children:"Complete your payment"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your invoice opened in a new tab. The subscription activates as soon as it is paid."}),e.jsx("a",{href:X,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary underline underline-offset-2",children:"Open the invoice again"})]}),O&&e.jsx(Os,{clientSecret:O,submitLabel:`Pay ${x?Re(x.price_cents):""}`,onSuccess:()=>{ae(""),y(null),ne()},onError:l=>I(l)}),e.jsx(Nt,{children:e.jsx(D,{variant:"ghost",onClick:()=>{ae(""),m(""),y(null),ne()},children:X?"Close":"Cancel"})})]})}),He&&e.jsx(rs,{open:He,serviceKey:r.service_key,initialTab:d,onClose:()=>{me(!1),ne()}})]}):null}export{pr 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.