1import{bw as he,r as N,g as M,i as q,j as e,G as k,L as ue,aC as je,a0 as pe,E as $,_ as ge,gO as U,b8 as fe,bN as G,U as Ne,gN as be,a$ as I,gP as ye,J as K,bX as ve,c$ as we,cY as z,bo as ke,I as Se}from"./vendor-BeA4siBz.js";import{u as Ce,f as W,q as V,B as p,g as d,C as c,a as o,b as x,c as J,d as m,D as X,F as Y,h as Z,j as Q,k as ee,I as se,Y as ae}from"./index-C2NQ_9nj.js";import{L as g}from"./label-BgiDwF3G.js";import{T as te}from"./textarea-BzoSp81z.js";import{S as re,a as ne,b as le,c as ie,d as f}from"./select-26Ep3yy3.js";import{S as de}from"./separator-CtoFHc0k.js";function Be(){var _;const{userId:l}=he(),{toast:u}=Ce(),[ce,L]=N.useState(!1),[oe,H]=N.useState(!1),[t,b]=N.useState(""),[y,v]=N.useState(""),[w,P]=N.useState("reward"),{data:B,isLoading:xe}=M({queryKey:["/api/admin/user-financial",l],queryFn:()=>ae(`/api/admin/user-financial/${l}`),enabled:!!l}),{data:r,isLoading:S,refetch:C}=M({queryKey:["/api/admin/user-financial",l,"hpg-wallet"],queryFn:()=>ae(`/api/admin/user-financial/${l}/hpg-wallet`),enabled:!!l}),T=q({mutationFn:async s=>(await W("POST",`/api/admin/user-financial/${l}/grant-tokens`,s)).json(),onSuccess:s=>{V.invalidateQueries({queryKey:["/api/admin/user-financial",l]}),C(),L(!1),b(""),v(""),s.hpgSynced?u({title:"Tokens granted & synced to Harbor OS"}):u({title:"Tokens granted locally",description:s.hpgError?`Harbor OS sync failed: ${s.hpgError}`:"Harbor OS sync pending",variant:s.hpgError?"destructive":"default"})},onError:s=>{u({title:"Error",description:s.message,variant:"destructive"})}}),A=q({mutationFn:async s=>(await W("POST",`/api/admin/user-financial/${l}/deduct-tokens`,s)).json(),onSuccess:s=>{V.invalidateQueries({queryKey:["/api/admin/user-financial",l]}),C(),H(!1),b(""),v(""),s.hpgSynced?u({title:"Tokens deducted & synced to Harbor OS"}):u({title:"Tokens deducted locally",description:s.hpgError?`Harbor OS sync failed: ${s.hpgError}`:"Harbor OS sync pending",variant:s.hpgError?"destructive":"default"})},onError:s=>{u({title:"Error",description:s.message,variant:"destructive"})}});if(xe)return e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(k,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!B)return e.jsx("div",{className:"container mx-auto py-6 max-w-5xl",children:e.jsx("p",{className:"text-muted-foreground",children:"User not found."})});const{user:i,wallet:O,transactions:F,tokenUsage:D,subscriptionHistory:E,storage:h}=B,me=h.includedMb>0?Math.round(h.usedMb/h.includedMb*100):0,n=r==null?void 0:r.wallet,a=r==null?void 0:r.quota;return e.jsxs("div",{className:"container mx-auto py-6 max-w-5xl space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(ue,{href:"/admin/users",children:e.jsx(p,{variant:"ghost",size:"icon",children:e.jsx(je,{className:"h-5 w-5"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h1",{className:"text-2xl font-bold",children:i.fullName||i.email}),e.jsx("p",{className:"text-muted-foreground",children:i.email}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(d,{variant:"outline",children:i.role}),e.jsx(d,{variant:"secondary",children:i.subscriptionTier||"free"}),(a==null?void 0:a.accountSuspended)&&e.jsx(d,{variant:"destructive",children:"Suspended"}),(a==null?void 0:a.disputeRisk)&&e.jsx(d,{variant:"destructive",children:"Dispute Risk"}),(a==null?void 0:a.isAdminBypass)&&e.jsx(d,{className:"bg-amber-500",children:"Admin Bypass"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs(c,{children:[e.jsxs(o,{children:[e.jsxs(x,{className:"flex items-center gap-2 text-lg",children:[e.jsx(pe,{className:"h-5 w-5"}),"Local Wallet"]}),e.jsx(J,{children:"HS3 internal token balance"})]}),e.jsxs(m,{children:[e.jsxs("div",{className:"text-3xl font-bold mb-4",children:[e.jsx($,{className:"h-6 w-6 inline mr-2 text-amber-500"}),O?parseFloat(O.balance).toLocaleString():"0"," tokens"]}),!O&&e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"No wallet created yet"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(X,{open:ce,onOpenChange:L,children:[e.jsx(Y,{asChild:!0,children:e.jsxs(p,{size:"sm",className:"gap-1",children:[e.jsx(ge,{className:"h-4 w-4"})," Credit"]})}),e.jsxs(Z,{children:[e.jsx(Q,{children:e.jsxs(ee,{children:["Credit Tokens to ",i.fullName||i.email]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Amount"}),e.jsx(se,{type:"number",min:"1",value:t,onChange:s=>b(s.target.value),placeholder:"Token amount"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Token Category"}),e.jsxs(re,{value:w,onValueChange:P,children:[e.jsx(ne,{children:e.jsx(le,{})}),e.jsxs(ie,{children:[e.jsx(f,{value:"reward",children:"Reward Tokens"}),e.jsx(f,{value:"product",children:"Product Tokens"}),e.jsx(f,{value:"promo",children:"Promo Tokens"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Category tells Harbor OS how to classify this credit"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Reason"}),e.jsx(te,{value:y,onChange:s=>v(s.target.value),placeholder:"e.g. Customer goodwill, refund, promotion...",rows:2})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground bg-muted p-2 rounded",children:[e.jsx(U,{className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{children:"This will update the local wallet and attempt to sync with Harbor OS (HPG)"})]}),e.jsxs(p,{onClick:()=>T.mutate({amount:parseFloat(t),reason:y,tokenCategory:w}),disabled:!t||parseFloat(t)<=0||T.isPending,className:"w-full",children:[T.isPending&&e.jsx(k,{className:"h-4 w-4 animate-spin mr-1"}
1),"Credit ",t?parseFloat(t).toLocaleString():"0"," Tokens"]})]})]})]}),e.jsxs(X,{open:oe,onOpenChange:H,children:[e.jsx(Y,{asChild:!0,children:e.jsxs(p,{size:"sm",variant:"destructive",className:"gap-1",children:[e.jsx(fe,{className:"h-4 w-4"})," Debit"]})}),e.jsxs(Z,{children:[e.jsx(Q,{children:e.jsxs(ee,{children:["Debit Tokens from ",i.fullName||i.email]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Amount"}),e.jsx(se,{type:"number",min:"1",value:t,onChange:s=>b(s.target.value),placeholder:"Token amount"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Token Category"}),e.jsxs(re,{value:w,onValueChange:P,children:[e.jsx(ne,{children:e.jsx(le,{})}),e.jsxs(ie,{children:[e.jsx(f,{value:"reward",children:"Reward Tokens"}),e.jsx(f,{value:"product",children:"Product Tokens"}),e.jsx(f,{value:"promo",children:"Promo Tokens"})]})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Reason"}),e.jsx(te,{value:y,onChange:s=>v(s.target.value),placeholder:"e.g. Chargeback, abuse, correction...",rows:2})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground bg-muted p-2 rounded",children:[e.jsx(G,{className:"h-4 w-4 flex-shrink-0 text-amber-500"}),e.jsx("span",{children:"This deduction will be synced to Harbor OS. The user will see the change immediately."})]}),e.jsxs(p,{variant:"destructive",onClick:()=>A.mutate({amount:parseFloat(t),reason:y,tokenCategory:w}),disabled:!t||parseFloat(t)<=0||A.isPending,className:"w-full",children:[A.isPending&&e.jsx(k,{className:"h-4 w-4 animate-spin mr-1"}),"Debit ",t?parseFloat(t).toLocaleString():"0"," Tokens"]})]})]})]})]})]})]}),e.jsxs(c,{children:[e.jsxs(o,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(x,{className:"flex items-center gap-2 text-lg",children:[e.jsx(U,{className:"h-5 w-5"}),"Harbor OS Wallet"]}),e.jsx(p,{variant:"ghost",size:"icon",onClick:()=>C(),disabled:S,children:e.jsx(Ne,{className:`h-4 w-4 ${S?"animate-spin":""}`})})]}),e.jsx(J,{children:"Token balance on Harbor Platform Gateway"})]}),e.jsx(m,{children:S?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(k,{className:"h-4 w-4 animate-spin"}),"Loading HPG data..."]}):r!=null&&r.available?n?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-3xl font-bold",children:[e.jsx($,{className:"h-6 w-6 inline mr-2 text-blue-500"}),n.totalBalance.toLocaleString()," tokens"]}),e.jsx(de,{}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-950/30 rounded p-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Product"}),e.jsx("p",{className:"font-bold text-lg",children:n.productTokens.toLocaleString()})]}),e.jsxs("div",{className:"bg-green-50 dark:bg-green-950/30 rounded p-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Reward"}),e.jsx("p",{className:"font-bold text-lg",children:n.rewardTokens.toLocaleString()})]}),e.jsxs("div",{className:"bg-purple-50 dark:bg-purple-950/30 rounded p-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Promo"}),e.jsx("p",{className:"font-bold text-lg",children:n.promoTokens.toLocaleString()})]}),e.jsxs("div",{className:"bg-amber-50 dark:bg-amber-950/30 rounded p-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Locked"}),e.jsx("p",{className:"font-bold text-lg",children:n.lockedTokens.toLocaleString()})]})]}),n.offlineBuffer&&e.jsxs("div",{className:"text-xs text-muted-foreground flex justify-between",children:[e.jsxs("span",{children:["Offline Buffer: ",n.offlineBuffer.remaining,"/",n.offlineBuffer.allowance]}),n.expiresAt&&e.jsxs("span",{children:["Expires: ",new Date(n.expiresAt).toLocaleDateString()]})]})]}):null:e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(be,{className:"h-5 w-5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Harbor OS Unavailable"}),e.jsx("p",{className:"text-xs",children:(r==null?void 0:r.reason)||"Not connected"})]})]})})]})]}),a&&e.jsxs(c,{children:[e.jsx(o,{children:e.jsxs(x,{className:"flex items-center gap-2 text-lg",children:[e.jsx(I,{className:"h-5 w-5"}),"Harbor OS Account Status"]})}),e.jsxs(m,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[a.accountSuspended?e.
1jsx(ye,{className:"h-5 w-5 text-red-500"}):e.jsx(K,{className:"h-5 w-5 text-green-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Account"}),e.jsx("p",{className:"font-medium text-sm",children:a.accountSuspended?"Suspended":"Active"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a.disputeRisk?e.jsx(G,{className:"h-5 w-5 text-amber-500"}):e.jsx(K,{className:"h-5 w-5 text-green-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Dispute Risk"}),e.jsx("p",{className:"font-medium text-sm",children:a.disputeRisk?"Flagged":"Clear"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a.isAdminBypass?e.jsx(I,{className:"h-5 w-5 text-amber-500"}):e.jsx(ve,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Admin Bypass"}),e.jsx("p",{className:"font-medium text-sm",children:a.isAdminBypass?"Enabled":"Off"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Grace Policy"}),e.jsxs("p",{className:"font-medium text-sm",children:[((_=a.gracePolicy)==null?void 0:_.max_grace_tokens_per_user_per_day)??0," tokens/day"]})]})]}),a.offlineBuffer&&e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"my-3"}),e.jsxs("div",{className:"flex gap-6 text-sm",children:[e.jsxs("span",{children:["Offline: ",a.offlineBuffer.monthly_used,"/",a.offlineBuffer.monthly_cap," monthly"]}),a.offlineBuffer.abuse_flagged&&e.jsx(d,{variant:"destructive",children:"Abuse Flagged"})]})]}),a.generatedAt&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["Snapshot: ",new Date(a.generatedAt).toLocaleString()]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs(c,{children:[e.jsx(o,{children:e.jsxs(x,{className:"flex items-center gap-2 text-lg",children:[e.jsx(we,{className:"h-5 w-5"}),"Storage"]})}),e.jsx(m,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{children:[h.usedMb," MB used"]}),e.jsxs("span",{children:[h.includedMb," MB included"]})]}),e.jsx("div",{className:"h-2 w-full bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary rounded-full transition-all",style:{width:`${Math.min(me,100)}%`}})}),e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:["Plan: ",h.planKey]}),e.jsxs("span",{children:["Overage: ",h.overageRate," tokens/GB"]})]})]})})]}),(a==null?void 0:a.featureAllowances)&&Object.keys(a.featureAllowances).length>0&&e.jsxs(c,{children:[e.jsx(o,{children:e.jsxs(x,{className:"flex items-center gap-2 text-lg",children:[e.jsx(z,{className:"h-5 w-5"}),"Feature Allowances"]})}),e.jsx(m,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Feature"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Tokens/Unit"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Est. Units"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Mode"})]})}),e.jsx("tbody",{children:Object.entries(a.featureAllowances).map(([s,j])=>{var R;return e.jsxs("tr",{className:"border-b last:border-0",children:[e.jsx("td",{className:"px-4 py-2 font-mono text-xs",children:j.feature_key}),e.jsx("td",{className:"px-4 py-2 text-right",children:j.tokens_per_unit}),e.jsx("td",{className:"px-4 py-2 text-right",children:(R=j.estimated_units_available)==null?void 0:R.toLocaleString()}),e.jsx("td",{className:"px-4 py-2",children:e.jsx(d,{variant:"outline",className:"text-xs",children:j.enforcement_mode})})]},s)})})]})})})]})]}),e.jsxs(c,{children:[e.jsx(o,{children:e.jsxs(x,{className:"flex items-center gap-2 text-lg",children:[e.jsx(z,{className:"h-5 w-5"}),"Token Usage by Feature (Local)"]})}),e.jsx(m,{className:"p-0",children:D.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"No token usage recorded"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Feature"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Total Tokens"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Total Cost (cents)"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Count"})]})}),e.jsx("tbody",{children:D.map(s=>e.jsxs("tr",{className:"border-b last:border-0",children:[e.jsx("td",{className:"px-4 py-2 font-mono text-xs",children:s.featureKey}),e.jsx("td",{className:"px-4 py-2 text-right",children:Number(s.totalTokens).toLocaleStr
1ing()}),e.jsx("td",{className:"px-4 py-2 text-right",children:Number(s.totalCost).toFixed(2)}),e.jsx("td",{className:"px-4 py-2 text-right",children:s.count})]},s.featureKey))})]})})})]}),e.jsxs(c,{children:[e.jsx(o,{children:e.jsxs(x,{className:"flex items-center gap-2 text-lg",children:[e.jsx(ke,{className:"h-5 w-5"}),"Transaction History"]})}),e.jsx(m,{className:"p-0",children:F.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"No transactions"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Type"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Amount"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Description"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Balance After"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Date"})]})}),e.jsx("tbody",{children:F.map(s=>e.jsxs("tr",{className:"border-b last:border-0",children:[e.jsx("td",{className:"px-4 py-2",children:e.jsx(d,{variant:parseFloat(s.amount)>=0?"secondary":"destructive",className:"text-xs",children:s.type})}),e.jsx("td",{className:"px-4 py-2 text-right font-mono",children:s.amount}),e.jsx("td",{className:"px-4 py-2 text-muted-foreground max-w-[200px] truncate",children:s.description}),e.jsx("td",{className:"px-4 py-2 text-right font-mono",children:s.balanceAfter}),e.jsx("td",{className:"px-4 py-2 text-right text-muted-foreground",children:new Date(s.createdAt).toLocaleDateString()})]},s.id))})]})})})]}),e.jsxs(c,{children:[e.jsx(o,{children:e.jsxs(x,{className:"flex items-center gap-2 text-lg",children:[e.jsx(Se,{className:"h-5 w-5"}),"Subscription History"]})}),e.jsx(m,{className:"p-0",children:E.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"No subscription history"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Plan ID"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Amount"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Status"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Date"})]})}),e.jsx("tbody",{children:E.map(s=>e.jsxs("tr",{className:"border-b last:border-0",children:[e.jsx("td",{className:"px-4 py-2",children:s.planId}),e.jsx("td",{className:"px-4 py-2 text-right font-mono",children:s.amount}),e.jsx("td",{className:"px-4 py-2",children:e.jsx(d,{variant:s.status==="completed"?"secondary":"outline",className:"text-xs",children:s.status})}),e.jsx("td",{className:"px-4 py-2 text-right text-muted-foreground",children:new Date(s.transactionDate).toLocaleDateString()})]},s.id))})]})})})]})]})}export{Be 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.