import{o as e}from"./rolldown-runtime-BM3Ffeng.js";import{Gy as t,ap as n,kn as r,lh as i,op as a}from"./index-DDwwBb9e.js";var o=e(t());function s(){let{data:e}=a(),{organization:t}=n({redirectToOnboarding:!1}),s=e?.user.email??`you@example.com`,c=e?.user.name??`You`,l=t?.name??`Your organization`,u=t?.id??`org_unknown`,d=i.user.personalContext.useQuery({organizationId:u},{enabled:!!t,refetchOnWindowFocus:!1}),f=i.personalVirtualKeys.list.useQuery({organizationId:u},{enabled:!!t,refetchOnWindowFocus:!1}),p=i.user.personalUsage.useQuery({organizationId:u},{enabled:!!t,refetchOnWindowFocus:!1}),m=i.user.personalBudget.useQuery({organizationId:u},{enabled:!!t,refetchOnWindowFocus:!1}),h=(0,o.useMemo)(()=>{let e=m.data;return!e||!(`limitUsd`in e)?{status:`ok`}:{status:e.status,spentUsd:Number(e.spentUsd),limitUsd:Number(e.limitUsd),period:e.period??``,scope:e.scope??``,requestIncreaseUrl:`requestIncreaseUrl`in e?e.requestIncreaseUrl??null:null,adminEmail:`adminEmail`in e?e.adminEmail??null:null}},[m.data]),g=(0,o.useMemo)(()=>{let e=f.data;return e?e.map(e=>({id:e.id,label:e.name,deviceHint:e.description??`Personal device`,os:`Unknown`,lastUsedAt:e.lastUsedAt?e.lastUsedAt.toISOString():null,createdAt:e.createdAt.toISOString()})):[]},[f.data]),_=r(),v=(0,o.useMemo)(()=>({..._,current:{kind:`personal`}}),[_]);return{ready:!!e&&!!t,email:s,fullName:c,joinedOn:d.data?.workspace.team.createdAt?.toISOString()?.slice(0,10)??`—`,organizationName:l,organizationId:u,routingPolicyName:d.data?.routingPolicy?.name??null,switcher:v,summary:{spentThisMonthUsd:p.data?.summary.spentUsd??0,budgetUsd:`limitUsd`in h?h.limitUsd:null,requestsThisMonth:p.data?.summary.requests??0,requestsDeltaPctVsLastMonth:null,mostUsedModel:p.data?.summary.mostUsedModel??null},budget:h,spendByDay:p.data?.dailyBuckets.map(e=>({day:e.day,usd:e.spentUsd}))??[],spendByTool:p.data?.breakdownByModel.map(e=>({tool:e.label,usd:e.spentUsd}))??[],recentActivity:p.data?.recentActivity.map(e=>({id:e.traceId,occurredAt:e.occurredAt,toolName:e.models[0]??`—`,summary:e.preview,costUsd:e.spentUsd}))??[],apiKeys:g}}export{s as t};
//# sourceMappingURL=usePersonalContext-D6TPWQNi.js.map