@stacknet/keyutils 0.4.8 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import Kr,{createContext,useContext,useMemo,useState,useRef,useEffect,useCallback}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {Loader2,CheckCircle,Check,Copy,CreditCard,Wallet,Download,X as X$1,ArrowLeft,KeyRound,ExternalLink,AlertTriangle,ChevronDown,ChevronRight,Send,CheckCircle2,AlertCircle,Info,FileText,Minus,Plus,ChevronUp}from'lucide-react';function G(){if(typeof document>"u")return {};let e=document.cookie.match(/(?:^|;\s*)__csrf=([^;]*)/);return e?{"x-csrf-token":e[1]}:{}}var Dt=500;function it(e,t){if(typeof e!="string"||e.length===0)return t;let r=e.replace(/[\u0000-\u001F\u007F]/g," ");return r.length>500?r.slice(0,500)+"\u2026":r}async function U(e,t){try{let r=await e.json();if(r&&typeof r=="object"&&"error"in r)return it(r.error,t)}catch{}return t}function F(e,t="#"){if(!e||typeof e!="string")return t;let r=e.trim();if(r===""||r==="#")return t;if(r.startsWith("/")||r.startsWith("./")||r.startsWith("../"))return r;try{let s=new URL(r);if(s.protocol==="http:"||s.protocol==="https:")return s.toString()}catch{}return t}function f(...e){return twMerge(clsx(e))}function T(e){return e==null?"0":e>=1e9?`${(e/1e9).toFixed(1)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function lt(e,t){return t<=0?0:Math.min(100,Math.round(e/t*100))}function ct(e){return e>=70?"bg-green-500":e>=30?"bg-yellow-500":"bg-red-500"}function X(e){if(e==null||e==="")return "";let t=typeof e=="string"&&/^\d+$/.test(e)?Number(e):e,r=new Date(t);return isNaN(r.getTime())?"":r.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function dt(){if(typeof navigator>"u")return "mac";let e=navigator.userAgent.toLowerCase();return /iphone|ipad|ipod/.test(e)?"ios":/android/.test(e)?"android":/win/.test(e)?"windows":/linux/.test(e)?"linux":"mac"}var ut=createContext(null);function h(){let e=useContext(ut);if(!e)throw new Error("useKeyUtilsContext must be used within a KeyUtilsProvider");return e}function Ie({config:e,callbacks:t={},children:r}){typeof e.apiBaseUrl!="string"&&console.error("[KeyUtils] apiBaseUrl must be a string");let s=useMemo(()=>({config:e,callbacks:t}),[e,t]);return jsx(ut.Provider,{value:s,children:r})}function Ue(){let{config:e}=h(),[t,r]=useState(null),[s,u]=useState(true),[c,a]=useState(null),o=useRef(true),n=useRef(e.apiBaseUrl);n.current=e.apiBaseUrl;let i=async()=>{try{o.current&&(u(!0),a(null));let l=await fetch(`${n.current}/api/keys/pricing`,{credentials:"include"});if(!l.ok)throw new Error(await U(l,`Pricing unavailable (${l.status})`));let m=await l.json();o.current&&r(m);}catch(l){o.current&&a(l instanceof Error?l.message:"Failed to fetch pricing");}finally{o.current&&u(false);}};return useEffect(()=>{o.current=true,i();let l=setInterval(i,6e4);return ()=>{o.current=false,clearInterval(l);}},[]),{pricing:t,loading:s,error:c,refresh:i}}function Xt(e){return {id:e.id||"",keyIndex:e.keyIndex??e.key_index??null,key:e.key||e.keyPrefix||"",userId:e.userId||e.user_id||"",status:e.status||"active",tokenBalance:e.tokenBalance??e.currentTokenBalance??e.current_token_balance??0,maxTokens:e.maxTokens??e.initialTokenBalance??e.initial_token_balance??0,createdAt:String(e.createdAt??e.created_at??""),expiresAt:e.expiresAt,label:e.label||e.keyPrefix||e.key_prefix||void 0,paperWork:e.paperWork||e.paper_work||void 0,stackId:e.stackId,stackName:e.stackName}}function H(){let{config:e}=h(),[t,r]=useState([]),[s,u]=useState(true),[c,a]=useState(null),o=useRef(true),n=e.apiBaseUrl,i=useCallback(async()=>{try{u(!0),a(null);let m=await fetch(`${n}/api/keys`,{credentials:"include"});if(!m.ok)throw new Error(await U(m,`Failed to fetch keys (${m.status})`));let p=await m.json(),d=Array.isArray(p)?p:p.keys??[];o.current&&r(d.map(Xt));}catch(m){o.current&&a(m instanceof Error?m.message:"Failed to fetch keys");}finally{o.current&&u(false);}},[n]);useEffect(()=>(o.current=true,i(),()=>{o.current=false;}),[i]);let l=t.reduce((m,p)=>m+p.tokenBalance,0);return {keys:t,totalBalance:l,loading:s,error:c,refresh:i}}function Be(e){let t=e.type||e.entry_type||"debit",r=e.amount??e.tokens??e.token_amount??0,s=e.description||e.memo||e.reason||Zt(t);return {id:e.id||"",keyId:e.keyId||e.key_id||"",type:t,amount:r,description:s,createdAt:String(e.createdAt??e.created_at??e.timestamp??""),metadata:e.metadata||void 0}}function Zt(e){switch(e){case "credit":return "Credit";case "debit":return "Usage";case "mint":return "Mint";case "reward":return "Reward";default:return ""}}function er(e){return {id:e.id||"",keyIndex:e.keyIndex??e.key_index??null,key:e.key||e.keyPrefix||"",userId:e.userId||e.user_id||"",status:e.status||"active",tokenBalance:e.tokenBalance??e.currentTokenBalance??e.current_token_balance??0,maxTokens:e.maxTokens??e.initialTokenBalance??e.initial_token_balance??0,createdAt:String(e.createdAt??e.created_at??""),expiresAt:e.expiresAt,label:e.label||e.keyPrefix||e.key_prefix||void 0,paperWork:e.paperWork||e.paper_work||void 0,stackId:e.stackId,stackName:e.stackName}}async function tr(e){if(!e)return {};let t=e();return t instanceof Promise?await t:t}async function oe(e,t={}){let{getHeaders:r,...s}=t,u=await tr(r),c=await fetch(e,{...s,headers:{"Content-Type":"application/json",...u,...s.headers},credentials:"include"});if(!c.ok)throw new Error(await U(c,`Request failed (${c.status})`));return c.json()}function rr(e){let{apiBaseUrl:t,stackId:r,stackName:s,getHeaders:u}=e,c=`${t}/api/keys`;return {async getKeys(){let a=await oe(c,{getHeaders:u});return (Array.isArray(a)?a:a.keys??[]).map(er)},async getLedger(a){let o=await oe(`${c}/${encodeURIComponent(a)}/ledger`,{getHeaders:u});return (Array.isArray(o)?o:o.entries??[]).map(Be)},async getPricing(){return oe(`${c}/pricing`,{getHeaders:u})},async mint(a,o,n=1){try{let i=await oe(c+"/mint",{method:"POST",body:JSON.stringify({paymentMethod:a,paymentRef:o,quantity:n,stackId:r}),getHeaders:u}),l=i.keys?.[0]||i;return {success:!0,key:{id:l.keyId||l.id||"",key:l.key||"",userId:l.userId||"",status:"active",tokenBalance:l.tokenBalance??l.currentTokenBalance??0,maxTokens:l.initialTokenBalance??l.tokenBalance??0,createdAt:String(l.createdAt||Date.now())},transactionId:o}}catch(i){return {success:false,error:i instanceof Error?i.message:"Key generation failed"}}},async listKey(a,o){return oe(`${c}/${encodeURIComponent(a)}/list`,{method:"POST",body:JSON.stringify({askPriceCents:o,stackId:r,stackName:s}),getHeaders:u})},async delistKey(a){await oe(`${c}/${encodeURIComponent(a)}/list`,{method:"DELETE",getHeaders:u});},async transferKey(a,o){return oe(`${c}/${encodeURIComponent(a)}/transfer`,{method:"POST",body:JSON.stringify({recipientId:o}),getHeaders:u})},async createStripeSession(a,o,n){return oe(`${c}/stripe-session`,{method:"POST",body:JSON.stringify({priceCents:a,quantity:o,stackId:r,referrerUrl:n}),getHeaders:u})}}}function ge(e){let{config:t}=h(),[r,s]=useState([]),[u,c]=useState(false),[a,o]=useState(null),n=useRef(true),i=t.apiBaseUrl,l=useCallback(async()=>{if(e)try{c(!0),o(null);let m=await fetch(`${i}/api/keys/${encodeURIComponent(e)}/ledger`,{credentials:"include"});if(!m.ok)throw new Error(await U(m,`Failed to fetch ledger (${m.status})`));let p=await m.json(),d=Array.isArray(p)?p:p.entries??[];n.current&&s(d.map(Be));}catch(m){n.current&&o(m instanceof Error?m.message:"Failed to fetch ledger");}finally{n.current&&c(false);}},[i,e]);return useEffect(()=>(n.current=true,l(),()=>{n.current=false;}),[l]),{entries:r,loading:u,error:a,refresh:l}}function Ae(){let{config:e,callbacks:t}=h(),[r,s]=useState(false),[u,c]=useState(null),[a,o]=useState(null);return {mint:useCallback(async(i,l,m=1)=>{try{s(!0),o(null),t.onPaymentComplete?.(i,l);let p=await fetch(`${e.apiBaseUrl}/api/keys/mint`,{method:"POST",headers:{"Content-Type":"application/json",...G()},credentials:"include",body:JSON.stringify({paymentMethod:i,paymentRef:l,quantity:m,stackId:e.stackId})});if(!p.ok)throw new Error(await U(p,`Key generation failed (${p.status})`));let d=await p.json(),g=d.keys?.[0]||d,k={success:!0,key:{id:g.keyId||g.id||"",key:g.key||"",userId:g.userId||"",status:"active",tokenBalance:g.tokenBalance??g.currentTokenBalance??0,maxTokens:g.initialTokenBalance??g.tokenBalance??0,createdAt:String(g.createdAt||Date.now())},transactionId:l};return c(k),t.onMintSuccess?.(k),k}catch(p){let d=p instanceof Error?p:new Error("Key generation failed");return o(d.message),t.onMintError?.(d),{success:false,error:d.message}}finally{s(false);}},[e.apiBaseUrl,t]),minting:r,result:u,error:a}}function xe(){let{config:e,callbacks:t}=h(),[r,s]=useState(false),[u,c]=useState(null),[a,o]=useState(null),n=useRef(true),i=useCallback(async(m,p)=>{try{s(!0),o(null);let d=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(m)}/list`,{method:"POST",headers:{"Content-Type":"application/json",...G()},credentials:"include",body:JSON.stringify({askPriceCents:p,stackId:e.stackId,stackName:e.stackName})});if(!d.ok)throw new Error(await U(d,`Listing failed (${d.status})`));let g=await d.json();return n.current&&(c(g),t.onListingCreated?.(g)),g}catch(d){let g=d instanceof Error?d.message:"Listing failed";return n.current&&o(g),null}finally{n.current&&s(false);}},[e.apiBaseUrl,e.stackId,e.stackName,t]),l=useCallback(async m=>{try{s(!0),o(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(m)}/list`,{method:"DELETE",headers:{...G()},credentials:"include"});if(!p.ok)throw new Error(await U(p,`Delist failed (${p.status})`));return n.current&&c(null),!0}catch(p){let d=p instanceof Error?p.message:"Delist failed";return n.current&&o(d),false}finally{n.current&&s(false);}},[e.apiBaseUrl]);return {listKey:i,delistKey:l,listing:r,result:u,error:a}}function Me(){let{config:e}=h(),[t,r]=useState(false),[s,u]=useState(null),c=useRef(true);return {createSession:useCallback(async(o,n)=>{try{r(!0),u(null);let i=await fetch(`${e.apiBaseUrl}/api/keys/stripe-session`,{method:"POST",headers:{"Content-Type":"application/json",...G()},credentials:"include",body:JSON.stringify({priceCents:o,quantity:n,stackId:e.stackId,referrerUrl:window.location.href})});if(!i.ok)throw new Error(await U(i,`Checkout failed (${i.status})`));let{url:l}=await i.json();if(!l)throw new Error("No checkout URL returned");let m;try{m=new URL(l);}catch{throw new Error("Invalid checkout URL")}if(m.protocol!=="https:"||!/(^|\.)stripe\.com$/.test(m.hostname))throw new Error("Refusing to redirect to non-Stripe URL");try{sessionStorage.setItem("keyutils_stripe_pending","1"),sessionStorage.setItem("keyutils_stripe_quantity",String(n));}catch{}window.location.href=m.toString();}catch(i){if(c.current){let l=i instanceof Error?i.message:"Checkout failed";u(l),r(false);}}},[e.apiBaseUrl,e.stackId]),loading:t,error:s}}var xt=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function ur(){let{config:e}=h(),[t,r]=useState(false),[s,u]=useState(null);return {pay:useCallback(async a=>{if(!e.merchantWallet||!xt.test(e.merchantWallet))throw new Error("Merchant wallet not configured");try{r(!0),u(null);let{Connection:o,PublicKey:n,Transaction:i,SystemProgram:l}=await import('@solana/web3.js'),m=typeof window<"u"?window.solana:void 0;if(!m||typeof m!="object"||!m.isPhantom)throw new Error("Phantom wallet not found. Please install Phantom.");let p=m,d=new n(e.merchantWallet),g=await p.connect(),k=new n(g.publicKey.toString()),I="https://api.mainnet-beta.solana.com",w=F(e.solanaRpcUrl,I),B=w==="#"?I:w,j=new o(B),{blockhash:P}=await j.getLatestBlockhash(),z=BigInt(Math.floor(a*1e9)),E=e.protocolTreasuryWallet,_=e.protocolFeeBps??500,q=new i({recentBlockhash:P,feePayer:k});if(E&&xt.test(E)&&_>0){let ue=z*BigInt(_)/10000n,D=z-ue,Q=new n(E);q.add(l.transfer({fromPubkey:k,toPubkey:d,lamports:Number(D)}),l.transfer({fromPubkey:k,toPubkey:Q,lamports:Number(ue)}));}else q.add(l.transfer({fromPubkey:k,toPubkey:d,lamports:Number(z)}));let{signature:ne}=await p.signAndSendTransaction(q);return ne}catch(o){let n=o instanceof Error?o:new Error("SOL payment failed");throw u(n.message),n}finally{r(false);}},[e.merchantWallet,e.protocolTreasuryWallet,e.protocolFeeBps,e.solanaRpcUrl]),processing:t,error:s}}function ye(){let{config:e,callbacks:t}=h(),[r,s]=useState(false),[u,c]=useState(null),[a,o]=useState(null),n=useRef(true);return {transferKey:useCallback(async(l,m)=>{try{s(!0),o(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(l)}/transfer`,{method:"POST",headers:{"Content-Type":"application/json",...G()},credentials:"include",body:JSON.stringify({recipientId:m})});if(!p.ok)throw new Error(await U(p,`Transfer failed (${p.status})`));let d=await p.json();return n.current&&(c(d),t.onTransferComplete?.(d)),d}catch(p){let d=p instanceof Error?p.message:"Transfer failed";return n.current&&o(d),null}finally{n.current&&s(false);}},[e.apiBaseUrl,t]),transferring:r,result:u,error:a}}function De(){let{config:e,callbacks:t}=h(),[r,s]=useState(false),[u,c]=useState(null),[a,o]=useState(null),n=useRef(true),i=useCallback(async m=>{try{s(!0),o(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(m)}/file`,{method:"POST",headers:{"Content-Type":"application/json",...G()},credentials:"include",body:JSON.stringify({stackId:e.stackId})});if(!p.ok)throw new Error(await U(p,`Filing failed (${p.status})`));let d=await p.json();return n.current&&(c(d),t.onFilingComplete?.(d)),d}catch(p){let d=p instanceof Error?p:new Error("Filing failed");return n.current&&o(d.message),t.onFilingError?.(d),null}finally{n.current&&s(false);}},[e.apiBaseUrl,e.stackId,t]),l=useCallback(()=>{c(null),o(null);},[]);return {filePaperwork:i,filing:r,result:u,error:a,reset:l}}function br(){let{config:e}=h(),[t,r]=useState([]),[s,u]=useState(true),[c,a]=useState(null),o=useRef(true),n=e.apiBaseUrl,i=useCallback(async()=>{try{u(!0),a(null);let l=await fetch(`${n}/api/keys/filings`,{credentials:"include"});if(!l.ok)throw new Error(await U(l,`Failed to fetch filings (${l.status})`));let m=await l.json(),p=Array.isArray(m)?m:m.filings??[];o.current&&r(p);}catch(l){o.current&&a(l instanceof Error?l.message:"Failed to fetch filings");}finally{o.current&&u(false);}},[n]);return useEffect(()=>(o.current=true,i(),()=>{o.current=false;}),[i]),{entries:t,loading:s,error:c,refresh:i}}var kt=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function Ve({amountSol:e,onSuccess:t,onError:r,disabled:s,className:u,style:c}){let{config:a}=h(),[o,n]=useState(false),[i,l]=useState(null),m=!!(a.merchantWallet&&kt.test(a.merchantWallet)),p=useCallback(async()=>{if(m)try{n(!0),l(null);let{Connection:d,PublicKey:g,Transaction:k,SystemProgram:I,LAMPORTS_PER_SOL:w}=await import('@solana/web3.js'),B=typeof window<"u"?window.solana:void 0;if(!B||typeof B!="object"||!B.isPhantom)throw new Error("Phantom wallet not found. Please install Phantom.");let j=B,P;try{P=new g(a.merchantWallet);}catch{throw new Error("Invalid merchant wallet address.")}let z=await j.connect(),E=new g(z.publicKey.toString()),_="https://api.mainnet-beta.solana.com",q=F(a.solanaRpcUrl,_),ne=q==="#"?_:q,ue=new d(ne),{blockhash:D}=await ue.getLatestBlockhash(),Q=BigInt(Math.floor(e*1e9)),me=a.protocolTreasuryWallet,pe=a.protocolFeeBps??500,fe=new k({recentBlockhash:D,feePayer:E});if(me&&kt.test(me)&&pe>0){let at=Q*BigInt(pe)/10000n,jt=Q-at,$t=new g(me);fe.add(I.transfer({fromPubkey:E,toPubkey:P,lamports:Number(jt)}),I.transfer({fromPubkey:E,toPubkey:$t,lamports:Number(at)}));}else fe.add(I.transfer({fromPubkey:E,toPubkey:P,lamports:Number(Q)}));let{signature:he}=await j.signAndSendTransaction(fe);t(he);}catch(d){let g=d instanceof Error?d:new Error("Payment failed");l(g.message),r?.(g);}finally{n(false);}},[e,a.merchantWallet,m,t,r]);return jsxs("div",{children:[jsx("button",{onClick:p,disabled:s||o||!m,"aria-label":`Pay ${e.toFixed(4)} SOL`,className:f("flex w-full items-center justify-center gap-2 rounded-2xl bg-purple-600 py-6 text-base font-semibold text-white transition-colors hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed",u),style:c,children:o?jsxs(Fragment,{children:[jsx(Loader2,{className:"h-4 w-4 animate-spin"}),"Processing..."]}):jsxs(Fragment,{children:["Pay ",e.toFixed(4)," SOL"]})}),i&&jsx("p",{className:"mt-2 text-center text-xs text-red-500",children:i})]})}function Ye({result:e,className:t,style:r}){let[s,u]=useState(false),c=useRef(null);useEffect(()=>()=>{c.current&&clearTimeout(c.current);},[]);let a=useCallback(()=>{e.key?.key&&(navigator.clipboard.writeText(e.key.key),u(true),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>u(false),2e3));},[e.key?.key]);return !e.success||!e.key?null:jsxs("div",{className:f("rounded-lg border border-green-500/20 bg-green-500/10 p-6 text-center",t),style:r,children:[jsx(CheckCircle,{className:"mx-auto mb-3 h-12 w-12 text-green-500"}),jsx("h3",{className:"mb-2 text-lg font-semibold text-foreground",children:"Key Generated!"}),jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Your node key has been successfully generated."}),jsxs("div",{className:"mx-auto flex max-w-md items-center gap-2 rounded-md border bg-background p-3",children:[jsx("code",{className:"flex-1 truncate text-xs text-foreground",children:e.key.key}),jsx("button",{onClick:a,"aria-label":"Copy key to clipboard",className:"shrink-0 rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:s?jsx(Check,{className:"h-4 w-4 text-green-500"}):jsx(Copy,{className:"h-4 w-4"})})]})]})}function te({className:e}){return jsx("div",{className:f("animate-pulse rounded-xl bg-muted",e)})}function ze(){return jsxs("div",{className:"space-y-6",children:[jsxs("div",{className:"px-6 py-10 flex flex-col items-center gap-3",children:[jsx(te,{className:"h-14 w-48"}),jsx(te,{className:"h-5 w-64"})]}),jsx(te,{className:"h-[72px] w-full rounded-2xl"}),jsx(te,{className:"h-[68px] w-full rounded-2xl"}),jsx(te,{className:"h-[60px] w-full rounded-2xl"})]})}function ae({count:e=3}){return jsx("div",{className:"space-y-3",children:Array.from({length:e}).map((t,r)=>jsxs("div",{className:"rounded-xl border p-4 space-y-3",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx(te,{className:"h-4 w-32"}),jsx(te,{className:"h-4 w-16"})]}),jsx(te,{className:"h-2 w-full rounded-full"}),jsxs("div",{className:"flex justify-between",children:[jsx(te,{className:"h-3 w-24"}),jsx(te,{className:"h-3 w-20"})]})]},r))})}function Ar({quantity:e,max:t,onChange:r}){return jsxs("div",{className:"flex items-center justify-between rounded-2xl bg-muted/20 px-6 py-6",children:[jsx("span",{className:"text-sm font-medium text-foreground",children:"Quantity"}),jsxs("div",{className:"flex items-center gap-0 rounded-xl bg-background",children:[jsx("button",{onClick:()=>r(Math.max(1,e-1)),disabled:e<=1,"aria-label":"Decrease quantity",className:"flex h-12 w-12 items-center justify-center rounded-l-xl text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-30",children:jsx(Minus,{className:"h-5 w-5"})}),jsx("span",{className:"flex h-12 w-14 items-center justify-center border-x text-xl font-bold text-foreground","aria-live":"polite",children:e}),jsx("button",{onClick:()=>r(Math.min(t,e+1)),disabled:e>=t,"aria-label":"Increase quantity",className:"flex h-12 w-12 items-center justify-center rounded-r-xl text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-30",children:jsx(Plus,{className:"h-5 w-5"})})]})]})}function wt({pricing:e,quantity:t}){let[r,s]=useState(false),u=e.priceUsd*t;return jsxs("div",{className:"rounded-2xl border bg-background",children:[jsxs("button",{onClick:()=>s(!r),"aria-expanded":r,className:"flex w-full items-center justify-between px-6 py-6 text-left",children:[jsxs("span",{className:"text-foreground",children:[jsxs("span",{className:"text-xl font-bold",children:["$",u.toFixed(2)]})," ",jsx("span",{className:"text-sm text-muted-foreground",children:"total fees included"})]}),r?jsx(ChevronUp,{className:"h-5 w-5 text-muted-foreground"}):jsx(ChevronDown,{className:"h-5 w-5 text-muted-foreground"})]}),r&&jsxs("div",{className:"border-t px-6 pb-8 pt-4 space-y-3 text-sm",children:[jsxs("div",{className:"flex justify-between",children:[jsxs("span",{className:"text-muted-foreground",children:["Node Key \xD7 ",t]}),jsxs("span",{className:"text-foreground",children:["$",(e.priceUsd*t).toFixed(2)]})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Keys sold"}),jsx("span",{className:"text-foreground",children:e.keysSold})]}),e.daysUntilHalving>0&&jsxs("div",{className:"flex justify-between text-muted-foreground",children:[jsx("span",{children:"Next refresh"}),jsxs("span",{children:[e.daysUntilHalving," day",e.daysUntilHalving!==1?"s":""]})]}),jsxs("div",{className:"flex justify-between border-t pt-3 font-semibold",children:[jsx("span",{className:"text-foreground",children:"Total"}),jsxs("span",{className:"text-foreground",children:["$",u.toFixed(2)]})]})]})]})}function qe({className:e,style:t}){let{config:r}=h(),{pricing:s,loading:u,error:c,refresh:a}=Ue(),{mint:o,minting:n,result:i,error:l}=Ae(),{createSession:m,loading:p,error:d}=Me(),[g,k]=useState(1),[I,w]=useState(r.paymentMethods?.includes("stripe")?"stripe":"solana"),[B,j]=useState(0),[P,z]=useState(false),E=Kr.useRef(g);E.current=g;let _=Math.max(1,r.maxQuantity||5),q=[...r.paymentMethods||["solana"]].sort((D,Q)=>D==="stripe"?-1:Q==="stripe"?1:0);if(useEffect(()=>{if(typeof window>"u")return;let Q=new URLSearchParams(window.location.search).get("session_id");if(!Q){try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}return}if(/^cs_(test|live)_/.test(Q)&&!P&&!i?.success){let me=false;try{me=sessionStorage.getItem("keyutils_stripe_pending")==="1";}catch{}if(!me)return;try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}z(true);let pe=new URL(window.location.href);pe.searchParams.delete("session_id"),window.history.replaceState({},"",pe.toString());let fe=E.current;try{let he=sessionStorage.getItem("keyutils_stripe_quantity");he&&(fe=parseInt(he,10)||1,sessionStorage.removeItem("keyutils_stripe_quantity"));}catch{}o("stripe",Q,fe);}},[P,i,o]),i?.success)return jsx("div",{className:f("flex flex-col items-center justify-center",e),style:t,children:jsx(Ye,{result:i})});if(P||n)return jsx("div",{className:f("flex flex-col",e),style:t,children:jsx(ze,{})});if(u)return jsx("div",{className:f("flex flex-col",e),style:t,children:jsx(ze,{})});if(c||!s)return jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-24",e),style:t,children:[jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load pricing"}),jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c||"Please check your connection and try again."})]}),jsx("button",{onClick:()=>a(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]});let ne=async D=>{j(2),await o(I,D,g);},ue=()=>{m(s.priceCents,g);};return jsx("div",{className:f("flex flex-col",e),style:t,children:jsxs("div",{className:"space-y-6",children:[B===0&&jsxs(Fragment,{children:[r.keyImage&&jsx("img",{src:F(r.keyImage),alt:"Node Key",className:r.keyImageClass||"w-1/2 mx-auto"}),jsxs("div",{className:"px-6 py-10 text-center",children:[jsxs("p",{className:"text-5xl font-bold tracking-tight text-foreground md:text-6xl",children:["$",s.priceUsd.toFixed(2)]}),jsxs("p",{className:"mt-2 text-base text-muted-foreground",children:["per key \xB7 ",s.tokenAllocationFormatted||T(s.tokenAllocation)," tokens included"]})]}),jsx(Ar,{quantity:g,max:_,onChange:k}),jsx(wt,{pricing:s,quantity:g}),jsx("button",{onClick:()=>j(1),className:"w-full rounded-2xl bg-foreground py-6 text-center text-base font-semibold text-background transition-colors hover:bg-foreground/90",children:"Continue to Payment"})]}),B===1&&jsxs(Fragment,{children:[q.length>1&&jsx("div",{role:"tablist",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:q.map(D=>jsxs("button",{role:"tab","aria-selected":I===D,onClick:()=>w(D),className:f("flex flex-1 items-center justify-center gap-2.5 rounded-xl py-4 text-sm font-medium transition-colors",I===D?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[D==="stripe"?jsx(CreditCard,{className:"h-5 w-5"}):jsx(Wallet,{className:"h-5 w-5"}),D==="stripe"?"Credit Card":"Crypto"]},D))}),jsx(wt,{pricing:s,quantity:g}),I==="stripe"?jsxs(Fragment,{children:[jsx("button",{onClick:ue,disabled:p,className:"flex w-full items-center justify-center gap-2 rounded-2xl bg-foreground py-6 text-base font-semibold text-background transition-colors hover:bg-foreground/90 disabled:opacity-50",children:p?jsxs(Fragment,{children:[jsx(Loader2,{className:"h-5 w-5 animate-spin"}),"Redirecting to Stripe..."]}):jsxs(Fragment,{children:[jsx(CreditCard,{className:"h-5 w-5"}),"Pay with Card"]})}),d&&jsx("p",{className:"text-center text-sm text-red-500",children:d})]}):I==="solana"?jsx(Ve,{amountSol:s.priceSol??0,onSuccess:ne}):null,l&&jsx("p",{className:"text-center text-sm text-red-500",children:l}),jsx("button",{type:"button",onClick:()=>j(0),className:"w-full rounded-2xl border border-border bg-transparent py-3 text-center text-sm font-medium text-foreground transition-colors hover:bg-muted/30",children:"Cancel"})]})]})})}var $r={ios:"iOS",android:"Android",windows:"Windows",mac:"macOS",linux:"Linux"},Dr=["mac","windows","linux","ios","android"],Wr="https://www.stacknet.org/download";function Ge({downloads:e,className:t,style:r}){let{config:s}=h(),u=useMemo(()=>dt(),[]),c=e||Dr.map(n=>({platform:n,label:$r[n],url:Wr,compatible:n===u})),a=c.find(n=>n.compatible)||c[0],o=c.filter(n=>n.platform!==a.platform);return jsxs("div",{className:f("space-y-8",t),style:r,children:[jsxs("div",{className:"flex flex-col items-center gap-6 pt-4 mt-4",children:[s.aispImage&&jsx("img",{src:F(s.aispImage),alt:"aiSP",className:"w-full sm:w-1/2 mx-auto px-4 sm:px-0"}),jsxs("div",{className:"text-center",children:[jsx("p",{className:"text-lg sm:text-2xl font-medium text-foreground",children:"Download the AI Service Provider App"}),jsx("p",{className:"mt-1 text-sm sm:text-base text-muted-foreground",children:"Load your keys and run your node."})]}),jsxs("a",{href:F(a.url),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-3 rounded-full px-10 py-4 text-lg font-semibold text-white transition-colors hover:opacity-90",style:{backgroundColor:"#0900f4"},children:[jsx(Download,{className:"h-5 w-5"}),"Get aiSP for ",a.label]})]}),jsxs("p",{className:"text-center text-sm text-muted-foreground",children:["aiSP is also available on"," ",o.map((n,i)=>jsxs(Kr.Fragment,{children:[i>0&&(i===o.length-1?" and ":", "),jsx("a",{href:F(n.url),target:"_blank",rel:"noopener noreferrer",className:"font-medium underline transition-colors hover:text-foreground",style:{color:"#066bff"},children:n.label})]},n.platform)),"."]}),jsxs("div",{className:"flex flex-col items-center gap-2 mt-12",children:[jsxs("p",{className:"text-center text-xs text-muted-foreground flex justify-center gap-0.5 flex-wrap",children:["Source code is available on",jsx("a",{href:"https://github.com/stack-net",target:"_blank",rel:"noopener noreferrer",className:"text-foreground underline hover:text-foreground/80 color-[#0900f4]",children:"Github"})]}),jsxs("p",{className:"text-center text-xs text-muted-foreground flex justify-center gap-0.5 flex-wrap",children:["By downloading, you agree to the",jsx("a",{href:F(s.termsUrl,"/terms"),target:"_blank",rel:"noopener noreferrer",className:"text-foreground underline hover:text-foreground/80",children:"Open Source Applications Terms"})]})]})]})}var Or={"bg-green-500":"bg-green-900/50","bg-yellow-500":"bg-yellow-900/50","bg-red-500":"bg-red-900/50"};function Z({current:e,max:t,className:r,style:s,showLabel:u=true,segments:c=40}){let a=lt(e,t),o=ct(a),n=Or[o]||"bg-muted",i=Math.round(a/100*c);return jsxs("div",{className:f("w-full",r),style:s,children:[u&&jsxs("div",{className:"mb-1 flex items-center justify-between text-xs text-muted-foreground",children:[jsxs("span",{children:[T(e)," / ",T(t)]}),jsxs("span",{children:[a,"%"]})]}),jsx("div",{className:"flex h-6 w-full items-stretch gap-1",children:Array.from({length:c}).map((l,m)=>jsx("div",{className:f("flex-1 rounded-[1px] transition-colors duration-300",m<i?o:n)},m))})]})}function ve({open:e,onClose:t,title:r,children:s}){let u=useRef(null),[c,a]=useState(false),[o,n]=useState(false),i=useCallback(l=>{l.key==="Escape"&&t();},[t]);return useEffect(()=>{if(e)a(true),document.addEventListener("keydown",i),document.body.style.overflow="hidden",requestAnimationFrame(()=>{requestAnimationFrame(()=>n(true));});else {n(false);let l=setTimeout(()=>{a(false),document.body.style.overflow="";},300);return document.removeEventListener("keydown",i),()=>clearTimeout(l)}return ()=>{document.removeEventListener("keydown",i);}},[e,i]),c?jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",children:[jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm transition-opacity duration-300",style:{opacity:o?1:0},onClick:t}),jsxs("div",{ref:u,className:f("relative z-10 w-full max-w-xl rounded-t-2xl bg-background shadow-2xl","max-h-[85vh] flex flex-col","transition-transform duration-300 ease-out"),style:{transform:o?"translateY(0)":"translateY(100%)"},children:[jsx("div",{className:"flex justify-center pt-3 pb-1",children:jsx("div",{className:"h-1 w-10 rounded-full bg-muted-foreground/30"})}),r&&jsxs("div",{className:"flex items-center justify-between px-5 pb-3 pt-1",children:[jsx("h3",{className:"text-lg font-semibold text-foreground",children:r}),jsx("button",{onClick:t,className:"rounded-full p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors","aria-label":"Close",children:jsx(X$1,{className:"h-5 w-5"})})]}),jsx("div",{className:"flex-1 overflow-y-auto px-5 pb-8",children:s})]})]}):null}var Ce=[" .-----."," / (_) \\"," / \\","( )"," \\ /"," \\_______/"," || |"," || |"," || /"," || /"," || \\"," || /"," || /"," \\// "],Qe=16,qr=Qe*.6,St=Qe*1;function Xe({className:e,style:t,color:r="currentColor",ariaLabel:s="Node key",keyImage:u,keyImageClass:c}){if(u)return jsx("img",{src:F(u),alt:s,className:f(c||"h-20 w-auto mx-auto",e),style:t});let a=Ce.reduce((p,d)=>Math.max(p,d.length),0),o=Ce.length,n=a*qr,l=o*St;return jsx("svg",{viewBox:`0 0 ${l} ${n}`,xmlns:"http://www.w3.org/2000/svg",className:f("block",e),style:t,role:"img","aria-label":s,preserveAspectRatio:"xMidYMid meet",children:jsx("g",{transform:`translate(0 ${n}) rotate(-90)`,children:Ce.map((p,d)=>jsx("text",{x:0,y:(d+.8)*St,fill:r,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:Qe,xmlSpace:"preserve",children:p},d))})})}function Xr({nodeKey:e,onSuccess:t}){let{transferKey:r,transferring:s,result:u,error:c}=ye(),[a,o]=useState(""),[n,i]=useState(false),l=a.trim()===e.userId,m=a.trim().length>0&&n&&!l&&!s,p=async()=>{if(!m)return;await r(e.id,a.trim())&&t();};return u?jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[jsx(CheckCircle,{className:"h-12 w-12 text-green-500"}),jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Transfer Complete"}),jsx("p",{className:"text-sm text-muted-foreground",children:"Key transferred successfully"})]}):jsxs("div",{className:"space-y-5",children:[jsxs("div",{children:[jsx("label",{className:"mb-1.5 block text-sm font-semibold text-foreground",children:"Recipient User ID"}),jsx("input",{type:"text",value:a,onChange:d=>{o(d.target.value),i(false);},placeholder:"Enter recipient's user ID or global ID",className:"w-full rounded-xl border border-border bg-background px-4 py-3 text-sm text-foreground placeholder:text-muted-foreground focus:border-foreground/30 focus:outline-none focus:ring-1 focus:ring-foreground/10"}),l&&jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),a.trim().length>0&&!l&&jsx("div",{className:"rounded-xl border border-amber-500/30 bg-amber-500/5 p-4",children:jsxs("div",{className:"flex items-start gap-3",children:[jsx(AlertTriangle,{className:"mt-0.5 h-5 w-5 shrink-0 text-amber-500"}),jsxs("div",{className:"space-y-3",children:[jsxs("div",{children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Confirm Transfer"}),jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Transferring key"," ",jsx("span",{className:"font-mono font-medium",children:e.keyIndex?`#${e.keyIndex}`:e.id.slice(0,12)})," ","(",T(e.tokenBalance)," tokens) to"," ",jsxs("span",{className:"font-mono font-medium",children:[a.trim().slice(0,20),a.trim().length>20?"...":""]})]})]}),jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsx("input",{type:"checkbox",checked:n,onChange:d=>i(d.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border"}),jsx("span",{className:"text-xs text-muted-foreground",children:"I confirm this transfer is permanent and cannot be undone."})]})]})]})}),c&&jsx("p",{className:"text-sm text-red-500",children:c}),jsx("button",{onClick:p,disabled:!m,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",m?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:s?jsxs(Fragment,{children:[jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Transferring..."]}):jsxs(Fragment,{children:[jsx(Send,{className:"h-4 w-4"}),"Transfer Key"]})})]})}function Zr({nodeKey:e,onSuccess:t}){let{config:r}=h(),{listKey:s,listing:u,result:c,error:a}=xe(),[o,n]=useState(""),[i,l]=useState(false),m=parseInt(o.replace(/[^0-9]/g,""),10)||0,d=m>0&&Number.isFinite(m)&&i&&!u,g=async()=>{if(!d)return;let k=m*100;await s(e.id,k)&&t();};return c?jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[jsx(CheckCircle,{className:"h-12 w-12 text-green-500"}),jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Key Listed!"}),jsx("p",{className:"text-sm text-muted-foreground",children:"Your key is now on the marketplace."}),jsxs("p",{className:"text-xs text-muted-foreground",children:["Listing ID: ",jsx("code",{children:c.listingId})]}),jsxs("a",{href:`https://market.stacknet.org/keys/${encodeURIComponent(c.keyId)}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 rounded-xl bg-foreground px-6 py-3 text-sm font-semibold text-background transition-colors hover:bg-foreground/90",children:[jsx(ExternalLink,{className:"h-4 w-4"}),"View Listing"]})]}):jsxs("div",{className:"space-y-5",children:[jsxs("div",{children:[jsx("label",{htmlFor:"listing-price",className:"mb-2 block text-sm font-semibold text-foreground",children:"Listing Price (USD)"}),jsxs("div",{className:"relative",children:[jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-2xl font-bold text-muted-foreground",children:"$"}),jsx("input",{id:"listing-price",type:"text",inputMode:"numeric",value:o,onChange:k=>{let I=k.target.value.replace(/[^0-9]/g,""),w=parseInt(I,10);n(isNaN(w)?"":w.toLocaleString("en-US"));},placeholder:"0",className:"w-full rounded-xl border bg-background py-6 pl-10 pr-4 text-3xl font-bold text-foreground placeholder:text-muted-foreground/30 focus:outline-none focus:ring-2 focus:ring-foreground/20"})]})]}),jsxs("div",{className:"flex items-start gap-3",children:[jsx("button",{type:"button",role:"checkbox","aria-checked":i,onClick:()=>l(!i),className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",i?"border-foreground bg-foreground":"border-muted-foreground/40"),children:i&&jsx(Check,{className:"h-3 w-3 text-background"})}),jsxs("span",{className:"text-xs text-muted-foreground leading-relaxed",children:["I agree to list this key on the Global Open AI Network marketplace. The key will be deactivated upon sale and transferred to the buyer. Listing fees may apply."," ",jsx("a",{href:F(r.termsUrl,"/terms"),className:"text-foreground underline",target:"_blank",rel:"noopener noreferrer",children:"Terms"})]})]}),a&&jsx("p",{className:"text-sm text-red-500",children:a}),jsxs("button",{onClick:g,disabled:!d,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",d?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:[jsx(ExternalLink,{className:"h-4 w-4"}),u?"Listing...":"List on Marketplace"]})]})}function es({nodeKey:e}){let[t,r]=useState(false);if(!e.paperWork)return jsxs("div",{className:"flex flex-col items-center gap-3 py-12",children:[jsx(FileText,{className:"h-10 w-10 text-muted-foreground"}),jsx("p",{className:"text-sm text-muted-foreground",children:"This key has no paperwork to file."})]});let s=()=>{navigator.clipboard.writeText(e.paperWork||""),r(true),setTimeout(()=>r(false),2e3);};return jsxs("div",{className:"space-y-5",children:[jsxs("div",{children:[jsx("label",{className:"mb-2 block text-sm font-semibold text-foreground",children:"Paperwork"}),jsxs("div",{className:"relative rounded-xl border bg-muted/30 p-4",children:[jsx("pre",{className:"whitespace-pre-wrap break-all text-sm text-foreground font-mono",children:e.paperWork}),jsx("button",{onClick:s,className:"absolute top-3 right-3 rounded-lg p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors","aria-label":"Copy paperwork",children:t?jsx(Check,{className:"h-4 w-4 text-green-500"}):jsx(Copy,{className:"h-4 w-4"})})]})]}),jsx("p",{className:"text-xs text-muted-foreground",children:"Filing paperwork submits the key's documentation on-chain for permanent record."}),jsxs("button",{disabled:true,className:"flex w-full items-center justify-center gap-2 rounded-xl bg-muted py-4 text-sm font-semibold text-muted-foreground cursor-not-allowed",children:[jsx(FileText,{className:"h-4 w-4"}),"File Paperwork (Coming Soon)"]})]})}function et({nodeKey:e,onBack:t,onKeysChanged:r,className:s,style:u}){let{config:c}=h(),{entries:a,loading:o}=ge(e.id),[n,i]=useState(null),[l,m]=useState(false),p=()=>{i(null),r?.();},d=()=>{e.key&&(navigator.clipboard.writeText(e.key),m(true),setTimeout(()=>m(false),2e3));},g=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsxs("div",{className:f("space-y-5",s),style:u,children:[jsxs("button",{onClick:t,className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors",children:[jsx(ArrowLeft,{className:"h-4 w-4"}),"View All"]}),jsx(Xe,{className:f("mx-auto text-foreground px-0 sm:px-0",c.keyImage?"w-2/3 h-auto":"h-20 w-auto"),keyImage:c.keyImage,keyImageClass:c.keyImageClass}),jsx("div",{className:"space-y-1",children:jsxs("div",{className:"flex items-center justify-between",children:[jsx("h2",{className:"text-2xl font-bold text-foreground",children:e.keyIndex?`Key #${e.keyIndex}`:e.label||e.id.slice(0,16)}),jsx("span",{className:f("text-sm font-medium capitalize",g),children:e.status})]})}),e.key&&jsxs("div",{className:"flex items-center gap-2",children:[jsx("code",{className:"flex-1 truncate px-3 py-2 text-lg text-muted-foreground",children:e.key}),jsx("button",{onClick:d,"aria-label":"Copy key",className:"shrink-0 rounded-lg p-2 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",children:l?jsx(Check,{className:"h-4 w-4 text-green-500"}):jsx(Copy,{className:"h-4 w-4"})})]}),jsx(Z,{current:e.tokenBalance,max:e.maxTokens,showLabel:true}),jsxs("div",{className:"rounded-xl bg-muted/30 p-5 space-y-2.5 text-sm",children:[(c.stackName||e.stackName)&&jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Stack"}),jsx("span",{className:"text-foreground",children:e.stackName||c.stackName})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Created"}),jsx("span",{className:"text-foreground",children:X(e.createdAt)})]}),e.expiresAt&&jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Expires"}),jsx("span",{className:"text-foreground",children:X(e.expiresAt)})]})]}),e.paperWork&&jsxs("div",{className:"rounded-xl border bg-muted/30 p-5",children:[jsx("h3",{className:"text-sm font-semibold text-foreground mb-2",children:"Paperwork"}),jsx("pre",{className:"whitespace-pre-wrap break-all text-xs text-muted-foreground font-mono",children:e.paperWork})]}),e.status==="active"&&jsxs("div",{className:"grid grid-cols-3 gap-3",children:[jsx("button",{onClick:()=>i("transfer"),className:"flex items-center justify-center rounded-xl border border-border p-4 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors",children:"Transfer"}),jsx("button",{onClick:()=>i("sell"),className:"flex items-center justify-center rounded-xl border border-border p-4 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors",children:"Sell"}),jsx("button",{onClick:()=>i("file"),className:f("flex items-center justify-center rounded-xl border border-border p-4 text-sm font-medium transition-colors",e.paperWork?"text-foreground hover:bg-muted/50":"text-muted-foreground cursor-not-allowed opacity-50"),disabled:!e.paperWork,children:"File"})]}),jsx(ve,{open:n==="transfer",onClose:()=>i(null),title:"Transfer Key",children:jsx(Xr,{nodeKey:e,onSuccess:p})}),jsx(ve,{open:n==="sell",onClose:()=>i(null),title:"Sell Key",children:jsx(Zr,{nodeKey:e,onSuccess:p})}),jsx(ve,{open:n==="file",onClose:()=>i(null),title:"File Paperwork",children:jsx(es,{nodeKey:e})})]})}function ts({nodeKey:e,onClick:t}){let r=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsx("button",{onClick:t,className:"flex w-full items-start gap-3 rounded-xl border border-border p-4 text-left transition-all hover:border-foreground/20 hover:bg-muted/30",children:jsxs("div",{className:"min-w-0 flex-1",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsx("span",{className:f("text-xs font-medium capitalize",r),children:e.status})]}),jsx(Z,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"}),e.paperWork&&jsx("span",{className:"mt-1.5 inline-block text-xs text-muted-foreground",children:"Has paperwork"})]})})}function tt({className:e,style:t}){let{keys:r,totalBalance:s,loading:u,error:c,refresh:a}=H(),[o,n]=useState(null),[i,l]=useState("active"),m=r.filter(g=>g.status===i),p=m.reduce((g,k)=>g+k.tokenBalance,0),d=r.find(g=>g.id===o);return d?jsx(et,{nodeKey:d,onBack:()=>n(null),onKeysChanged:()=>{n(null),a();},className:e,style:t}):u?jsxs("div",{className:f("space-y-4",e),style:t,children:[jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsx(ae,{count:3})]}):c?jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-16",e),style:t,children:[jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c})]}),jsx("button",{onClick:()=>a(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]}):r.length===0?jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 rounded-xl border border-dashed py-16",e),style:t,children:[jsx(KeyRound,{className:"h-10 w-10 text-muted-foreground"}),jsxs("div",{className:"text-center",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys yet"}),jsx("p",{className:"text-xs text-muted-foreground",children:"Get your first node key to start earning."})]})]}):jsxs("div",{className:f("space-y-4",e),style:t,children:[jsxs("div",{className:"flex items-center justify-between mt-3",children:[jsx("h3",{className:"text-2xl font-semibold text-foreground",children:"Your Keys"}),jsxs("span",{className:"hidden text-xs text-muted-foreground sm:inline",children:[m.length," key",m.length!==1?"s":""," \xB7 ",T(p)," tokens"]}),jsx("div",{className:"flex gap-1 rounded-lg bg-muted/50 p-1",children:["active","listed"].map(g=>jsx("button",{onClick:()=>l(g),className:f("rounded-md px-3 py-1 text-xs font-medium capitalize transition-all",i===g?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:g},g))})]}),m.length===0?jsxs("div",{className:"flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-12",children:[jsx(KeyRound,{className:"h-8 w-8 text-muted-foreground"}),jsxs("p",{className:"text-sm text-muted-foreground",children:["No ",i," keys."]})]}):jsx("div",{className:"space-y-2",children:m.map(g=>jsx(ts,{nodeKey:g,onClick:()=>n(g.id)},g.id))})]})}var ss=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function ns({active:e,onChange:t}){return jsx("div",{role:"tablist","aria-label":"Key actions",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:ss.map(({id:r,label:s})=>jsx("button",{role:"tab","aria-selected":e===r,"aria-controls":`panel-${r}`,id:`tab-${r}`,onClick:()=>t(r),className:f("flex flex-1 items-center justify-center gap-2.5 rounded-xl py-3.5 text-sm font-medium transition-all",e===r?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:jsx("span",{className:"inline",children:s})},r))})}function os({defaultTab:e="buy",className:t,style:r}){let[s,u]=useState(e);return jsxs("div",{className:f("flex flex-col",t),style:r,children:[jsx("div",{className:"sticky top-0 z-10 bg-background/80 px-5 pb-3 pt-2 sm:pt-5 backdrop-blur-sm sm:px-10 md:px-16 lg:px-20",children:jsx("div",{className:"mx-auto max-w-xl",children:jsx(ns,{active:s,onChange:u})})}),jsx("div",{className:"flex flex-1 flex-col px-5 pb-8 sm:px-10 md:px-16 md:pb-12 lg:px-20",children:jsx("div",{className:"mx-auto w-full max-w-xl flex-1",children:jsxs("div",{role:"tabpanel",id:`panel-${s}`,"aria-labelledby":`tab-${s}`,children:[s==="buy"&&jsx(qe,{className:"flex-1"}),s==="use"&&jsx(Ge,{className:"flex-1"}),s==="keys"&&jsx(tt,{className:"flex-1"})]})})})]})}function as({apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:s,merchantWallet:u,stripePublicKey:c,theme:a,maxQuantity:o,keyImage:n,keyImageClass:i,aispImage:l,termsUrl:m,onMintSuccess:p,onMintError:d,onPaymentStart:g,onPaymentComplete:k,onListingCreated:I,onTransferComplete:w,defaultTab:B,className:j,style:P}){return jsx(Ie,{config:{apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:s,merchantWallet:u,stripePublicKey:c,theme:a,maxQuantity:o,keyImage:n,keyImageClass:i,aispImage:l,termsUrl:m},callbacks:{onMintSuccess:p,onMintError:d,onPaymentStart:g,onPaymentComplete:k,onListingCreated:I,onTransferComplete:w},children:jsx(os,{defaultTab:B,className:j,style:P})})}function cs({nodeKey:e,selected:t,onSelect:r}){return jsxs("button",{onClick:r,className:f("flex w-full items-start gap-3 rounded-xl border p-4 text-left transition-all",t?"border-foreground/30 bg-foreground/5 ring-1 ring-foreground/10":"border-border hover:border-foreground/20"),children:[jsx("div",{className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors",t?"border-foreground bg-foreground":"border-muted-foreground/40"),children:t&&jsx(Check,{className:"h-3 w-3 text-background"})}),jsxs("div",{className:"min-w-0 flex-1",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsx("span",{className:f("text-xs font-medium capitalize",e.status==="active"?"text-green-500":"text-muted-foreground"),children:e.status})]}),jsx(Z,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function ds({className:e,style:t}){let{config:r}=h(),{keys:s,loading:u,error:c,refresh:a}=H(),{listKey:o,listing:n,result:i,error:l}=xe(),[m,p]=useState(null),[d,g]=useState(""),[k,I]=useState(false),w=s.find(_=>_.id===m),B=parseInt(d.replace(/[^0-9]/g,""),10)||0,j=B>0&&Number.isFinite(B),P=!!w&&j&&k&&!n,z=async()=>{if(!P||!w)return;let _=B*100;await o(w.id,_)&&a();};if(i)return jsxs("div",{className:f("flex flex-col items-center gap-4 rounded-xl bg-green-500/10 py-12",e),style:t,children:[jsx(CheckCircle,{className:"h-12 w-12 text-green-500"}),jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Key Listed!"}),jsx("p",{className:"text-sm text-muted-foreground",children:"Your key is now on the Global Open AI Network marketplace."}),jsxs("p",{className:"text-xs text-muted-foreground",children:["Listing ID: ",jsx("code",{children:i.listingId})]}),jsxs("a",{href:`https://market.stacknet.org/keys/${encodeURIComponent(i.keyId)}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 rounded-xl bg-foreground px-6 py-3 text-sm font-semibold text-background transition-colors hover:bg-foreground/90",children:[jsx(ExternalLink,{className:"h-4 w-4"}),"View Listing"]})]});if(u)return jsxs("div",{className:f("space-y-5 px-1",e),style:t,children:[jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsx(ae,{count:2})]});if(c)return jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-16",e),style:t,children:[jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c})]}),jsx("button",{onClick:()=>a(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]});let E=s.filter(_=>_.status==="active");return E.length===0?jsxs("div",{className:f("flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16",e),style:t,children:[jsx(AlertTriangle,{className:"h-8 w-8 text-muted-foreground"}),jsx("p",{className:"text-sm text-muted-foreground",children:"No active keys to sell."})]}):jsxs("div",{className:f("space-y-5",e),style:t,children:[jsxs("div",{children:[jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsx("div",{className:"space-y-2",children:E.map(_=>jsx(cs,{nodeKey:_,selected:m===_.id,onSelect:()=>p(_.id)},_.id))})]}),w&&jsxs("div",{className:"rounded-xl border bg-muted/30 p-5 space-y-2 text-sm",children:[w.keyIndex&&jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Key #"}),jsxs("span",{className:"text-foreground font-semibold",children:["#",w.keyIndex]})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Key ID"}),jsx("code",{className:"text-xs text-foreground",children:w.id})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Originating Stack"}),jsx("span",{className:"text-foreground",children:r.stackName||"Unknown"})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Tokens (remaining / total)"}),jsxs("span",{className:"text-foreground",children:[T(w.tokenBalance)," / ",T(w.maxTokens)]})]}),w.paperWork&&jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Paper earned"}),jsx("span",{className:"text-foreground",children:w.paperWork})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Created"}),jsx("span",{className:"text-foreground",children:X(w.createdAt)})]})]}),jsxs("div",{children:[jsx("label",{htmlFor:"listing-price",className:"mb-2 block text-sm sm:text-lg font-semibold text-foreground",children:"Listing Price (USD)"}),jsxs("div",{className:"relative",children:[jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-2xl font-bold text-muted-foreground",children:"$"}),jsx("input",{id:"listing-price",type:"text",inputMode:"numeric",value:d,onChange:_=>{let q=_.target.value.replace(/[^0-9]/g,""),ne=parseInt(q,10);g(isNaN(ne)?"":ne.toLocaleString("en-US"));},placeholder:"0",className:"w-full rounded-xl border bg-background py-6 pl-10 pr-4 text-3xl font-bold text-foreground placeholder:text-muted-foreground/30 focus:outline-none focus:ring-2 focus:ring-foreground/20"})]})]}),jsxs("div",{className:"flex items-start gap-3",children:[jsx("button",{type:"button",role:"checkbox","aria-checked":k,onClick:()=>I(!k),className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",k?"border-foreground bg-foreground":"border-muted-foreground/40"),children:k&&jsx(Check,{className:"h-3 w-3 text-background"})}),jsxs("span",{className:"text-xs text-muted-foreground leading-relaxed",children:["I agree to list this key on the Global Open AI Network marketplace. The key will be deactivated upon sale and transferred to the buyer. Listing fees may apply."," ",jsx("a",{href:F(r.termsUrl,"/terms"),className:"text-foreground underline",target:"_blank",rel:"noopener noreferrer",children:"Terms"})]})]}),l&&jsx("p",{className:"text-sm text-red-500",children:l}),jsxs("button",{onClick:z,disabled:!P,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",P?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:[jsx(ExternalLink,{className:"h-4 w-4"}),n?"Listing...":"List on Marketplace"]})]})}var st=20;function nt({nodeKey:e,className:t,style:r}){let[s,u]=useState(false),[c,a]=useState(false),o=useRef(null),{entries:n,loading:i}=ge(s?e.id:null);useEffect(()=>()=>{o.current&&clearTimeout(o.current);},[]);let l=useCallback(()=>{e.key&&(navigator.clipboard.writeText(e.key),a(true),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>a(false),2e3));},[e.key]),m=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500",p=n.slice(0,st);return jsxs("div",{className:f("rounded-lg border bg-background",t),style:r,children:[jsxs("div",{className:"p-4",children:[jsxs("div",{className:"mb-3 flex items-center justify-between",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("button",{onClick:()=>u(!s),"aria-expanded":s,"aria-label":s?"Collapse ledger":"Expand ledger",className:"text-muted-foreground hover:text-foreground",children:s?jsx(ChevronDown,{className:"h-4 w-4"}):jsx(ChevronRight,{className:"h-4 w-4"})}),jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]})]}),jsx("span",{className:f("text-xs font-medium capitalize",m),children:e.status})]}),e.key&&jsxs("div",{className:"mb-3 flex items-center gap-2",children:[jsx("code",{className:"flex-1 truncate rounded bg-muted px-2 py-1 text-xs text-muted-foreground",children:e.key}),jsx("button",{onClick:l,"aria-label":"Copy key to clipboard",className:"shrink-0 rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:c?jsx(Check,{className:"h-3.5 w-3.5 text-green-500"}):jsx(Copy,{className:"h-3.5 w-3.5"})})]}),jsx(Z,{current:e.tokenBalance,max:e.maxTokens}),jsxs("div",{className:"mt-2 flex items-center justify-between text-xs text-muted-foreground",children:[jsxs("span",{children:["Created ",X(e.createdAt)]}),e.expiresAt&&jsxs("span",{children:["Expires ",X(e.expiresAt)]})]})]}),s&&jsxs("div",{className:"border-t px-4 py-3",children:[jsx("h4",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Ledger"}),i?jsx("p",{className:"text-xs text-muted-foreground",children:"Loading..."}):p.length===0?jsx("p",{className:"text-xs text-muted-foreground",children:"No ledger entries."}):jsxs("div",{className:"space-y-1.5",children:[p.map(d=>jsxs("div",{className:"flex items-center justify-between text-xs",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsxs("span",{className:f("font-medium",d.type==="credit"||d.type==="reward"?"text-green-500":"text-red-500"),children:[d.type==="credit"||d.type==="reward"?"+":"-",T(Math.abs(d.amount))]}),jsx("span",{className:"text-muted-foreground",children:d.description})]}),jsx("span",{className:"text-muted-foreground",children:X(d.createdAt)})]},d.id)),n.length>st&&jsxs("p",{className:"pt-1 text-xs text-muted-foreground",children:["Showing ",st," of ",n.length," entries"]})]})]})]})}var ks=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function Se({baseHref:e}){return jsx("div",{className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5 mb-6",children:ks.map(({id:t,label:r})=>jsx("a",{href:`${e}?tab=${t}`,className:"flex flex-1 items-center justify-center gap-2.5 rounded-xl py-3.5 text-sm font-medium text-muted-foreground hover:text-foreground transition-all",children:r},t))})}function Ns({getKeyHref:e="/keys/get",showTabs:t=true,className:r,style:s}){let{keys:u,totalBalance:c,loading:a,error:o,refresh:n}=H();return a?jsxs("div",{className:f("space-y-4",r),style:s,children:[t&&e&&jsx(Se,{baseHref:e}),jsx(ae,{count:3})]}):o?jsxs("div",{className:f("space-y-4",r),style:s,children:[t&&e&&jsx(Se,{baseHref:e}),jsxs("div",{className:"flex flex-col items-center justify-center gap-4 py-12",children:[jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o})]}),jsx("button",{onClick:()=>n(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]})]}):u.length===0?jsxs("div",{className:f("space-y-4",r),style:s,children:[t&&e&&jsx(Se,{baseHref:e}),jsxs("div",{className:"flex flex-col items-center justify-center gap-4 rounded-lg border border-dashed py-12",children:[jsx(KeyRound,{className:"h-10 w-10 text-muted-foreground"}),jsxs("div",{className:"text-center",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys yet"}),jsx("p",{className:"text-xs text-muted-foreground",children:"Get your first node key to start earning."})]}),e&&jsx("a",{href:e,className:"rounded-lg bg-foreground px-4 py-2 text-sm font-medium text-background transition-colors hover:bg-foreground/90",children:"Get a Key"})]})]}):jsxs("div",{className:f("space-y-4",r),style:s,children:[t&&e&&jsx(Se,{baseHref:e}),jsxs("div",{className:"flex items-center justify-between",children:[jsxs("p",{className:"text-sm text-muted-foreground",children:[u.length," key",u.length!==1?"s":""," \xB7 Total balance: ",T(c)]}),e&&jsx("a",{href:e,className:"rounded-md bg-foreground px-3 py-1.5 text-xs font-medium text-background transition-colors hover:bg-foreground/90",children:"Get a Key"})]}),u.map(i=>jsx(nt,{nodeKey:i},i.id))]})}function Cs({nodeKey:e,selected:t,onSelect:r}){return jsxs("button",{onClick:r,className:f("flex w-full items-start gap-3 rounded-xl border p-4 text-left transition-all",t?"border-foreground/30 bg-foreground/5 ring-1 ring-foreground/10":"border-border hover:border-foreground/20"),children:[jsx("div",{className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors",t?"border-foreground bg-foreground":"border-muted-foreground/40"),children:t&&jsx(Check,{className:"h-3 w-3 text-background"})}),jsxs("div",{className:"min-w-0 flex-1",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsx("span",{className:"text-xs font-medium capitalize text-green-500",children:e.status})]}),jsx(Z,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function Ss({className:e,style:t}){let{keys:r,loading:s}=H(),{transferKey:u,transferring:c,result:a,error:o}=ye(),[n,i]=useState(null),[l,m]=useState(""),[p,d]=useState(false),g=r.filter(P=>P.status==="active"),k=g.find(P=>P.id===n),I=k&&l.trim()===k.userId,w=n&&l.trim().length>0&&p&&!I&&!c,B=async()=>{!n||!l.trim()||await u(n,l.trim());},j=()=>{i(null),m(""),d(false);};return a?jsxs("div",{className:f("flex flex-col items-center gap-4 py-8",e),style:t,children:[jsx(CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxs("div",{className:"text-center",children:[jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Transfer Complete"}),jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Key transferred successfully"})]}),jsxs("div",{className:"w-full max-w-sm space-y-2 rounded-xl border border-border bg-muted/30 p-4 text-sm",children:[jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Key"}),jsxs("span",{className:"font-mono text-foreground",children:[a.keyId.slice(0,20),"..."]})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Recipient"}),jsxs("span",{className:"font-mono text-foreground",children:[a.toUserId.slice(0,20),"..."]})]})]}),jsx("button",{onClick:j,className:"mt-2 rounded-lg border border-border px-4 py-2 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors",children:"Transfer Another"})]}):jsxs("div",{className:f("space-y-5",e),style:t,children:[jsxs("div",{children:[jsx("h3",{className:"mb-3 text-sm font-medium text-foreground",children:"Select Key to Transfer"}),s?jsx(ae,{count:2}):g.length===0?jsx("p",{className:"text-sm text-muted-foreground",children:"No active keys available for transfer."}):jsx("div",{className:"space-y-2",children:g.map(P=>jsx(Cs,{nodeKey:P,selected:n===P.id,onSelect:()=>i(P.id)},P.id))})]}),n&&jsxs("div",{children:[jsx("label",{className:"mb-1.5 block text-sm font-medium text-foreground",children:"Recipient User ID"}),jsx("input",{type:"text",value:l,onChange:P=>{m(P.target.value),d(false);},placeholder:"Enter recipient's user ID or global ID",className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:border-foreground/30 focus:outline-none focus:ring-1 focus:ring-foreground/10"}),I&&jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),k&&l.trim().length>0&&!I&&jsx("div",{className:"rounded-xl border border-amber-500/30 bg-amber-500/5 p-4",children:jsxs("div",{className:"flex items-start gap-3",children:[jsx(AlertTriangle,{className:"mt-0.5 h-5 w-5 shrink-0 text-amber-500"}),jsxs("div",{className:"space-y-3",children:[jsxs("div",{children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Confirm Transfer"}),jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["You are about to transfer key"," ",jsx("span",{className:"font-mono font-medium",children:k.keyIndex?`#${k.keyIndex}`:k.id.slice(0,12)})," ","(",T(k.tokenBalance)," tokens) to"," ",jsxs("span",{className:"font-mono font-medium",children:[l.trim().slice(0,20),"..."]})]})]}),jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsx("input",{type:"checkbox",checked:p,onChange:P=>d(P.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border"}),jsx("span",{className:"text-xs text-muted-foreground",children:"I confirm this transfer is permanent and cannot be undone."})]})]})]})}),o&&jsx("p",{className:"text-sm text-red-500",children:o}),jsx("button",{onClick:B,disabled:!w,className:f("flex w-full items-center justify-center gap-2 rounded-lg px-4 py-3 text-sm font-medium transition-all",w?"bg-foreground text-background hover:opacity-90":"bg-muted text-muted-foreground cursor-not-allowed"),children:c?jsxs(Fragment,{children:[jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Transferring..."]}):jsxs(Fragment,{children:[jsx(Send,{className:"h-4 w-4"}),"Transfer Key"]})})]})}function Ke(e,t=6,r=6){return !e||e.length<=t+r+1?e:`${e.slice(0,t)}\u2026${e.slice(-r)}`}function Ts({nodeKey:e,stackName:t}){let r=Math.max(0,e.maxTokens-e.tokenBalance);return jsxs("div",{className:"bg-muted/30 p-5 space-y-2 text-sm",children:[e.keyIndex!=null&&jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Key #"}),jsxs("span",{className:"text-foreground font-semibold",children:["#",e.keyIndex]})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Key ID"}),jsx("code",{className:"text-xs text-foreground",children:Ke(e.id,8,8)})]}),t&&jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Originating Stack"}),jsx("span",{className:"text-foreground",children:t})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Compute tokens used"}),jsxs("span",{className:"text-foreground",children:[T(r)," / ",T(e.maxTokens)]})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Created"}),jsx("span",{className:"text-foreground",children:X(e.createdAt)})]})]})}function Re(){return jsxs("div",{className:"bg-stacknet-blue text-white p-8 lg:w-2/5 flex flex-col justify-between min-h-[260px]",children:[jsxs("div",{className:"space-y-3",children:[jsx("p",{className:"text-sm font-mono opacity-80",children:"stacknet | filing"}),jsx("h2",{className:"text-2xl font-semibold leading-snug",children:"File paperwork to redeem Paper."}),jsx("p",{className:"text-sm opacity-80 leading-relaxed",children:"Filing submits your prepared paperwork on chain. Once validated, Paper is sent to your registered payment address."})]}),jsx("p",{className:"text-xs opacity-60 mt-8",children:"Powered by StackNet"})]})}function Us({keyId:e,paymentAddress:t,onComplete:r,onConfigurePayment:s,onBack:u,className:c,style:a}){let{config:o}=h(),{keys:n,loading:i,error:l,refresh:m}=H(),{filePaperwork:p,filing:d,result:g,error:k,reset:I}=De(),w=n.find(E=>E.id===e),B=!!w?.paperWork&&w.paperWork.length>0,j=!!t&&t.length>0,P=B&&j&&!d&&!g,z=async()=>{if(!P||!w)return;let E=await p(w.id);E&&(m(),r?.(E));};return g?jsxs("div",{className:f("flex flex-col lg:flex-row",c),style:a,children:[jsx(Re,{}),jsxs("div",{className:"flex-1 bg-background p-8 space-y-6",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx(CheckCircle2,{className:"h-7 w-7 text-green-500","aria-hidden":true}),jsx("h3",{className:"text-2xl font-semibold text-foreground",children:"Paperwork filed"})]}),jsx("p",{className:"text-sm text-muted-foreground",children:"Your filing has been submitted. Paper will be released to your payment address once the watcher network validates the proof."}),jsxs("div",{className:"bg-muted/30 p-5 space-y-3 text-sm",children:[jsxs("div",{className:"flex justify-between gap-4",children:[jsx("span",{className:"text-muted-foreground",children:"Status"}),jsx("span",{className:"text-foreground capitalize",children:g.status})]}),jsxs("div",{className:"flex justify-between gap-4",children:[jsx("span",{className:"text-muted-foreground",children:"Paper amount"}),jsxs("span",{className:"text-foreground tabular-nums",children:[(g.paperAmount/1e6).toLocaleString(void 0,{maximumFractionDigits:6})," Paper"]})]}),jsxs("div",{className:"flex justify-between gap-4",children:[jsx("span",{className:"text-muted-foreground",children:"File hash"}),jsx("code",{className:"text-xs text-foreground break-all",children:Ke(g.fileHash,10,10)})]}),g.txSignature&&jsxs("div",{className:"flex justify-between gap-4",children:[jsx("span",{className:"text-muted-foreground",children:"Tx"}),jsx("a",{href:`https://solscan.io/tx/${encodeURIComponent(g.txSignature)}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-foreground underline underline-offset-4",children:Ke(g.txSignature,8,8)})]}),jsxs("div",{className:"flex justify-between gap-4",children:[jsx("span",{className:"text-muted-foreground",children:"Beneficiary"}),jsx("code",{className:"text-xs text-foreground",children:Ke(g.beneficiary,6,6)})]})]}),u&&jsx("button",{type:"button",onClick:()=>{I(),u();},className:"w-full bg-foreground text-background py-4 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:"Back to dashboard"})]})]}):i?jsxs("div",{className:f("flex flex-col lg:flex-row",c),style:a,children:[jsx(Re,{}),jsxs("div",{className:"flex-1 bg-background p-8 space-y-4",children:[jsx("div",{className:"h-7 w-48 bg-muted animate-pulse"}),jsx("div",{className:"h-32 w-full bg-muted animate-pulse"}),jsx("div",{className:"h-12 w-full bg-muted animate-pulse"})]})]}):l||!w?jsxs("div",{className:f("flex flex-col lg:flex-row",c),style:a,children:[jsx(Re,{}),jsxs("div",{className:"flex-1 bg-background p-8 space-y-4",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx(AlertCircle,{className:"h-6 w-6 text-red-500","aria-hidden":true}),jsx("h3",{className:"text-xl font-semibold text-foreground",children:l?"Unable to load keys":"Key not found"})]}),jsx("p",{className:"text-sm text-muted-foreground",children:l||`No key with id ${e} on this account.`}),jsx("button",{type:"button",onClick:()=>m(),className:"bg-foreground text-background px-4 py-3 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:"Try again"})]})]}):jsxs("div",{className:f("flex flex-col lg:flex-row",c),style:a,children:[jsx(Re,{}),jsxs("div",{className:"flex-1 bg-background p-8 space-y-6",children:[jsxs("div",{children:[jsx("h2",{className:"text-2xl font-semibold text-foreground",children:"File paperwork"}),jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Review the key and beneficiary, then submit your filing."})]}),jsx(Ts,{nodeKey:w,stackName:o.stackName}),!B&&jsx("div",{className:"bg-muted/30 p-4 text-sm text-muted-foreground",children:"This key has no pending paperwork. Run your node to earn Paper, then return to file."}),jsxs("div",{className:"space-y-2",children:[jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Beneficiary (payment address)"}),j?jsx("div",{className:"bg-muted/30 p-4",children:jsx("code",{className:"text-xs text-foreground break-all",children:t})}):jsxs("div",{className:"bg-muted/30 p-4 space-y-3",children:[jsx("p",{className:"text-sm text-foreground",children:"You haven't set a payment address yet."}),s&&jsx("button",{type:"button",onClick:s,className:"bg-foreground text-background px-4 py-3 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:"Set payment address"})]})]}),jsxs("div",{className:"bg-muted/30 p-4 flex gap-3",children:[jsx(Info,{className:"h-5 w-5 shrink-0 text-foreground mt-0.5","aria-hidden":true}),jsxs("p",{className:"text-sm text-foreground leading-relaxed",children:[jsx("span",{className:"font-semibold",children:"Important."})," ","Filing is one-time per key. Paper will be sent to the address above and cannot be reversed. Double-check the address before submitting."]})]}),k&&jsx("p",{className:"text-sm text-red-500",children:k}),jsx("button",{type:"button",onClick:z,disabled:!P,className:f("w-full py-4 text-sm font-semibold transition-colors",P?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:d?"Filing\u2026":"File Paperwork"})]})]})}function Es(e){return typeof e.paperWork=="string"&&e.paperWork.length>0}function _s({count:e=3}){return jsx("div",{className:"space-y-2",children:Array.from({length:e}).map((t,r)=>jsxs("div",{className:"bg-muted/30 p-4 space-y-3",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("div",{className:"h-4 w-40 bg-muted animate-pulse"}),jsx("div",{className:"h-4 w-16 bg-muted animate-pulse"})]}),jsx("div",{className:"h-3 w-32 bg-muted animate-pulse"})]},r))})}function As({nodeKey:e,onSelect:t}){let r=Math.max(0,e.maxTokens-e.tokenBalance);return jsxs("button",{type:"button",onClick:t,className:"group flex w-full items-center gap-4 bg-muted/30 p-4 text-left transition-colors hover:bg-muted/50",children:[jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsxs("span",{className:"text-sm font-semibold text-foreground",children:[e.keyIndex!=null?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsx("span",{className:"text-xs text-muted-foreground",children:e.stackName||""})]}),jsxs("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[jsxs("span",{className:"tabular-nums",children:[T(r)," / ",T(e.maxTokens)," compute used"]}),jsx("span",{className:"text-foreground",children:"Eligible"})]})]}),jsx(ChevronRight,{className:"h-5 w-5 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5","aria-hidden":true})]})}function Fs({onSelect:e,className:t,style:r}){let{keys:s,loading:u,error:c,refresh:a}=H();if(u)return jsx("div",{className:f("space-y-3",t),style:r,children:jsx(_s,{count:3})});if(c)return jsx("div",{className:f("space-y-3",t),style:r,children:jsxs("div",{className:"bg-muted/30 p-5 text-center",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c}),jsx("button",{type:"button",onClick:()=>a(),className:"mt-3 bg-foreground text-background px-4 py-2 text-xs font-semibold hover:bg-foreground/90 transition-colors",children:"Try again"})]})});let o=s.filter(Es);return o.length===0?jsxs("div",{className:f("flex flex-col items-center justify-center gap-3 bg-muted/20 py-16",t),style:r,children:[jsx(FileText,{className:"h-10 w-10 text-muted-foreground","aria-hidden":true}),jsxs("div",{className:"text-center",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys with pending paperwork"}),jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Run a node to earn Paper, then return here to file."})]})]}):jsx("div",{className:f("space-y-2",t),style:r,children:o.map(n=>jsx(As,{nodeKey:n,onSelect:()=>e(n.id)},n.id))})}
2
- export{Ce as ASCII_KEY_ART,ve as BottomSheet,as as BuyKeyWidget,qe as BuyPanel,Xe as DefaultKeyArt,Fs as FilePaperworkList,Us as FilePaperworkView,Z as KeyBalanceBar,nt as KeyCard,et as KeyDetailView,Ns as KeyList,Ie as KeyUtilsProvider,tt as KeysPanel,Dt as MAX_ERROR_LEN,Ye as MintSuccess,ds as SellPanel,Ve as SolanaPayButton,Ss as TransferPanel,Ge as UsePanel,lt as calculateBalancePercentage,it as clampErrorMessage,f as cn,rr as createKeyClient,G as csrfHeaders,dt as detectPlatform,X as formatDate,T as formatTokens,ct as getBalanceColor,U as readErrorMessage,F as safeUrl,De as useFilePaperwork,br as useFilingHistory,ge as useKeyLedger,h as useKeyUtilsContext,H as useKeys,xe as useListKey,Ae as useMintKey,Ue as usePricing,ur as useSolanaPayment,Me as useStripeCheckout,ye as useTransferKey};
1
+ import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import Fn,{createContext,useContext,useMemo,useState,useRef,useEffect,useCallback}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {Loader2,CheckCircle,Check,Copy,CreditCard,Wallet,Download,X,AlertCircle,Info,ExternalLink,Eye,EyeOff,ArrowLeft,KeyRound,AlertTriangle,ChevronDown,ChevronRight,Send,FileText,RefreshCw,Minus,Plus,ChevronUp,ArrowRight,Circle,Lock,CheckCircle2}from'lucide-react';var Lt=false;function O(){if(typeof document>"u")return {};let e=document.cookie.match(/(?:^|;\s*)__csrf=([^;]*)/);if(!e)return Lt||(Lt=true,console.warn("[keyutils] __csrf cookie not found; mutations will be sent without a CSRF token")),{};let t=e[1];try{t=decodeURIComponent(t);}catch{}return {"x-csrf-token":t}}var Sr=500;function Bt(e,t){if(typeof e!="string"||e.length===0)return t;let r=e.replace(/[\u0000-\u001F\u007F]/g," ");return r.length>500?r.slice(0,500)+"\u2026":r}async function C(e,t){try{let r=await e.json();if(r&&typeof r=="object"&&"error"in r)return Bt(r.error,t)}catch{}return t}function D(e,t="#"){if(!e||typeof e!="string")return t;let r=e.trim();if(r===""||r==="#")return t;if(r.startsWith("/")||r.startsWith("./")||r.startsWith("../"))return r;try{let n=new URL(r);if(n.protocol==="http:"||n.protocol==="https:")return n.toString()}catch{}return t}var He={sent:"sent",routed:"routed",confirmed:"confirmed",finalized:"finalized",filed:"filed"},Se={sent:{pending:"sent",progressing:"sending",done:"sent"},routed:{pending:"routed",progressing:"routing",done:"routed"},confirmed:{pending:"confirmed",progressing:"confirming",done:"confirmed"},finalized:{pending:"finalized",progressing:"finalizing",done:"finalized"},filed:{pending:"filed",progressing:"filing",done:"filed"}},Rr=["sent","routed","confirmed","finalized","filed"];function Ve(e){let t=new Map;(e??[]).forEach(a=>t.set(a.id,a));let r=Rr.map(a=>{let s=t.get(a);return s?{...s,label:s.label||He[a]}:{id:a,label:He[a],status:"pending",timestampMs:null,detail:null}}),n=r.reduce((a,s,o)=>s.status==="done"||s.status==="failed"?o:a,-1);if(n>0)for(let a=0;a<n;a++)r[a].status!=="failed"&&(r[a]={...r[a],status:"done"});if(!r.some(a=>a.status==="failed")){let a=r.findIndex(s=>s.status!=="done");if(a>=0){let s=r[a];s.status!=="current"&&(r[a]={...s,status:"current"});}}return r}function Ft(e){return e.find(t=>t.status==="current")??null}function At(e){return e.length>0&&e.every(t=>t.status==="done")}function Mt(e){return e.some(t=>t.status==="failed")}function We(e,t){if(!t)return {text:"loading",playing:true,stepId:"sent"};if(Mt(e))return {text:"failed",playing:false,stepId:"filed"};if(At(e))return {text:Se.filed.done,playing:false,stepId:"filed"};let n=Ft(e)?.id??"sent";return {text:Se[n].progressing,playing:true,stepId:n}}function f(...e){return twMerge(clsx(e))}function F(e){return e==null?"0":e>=1e9?`${(e/1e9).toFixed(1)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function _t(e,t){return t<=0?0:Math.min(100,Math.round(e/t*100))}function Dt(e){return e>=70?"bg-green-500":e>=30?"bg-yellow-500":"bg-red-500"}function Ae(e,t={}){let r=t.withSymbol!==false,n=Math.max(0,Math.min(6,t.maxDecimals??2));if(e==null||e==="")return r?"$0.00":"0.00";let l;try{if(typeof e=="bigint")l=e;else if(typeof e=="number")l=BigInt(Math.trunc(e));else {let m=String(e).trim().replace(/^\+/,"");if(/^-?\d+$/.test(m))l=BigInt(m);else {let g=Number(m);if(!Number.isFinite(g))return r?"$0.00":"0.00";l=BigInt(Math.trunc(g));}}}catch{return r?"$0.00":"0.00"}let a=l<0n,s=a?-l:l,o=s/1000000n,d=(s%1000000n).toString().padStart(6,"0").slice(0,n),c=o.toLocaleString("en-US"),u=n>0?`.${d}`:"";return `${a?"-":""}${r?"$":""}${c}${u}`}function ee(e){if(e==null||e==="")return "";let t=typeof e=="string"&&/^\d+$/.test(e)?Number(e):e,r=new Date(t);return isNaN(r.getTime())?"":r.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function $t(){if(typeof navigator>"u")return "mac";let e=navigator.userAgent.toLowerCase();return /iphone|ipad|ipod/.test(e)?"ios":/android/.test(e)?"android":/win/.test(e)?"windows":/linux/.test(e)?"linux":"mac"}var jt=createContext(null);function h(){let e=useContext(jt);if(!e)throw new Error("useKeyUtilsContext must be used within a KeyUtilsProvider");return e}function ze({config:e,callbacks:t={},children:r}){typeof e.apiBaseUrl!="string"&&console.error("[KeyUtils] apiBaseUrl must be a string");let n=useMemo(()=>({config:e,callbacks:t}),[e,t]);return jsx(jt.Provider,{value:n,children:r})}function qe(){let{config:e}=h(),[t,r]=useState(null),[n,l]=useState(true),[a,s]=useState(null),o=useRef(true),i=useRef(e.apiBaseUrl);i.current=e.apiBaseUrl;let d=async()=>{try{o.current&&(l(!0),s(null));let c=await fetch(`${i.current}/api/keys/pricing`,{credentials:"include"});if(!c.ok)throw new Error(await C(c,`Pricing unavailable (${c.status})`));let u=await c.json();o.current&&r(u);}catch(c){o.current&&s(c instanceof Error?c.message:"Failed to fetch pricing");}finally{o.current&&l(false);}};return useEffect(()=>{o.current=true,d();let c=setInterval(d,6e4);return ()=>{o.current=false,clearInterval(c);}},[]),{pricing:t,loading:n,error:a,refresh:d}}function _r(e){return {id:e.id||"",keyIndex:e.keyIndex??e.key_index??null,key:e.id||e.key||e.keyPrefix||"",userId:e.userId||e.user_id||"",status:e.status||"active",tokenBalance:e.tokenBalance??e.currentTokenBalance??e.current_token_balance??0,maxTokens:e.maxTokens??e.initialTokenBalance??e.initial_token_balance??0,createdAt:String(e.createdAt??e.created_at??""),expiresAt:e.expiresAt,label:e.label||void 0,paperWork:e.paperWork||e.paper_work||void 0,stackId:e.stackId,stackName:e.stackName}}function te(){let{config:e}=h(),[t,r]=useState([]),[n,l]=useState(true),[a,s]=useState(null),o=useRef(true),i=e.apiBaseUrl,d=useCallback(async()=>{try{l(!0),s(null);let u=await fetch(`${i}/api/keys`,{credentials:"include"});if(!u.ok)throw new Error(await C(u,`Failed to fetch keys (${u.status})`));let p=await u.json(),m=Array.isArray(p)?p:p.keys??[];o.current&&r(m.map(_r));}catch(u){o.current&&s(u instanceof Error?u.message:"Failed to fetch keys");}finally{o.current&&l(false);}},[i]);useEffect(()=>(o.current=true,d(),()=>{o.current=false;}),[d]);let c=t.reduce((u,p)=>u+p.tokenBalance,0);return {keys:t,totalBalance:c,loading:n,error:a,refresh:d}}function Ge(e){let t=e.type||e.entry_type||"debit",r=e.amount??e.tokens??e.token_amount??0,n=e.description||e.memo||e.reason||Dr(t);return {id:e.id||"",keyId:e.keyId||e.key_id||"",type:t,amount:r,description:n,createdAt:String(e.createdAt??e.created_at??e.timestamp??""),metadata:e.metadata||void 0}}function Dr(e){switch(e){case "credit":return "Credit";case "debit":return "Usage";case "mint":return "Mint";case "reward":return "Reward";default:return ""}}function $r(e){return {id:e.id||"",keyIndex:e.keyIndex??e.key_index??null,key:e.id||e.key||e.keyPrefix||"",userId:e.userId||e.user_id||"",status:e.status||"active",tokenBalance:e.tokenBalance??e.currentTokenBalance??e.current_token_balance??0,maxTokens:e.maxTokens??e.initialTokenBalance??e.initial_token_balance??0,createdAt:String(e.createdAt??e.created_at??""),expiresAt:e.expiresAt,label:e.label||void 0,paperWork:e.paperWork||e.paper_work||void 0,stackId:e.stackId,stackName:e.stackName}}async function jr(e){if(!e)return {};let t=e();return t instanceof Promise?await t:t}function Or(e){if(!e)return false;let t=e.toUpperCase();return t==="POST"||t==="PUT"||t==="PATCH"||t==="DELETE"}async function be(e,t={}){let{getHeaders:r,...n}=t,l=await jr(r),a=Or(n.method)?O():{},s=await fetch(e,{...n,headers:{"Content-Type":"application/json",...a,...l,...n.headers},credentials:"include"});if(!s.ok)throw new Error(await C(s,`Request failed (${s.status})`));return s.json()}function Hr(e){let{apiBaseUrl:t,stackId:r,stackName:n,getHeaders:l}=e,a=`${t}/api/keys`;return {async getKeys(){let s=await be(a,{getHeaders:l});return (Array.isArray(s)?s:s.keys??[]).map($r)},async getLedger(s){let o=await be(`${a}/${encodeURIComponent(s)}/ledger`,{getHeaders:l});return (Array.isArray(o)?o:o.entries??[]).map(Ge)},async getPricing(){return be(`${a}/pricing`,{getHeaders:l})},async mint(s,o,i=1){try{let d=await be(a+"/mint",{method:"POST",body:JSON.stringify({paymentMethod:s,paymentRef:o,quantity:i,stackId:r}),getHeaders:l}),c=d.keys?.[0]||d;return {success:!0,key:{id:c.keyId||c.id||"",key:c.key||"",userId:c.userId||"",status:"active",tokenBalance:c.tokenBalance??c.currentTokenBalance??0,maxTokens:c.initialTokenBalance??c.tokenBalance??0,createdAt:String(c.createdAt||Date.now())},transactionId:o}}catch(d){return {success:false,error:d instanceof Error?d.message:"Key generation failed"}}},async listKey(s,o){return be(`${a}/${encodeURIComponent(s)}/list`,{method:"POST",body:JSON.stringify({askPriceCents:o,stackId:r,stackName:n}),getHeaders:l})},async delistKey(s){await be(`${a}/${encodeURIComponent(s)}/list`,{method:"DELETE",getHeaders:l});},async transferKey(s,o){return be(`${a}/${encodeURIComponent(s)}/transfer`,{method:"POST",body:JSON.stringify({recipientId:o}),getHeaders:l})},async createStripeSession(s,o,i){return be(`${a}/stripe-session`,{method:"POST",body:JSON.stringify({priceCents:s,quantity:o,stackId:r,referrerUrl:i}),getHeaders:l})}}}function Re(e){let{config:t}=h(),[r,n]=useState([]),[l,a]=useState(false),[s,o]=useState(null),i=useRef(true),d=t.apiBaseUrl,c=useCallback(async()=>{if(e)try{a(!0),o(null);let u=await fetch(`${d}/api/keys/${encodeURIComponent(e)}/ledger`,{credentials:"include"});if(!u.ok)throw new Error(await C(u,`Failed to fetch ledger (${u.status})`));let p=await u.json(),m=Array.isArray(p)?p:p.entries??[];i.current&&n(m.map(Ge));}catch(u){i.current&&o(u instanceof Error?u.message:"Failed to fetch ledger");}finally{i.current&&a(false);}},[d,e]);return useEffect(()=>(i.current=true,c(),()=>{i.current=false;}),[c]),{entries:r,loading:l,error:s,refresh:c}}function Ze(){let{config:e,callbacks:t}=h(),[r,n]=useState(false),[l,a]=useState(null),[s,o]=useState(null);return {mint:useCallback(async(d,c,u=1)=>{try{n(!0),o(null),t.onPaymentComplete?.(d,c);let p=await fetch(`${e.apiBaseUrl}/api/keys/mint`,{method:"POST",headers:{"Content-Type":"application/json",...O()},credentials:"include",body:JSON.stringify({paymentMethod:d,paymentRef:c,quantity:u,stackId:e.stackId})});if(!p.ok)throw new Error(await C(p,`Key generation failed (${p.status})`));let m=await p.json(),g=m.keys?.[0]||m,x={success:!0,key:{id:g.keyId||g.id||"",key:g.key||"",userId:g.userId||"",status:"active",tokenBalance:g.tokenBalance??g.currentTokenBalance??0,maxTokens:g.initialTokenBalance??g.tokenBalance??0,createdAt:String(g.createdAt||Date.now())},transactionId:c};return a(x),t.onMintSuccess?.(x),x}catch(p){let m=p instanceof Error?p:new Error("Key generation failed");return o(m.message),t.onMintError?.(m),{success:false,error:m.message}}finally{n(false);}},[e.apiBaseUrl,t]),minting:r,result:l,error:s}}function Te(){let{config:e,callbacks:t}=h(),[r,n]=useState(false),[l,a]=useState(null),[s,o]=useState(null),i=useRef(true),d=useCallback(async(u,p)=>{try{n(!0),o(null);let m=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/list`,{method:"POST",headers:{"Content-Type":"application/json",...O()},credentials:"include",body:JSON.stringify({askPriceCents:p,stackId:e.stackId,stackName:e.stackName})});if(!m.ok)throw new Error(await C(m,`Listing failed (${m.status})`));let g=await m.json();return i.current&&(a(g),t.onListingCreated?.(g)),g}catch(m){let g=m instanceof Error?m.message:"Listing failed";return i.current&&o(g),null}finally{i.current&&n(false);}},[e.apiBaseUrl,e.stackId,e.stackName,t]),c=useCallback(async u=>{try{n(!0),o(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/list`,{method:"DELETE",headers:{...O()},credentials:"include"});if(!p.ok)throw new Error(await C(p,`Delist failed (${p.status})`));return i.current&&a(null),!0}catch(p){let m=p instanceof Error?p.message:"Delist failed";return i.current&&o(m),false}finally{i.current&&n(false);}},[e.apiBaseUrl]);return {listKey:d,delistKey:c,listing:r,result:l,error:s}}function tt(){let{config:e}=h(),[t,r]=useState(false),[n,l]=useState(null),a=useRef(true);return {createSession:useCallback(async(o,i)=>{try{r(!0),l(null);let d=await fetch(`${e.apiBaseUrl}/api/keys/stripe-session`,{method:"POST",headers:{"Content-Type":"application/json",...O()},credentials:"include",body:JSON.stringify({priceCents:o,quantity:i,stackId:e.stackId,referrerUrl:window.location.href})});if(!d.ok)throw new Error(await C(d,`Checkout failed (${d.status})`));let{url:c}=await d.json();if(!c)throw new Error("No checkout URL returned");let u;try{u=new URL(c);}catch{throw new Error("Invalid checkout URL")}if(u.protocol!=="https:"||!/(^|\.)stripe\.com$/.test(u.hostname))throw new Error("Refusing to redirect to non-Stripe URL");try{sessionStorage.setItem("keyutils_stripe_pending","1"),sessionStorage.setItem("keyutils_stripe_quantity",String(i));}catch{}window.location.href=u.toString();}catch(d){if(a.current){let c=d instanceof Error?d.message:"Checkout failed";l(c),r(false);}}},[e.apiBaseUrl,e.stackId]),loading:t,error:n}}var zt=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function Xr(){let{config:e}=h(),[t,r]=useState(false),[n,l]=useState(null);return {pay:useCallback(async s=>{if(!e.merchantWallet||!zt.test(e.merchantWallet))throw new Error("Merchant wallet not configured");try{r(!0),l(null);let{Connection:o,PublicKey:i,Transaction:d,SystemProgram:c}=await import('@solana/web3.js'),u=typeof window<"u"?window.solana:void 0;if(!u||typeof u!="object"||!u.isPhantom)throw new Error("Phantom wallet not found. Please install Phantom.");let p=u,m=new i(e.merchantWallet),g=await p.connect(),x=new i(g.publicKey.toString()),b="https://api.mainnet-beta.solana.com",k=D(e.solanaRpcUrl,b),T=k==="#"?b:k,B=new o(T),{blockhash:N}=await B.getLatestBlockhash(),z=BigInt(Math.floor(s*1e9)),M=e.protocolTreasuryWallet,L=e.protocolFeeBps??500,V=new d({recentBlockhash:N,feePayer:x});if(M&&zt.test(M)&&L>0){let H=z*BigInt(L)/10000n,j=z-H,G=new i(M);V.add(c.transfer({fromPubkey:x,toPubkey:m,lamports:Number(j)}),c.transfer({fromPubkey:x,toPubkey:G,lamports:Number(H)}));}else V.add(c.transfer({fromPubkey:x,toPubkey:m,lamports:Number(z)}));let{signature:q}=await p.signAndSendTransaction(V);return q}catch(o){let i=o instanceof Error?o:new Error("SOL payment failed");throw l(i.message),i}finally{r(false);}},[e.merchantWallet,e.protocolTreasuryWallet,e.protocolFeeBps,e.solanaRpcUrl]),processing:t,error:n}}function Ie(){let{config:e,callbacks:t}=h(),[r,n]=useState(false),[l,a]=useState(null),[s,o]=useState(null),i=useRef(true);return {transferKey:useCallback(async(c,u)=>{try{n(!0),o(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(c)}/transfer`,{method:"POST",headers:{"Content-Type":"application/json",...O()},credentials:"include",body:JSON.stringify({recipientId:u})});if(!p.ok)throw new Error(await C(p,`Transfer failed (${p.status})`));let m=await p.json();return i.current&&(a(m),t.onTransferComplete?.(m)),m}catch(p){let m=p instanceof Error?p.message:"Transfer failed";return i.current&&o(m),null}finally{i.current&&n(false);}},[e.apiBaseUrl,t]),transferring:r,result:l,error:s}}function st(){let{config:e,callbacks:t}=h(),[r,n]=useState(false),[l,a]=useState(null),[s,o]=useState(null),i=useRef(true);useEffect(()=>(i.current=true,()=>{i.current=false;}),[]);let d=useCallback(async(u,p)=>{try{n(!0),o(null);let m={stackId:e.stackId};p&&(m.payoutMethod=p);let g=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/file`,{method:"POST",headers:{"Content-Type":"application/json",...O()},credentials:"include",body:JSON.stringify(m)});if(!g.ok)throw new Error(await C(g,`Filing failed (${g.status})`));let x=await g.json();return i.current&&(a(x),t.onFilingComplete?.(x)),x}catch(m){let g=m instanceof Error?m:new Error("Filing failed");return i.current&&o(g.message),t.onFilingError?.(g),null}finally{i.current&&n(false);}},[e.apiBaseUrl,e.stackId,t]),c=useCallback(()=>{a(null),o(null);},[]);return {filePaperwork:d,filing:r,result:l,error:s,reset:c}}function an(){let{config:e}=h(),[t,r]=useState([]),[n,l]=useState(true),[a,s]=useState(null),o=useRef(true),i=e.apiBaseUrl,d=useCallback(async()=>{try{l(!0),s(null);let c=await fetch(`${i}/api/keys/filings`,{credentials:"include"});if(!c.ok)throw new Error(await C(c,`Failed to fetch filings (${c.status})`));let u=await c.json(),p=Array.isArray(u)?u:u.filings??[];o.current&&r(p);}catch(c){o.current&&s(c instanceof Error?c.message:"Failed to fetch filings");}finally{o.current&&l(false);}},[i]);return useEffect(()=>(o.current=true,d(),()=>{o.current=false;}),[d]),{entries:t,loading:n,error:a,refresh:d}}function it(e){let{config:t}=h(),r=e??t.stackId,n=t.apiBaseUrl,[l,a]=useState(null),[s,o]=useState(!!r),[i,d]=useState(null),c=useRef(true),u=useCallback(async()=>{if(!r){a(null),o(false);return}try{o(!0),d(null);let p=await fetch(`${n}/api/stacks/${encodeURIComponent(r)}/payout-capabilities`,{credentials:"include"});if(!p.ok)throw new Error(await C(p,`Failed to load payout capabilities (${p.status})`));let m=await p.json();c.current&&a(m);}catch(p){c.current&&d(p instanceof Error?p.message:"Failed to load payout capabilities");}finally{c.current&&o(false);}},[n,r]);return useEffect(()=>(c.current=true,u(),()=>{c.current=false;}),[u]),{caps:l,loading:s,error:i,refresh:u}}var pn=5e3;function gn(e){return e==="paid"||e==="failed"}function ct(e){let{config:t}=h(),r=t.apiBaseUrl,[n,l]=useState(null),[a,s]=useState(!!e),[o,i]=useState(null),d=useRef(true),c=useCallback(async()=>{if(!e){l(null),s(false);return}try{i(null);let u=await fetch(`${r}/api/keys/filings/${encodeURIComponent(e)}`,{credentials:"include"});if(!u.ok)throw new Error(await C(u,`Failed to load filing (${u.status})`));let p=await u.json();d.current&&l(p);}catch(u){d.current&&i(u instanceof Error?u.message:"Failed to load filing");}finally{d.current&&s(false);}},[r,e]);return useEffect(()=>{if(d.current=true,!e)return l(null),s(false),()=>{d.current=false;};s(true),c();let u=setInterval(()=>{d.current&&(n&&gn(n.status)||c());},pn);return ()=>{d.current=false,clearInterval(u);}},[e,c,n]),{detail:n,loading:a,error:o,refresh:c}}function Ue(e){let{config:t}=h(),r=e??t.stackId??"",n=t.apiBaseUrl,[l,a]=useState(null),[s,o]=useState(true),[i,d]=useState(null),[c,u]=useState(false),p=useRef(true),m=useCallback(async()=>{try{o(!0),d(null);let x=r?`${n}/api/payout?stackId=${encodeURIComponent(r)}`:`${n}/api/payout`,b=await fetch(x,{credentials:"include"});if(!b.ok)throw new Error(await C(b,`Failed to load payout account (${b.status})`));let k=await b.json();p.current&&a(k);}catch(x){p.current&&d(x instanceof Error?x.message:"Failed to load payout account");}finally{p.current&&o(false);}},[n,r]);useEffect(()=>(p.current=true,m(),()=>{p.current=false;}),[m]);let g=useCallback(async x=>{try{u(!0),d(null);let b=x?`${n}/api/payout?stackId=${encodeURIComponent(x)}`:`${n}/api/payout`,k=await fetch(b,{method:"DELETE",headers:{...O()},credentials:"include"});if(!k.ok&&k.status!==204)throw new Error(await C(k,`Disconnect failed (${k.status})`));return await m(),!0}catch(b){return p.current&&d(b instanceof Error?b.message:"Disconnect failed"),false}finally{p.current&&u(false);}},[n,m]);return {account:l,loading:s,error:i,refresh:m,disconnect:g,disconnecting:c}}function vn(){let{config:e}=h(),t=e.apiBaseUrl,[r,n]=useState([]),[l,a]=useState(true),[s,o]=useState(null),i=useRef(true),d=useCallback(async()=>{try{a(!0),o(null);let c=await fetch(`${t}/api/payout/stripe-stacks`,{credentials:"include"});if(!c.ok)throw new Error(await C(c,`Failed to load stripe stacks (${c.status})`));let u=await c.json();i.current&&n(u.stacks??[]);}catch(c){i.current&&o(c instanceof Error?c.message:"Failed to load stripe stacks");}finally{i.current&&a(false);}},[t]);return useEffect(()=>(i.current=true,d(),()=>{i.current=false;}),[d]),{stacks:r,loading:l,error:s,refresh:d}}function ut(e){let{config:t}=h(),r=e??t.stackId,[n,l]=useState(false),[a,s]=useState(null);return {startStripeConnect:useCallback(async()=>{try{l(!0),s(null);let i=await fetch(`${t.apiBaseUrl}/api/payout/stripe/start`,{method:"POST",headers:{"Content-Type":"application/json",...O()},credentials:"include",body:JSON.stringify({stackId:r})});if(!i.ok)throw new Error(await C(i,`Stripe Connect start failed (${i.status})`));let d=await i.json();if(typeof window<"u"&&d.onboardingUrl){let c;try{c=new URL(d.onboardingUrl);}catch{throw new Error("Invalid onboarding URL")}if(c.protocol!=="https:"||!/(^|\.)stripe\.com$/.test(c.hostname))throw new Error("Refusing to redirect to non-Stripe URL");window.location.href=c.toString();return}}catch(i){s(i instanceof Error?i.message:"Stripe Connect start failed");}finally{l(false);}},[t.apiBaseUrl,r]),starting:n,error:a}}function Pn(){if(typeof window>"u")return null;let e=window,t=e.solana,r=e.phantom?.solana;return ((t&&t.isPhantom?t:null)||(r&&r.isPhantom?r:null))??null}function Cn(e){let t="";for(let r=0;r<e.length;r+=1)t+=String.fromCharCode(e[r]);return typeof btoa=="function"?btoa(t):Buffer.from(e).toString("base64")}function mt(){let{config:e}=h(),[t,r]=useState(false),[n,l]=useState(null);return {connectAndVerify:useCallback(async()=>{try{r(!0),l(null);let s=Pn();if(!s)throw new Error("Phantom wallet not found. Install Phantom to continue.");let i=(await s.connect()).publicKey.toString(),d=await fetch(`${e.apiBaseUrl}/api/payout/crypto/nonce`,{method:"POST",headers:{"Content-Type":"application/json",...O()},credentials:"include",body:JSON.stringify({address:i})});if(!d.ok)throw new Error(await C(d,`Nonce request failed (${d.status})`));let{nonce:c,message:u}=await d.json(),p=new TextEncoder().encode(u),m=await s.signMessage(p,"utf8"),g=Cn(m.signature),x=await fetch(`${e.apiBaseUrl}/api/payout/crypto/verify`,{method:"POST",headers:{"Content-Type":"application/json",...O()},credentials:"include",body:JSON.stringify({address:i,nonce:c,signature:g})});if(!x.ok)throw new Error(await C(x,`Verification failed (${x.status})`));return {address:i}}catch(s){let o=s instanceof Error?s:new Error("Wallet verification failed");return l(o.message),null}finally{r(false);}},[e.apiBaseUrl]),connecting:t,error:n}}var Xt=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function gt({amountSol:e,onSuccess:t,onError:r,disabled:n,className:l,style:a}){let{config:s}=h(),[o,i]=useState(false),[d,c]=useState(null),u=!!(s.merchantWallet&&Xt.test(s.merchantWallet)),p=useCallback(async()=>{if(u)try{i(!0),c(null);let{Connection:m,PublicKey:g,Transaction:x,SystemProgram:b,LAMPORTS_PER_SOL:k}=await import('@solana/web3.js'),T=typeof window<"u"?window.solana:void 0;if(!T||typeof T!="object"||!T.isPhantom)throw new Error("Phantom wallet not found. Please install Phantom.");let B=T,N;try{N=new g(s.merchantWallet);}catch{throw new Error("Invalid merchant wallet address.")}let z=await B.connect(),M=new g(z.publicKey.toString()),L="https://api.mainnet-beta.solana.com",V=D(s.solanaRpcUrl,L),q=V==="#"?L:V,H=new m(q),{blockhash:j}=await H.getLatestBlockhash(),G=BigInt(Math.floor(e*1e9)),me=s.protocolTreasuryWallet,fe=s.protocolFeeBps??500,ie=new x({recentBlockhash:j,feePayer:M});if(me&&Xt.test(me)&&fe>0){let le=G*BigInt(fe)/10000n,Pr=G-le,Cr=new g(me);ie.add(b.transfer({fromPubkey:M,toPubkey:N,lamports:Number(Pr)}),b.transfer({fromPubkey:M,toPubkey:Cr,lamports:Number(le)}));}else ie.add(b.transfer({fromPubkey:M,toPubkey:N,lamports:Number(G)}));let{signature:ye}=await B.signAndSendTransaction(ie);t(ye);}catch(m){let g=m instanceof Error?m:new Error("Payment failed");c(g.message),r?.(g);}finally{i(false);}},[e,s.merchantWallet,u,t,r]);return jsxs("div",{children:[jsx("button",{onClick:p,disabled:n||o||!u,"aria-label":`Pay ${e.toFixed(4)} SOL`,className:f("flex w-full items-center justify-center gap-2 rounded-2xl bg-purple-600 py-6 text-base font-semibold text-white transition-colors hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed",l),style:a,children:o?jsxs(Fragment,{children:[jsx(Loader2,{className:"h-4 w-4 animate-spin"}),"Processing..."]}):jsxs(Fragment,{children:["Pay ",e.toFixed(4)," SOL"]})}),d&&jsx("p",{className:"mt-2 text-center text-xs text-red-500",children:d})]})}function xt({result:e,className:t,style:r}){let[n,l]=useState(false),a=useRef(null);useEffect(()=>()=>{a.current&&clearTimeout(a.current);},[]);let s=useCallback(()=>{e.key?.key&&(navigator.clipboard.writeText(e.key.key),l(true),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>l(false),2e3));},[e.key?.key]);return !e.success||!e.key?null:jsxs("div",{className:f("rounded-lg border border-green-500/20 bg-green-500/10 p-6 text-center",t),style:r,children:[jsx(CheckCircle,{className:"mx-auto mb-3 h-12 w-12 text-green-500"}),jsx("h3",{className:"mb-2 text-lg font-semibold text-foreground",children:"Key Generated!"}),jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Your node key has been successfully generated."}),jsxs("div",{className:"mx-auto flex max-w-md items-center gap-2 rounded-md border bg-background p-3",children:[jsx("code",{className:"flex-1 truncate text-xs text-foreground",children:e.key.key}),jsx("button",{onClick:s,"aria-label":"Copy key to clipboard",className:"shrink-0 rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:n?jsx(Check,{className:"h-4 w-4 text-green-500"}):jsx(Copy,{className:"h-4 w-4"})})]})]})}function ce({className:e}){return jsx("div",{className:f("animate-pulse rounded-xl bg-muted",e)})}function yt(){return jsxs("div",{className:"space-y-6",children:[jsxs("div",{className:"px-6 py-10 flex flex-col items-center gap-3",children:[jsx(ce,{className:"h-14 w-48"}),jsx(ce,{className:"h-5 w-64"})]}),jsx(ce,{className:"h-[72px] w-full rounded-2xl"}),jsx(ce,{className:"h-[68px] w-full rounded-2xl"}),jsx(ce,{className:"h-[60px] w-full rounded-2xl"})]})}function he({count:e=3}){return jsx("div",{className:"space-y-3",children:Array.from({length:e}).map((t,r)=>jsxs("div",{className:"rounded-xl border p-4 space-y-3",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx(ce,{className:"h-4 w-32"}),jsx(ce,{className:"h-4 w-16"})]}),jsx(ce,{className:"h-2 w-full rounded-full"}),jsxs("div",{className:"flex justify-between",children:[jsx(ce,{className:"h-3 w-24"}),jsx(ce,{className:"h-3 w-20"})]})]},r))})}function Hn({quantity:e,max:t,onChange:r}){return jsxs("div",{className:"flex items-center justify-between rounded-2xl bg-muted/20 px-6 py-6",children:[jsx("span",{className:"text-sm font-medium text-foreground",children:"Quantity"}),jsxs("div",{className:"flex items-center gap-0 rounded-xl bg-background",children:[jsx("button",{onClick:()=>r(Math.max(1,e-1)),disabled:e<=1,"aria-label":"Decrease quantity",className:"flex h-12 w-12 items-center justify-center rounded-l-xl text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-30",children:jsx(Minus,{className:"h-5 w-5"})}),jsx("span",{className:"flex h-12 w-14 items-center justify-center border-x text-xl font-bold text-foreground","aria-live":"polite",children:e}),jsx("button",{onClick:()=>r(Math.min(t,e+1)),disabled:e>=t,"aria-label":"Increase quantity",className:"flex h-12 w-12 items-center justify-center rounded-r-xl text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-30",children:jsx(Plus,{className:"h-5 w-5"})})]})]})}function rr({pricing:e,quantity:t}){let[r,n]=useState(false),l=e.priceUsd*t;return jsxs("div",{className:"rounded-2xl border bg-background",children:[jsxs("button",{onClick:()=>n(!r),"aria-expanded":r,className:"flex w-full items-center justify-between px-6 py-6 text-left",children:[jsxs("span",{className:"text-foreground",children:[jsxs("span",{className:"text-xl font-bold",children:["$",l.toFixed(2)]})," ",jsx("span",{className:"text-sm text-muted-foreground",children:"total fees included"})]}),r?jsx(ChevronUp,{className:"h-5 w-5 text-muted-foreground"}):jsx(ChevronDown,{className:"h-5 w-5 text-muted-foreground"})]}),r&&jsxs("div",{className:"border-t px-6 pb-8 pt-4 space-y-3 text-sm",children:[jsxs("div",{className:"flex justify-between",children:[jsxs("span",{className:"text-muted-foreground",children:["Node Key \xD7 ",t]}),jsxs("span",{className:"text-foreground",children:["$",(e.priceUsd*t).toFixed(2)]})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Keys sold"}),jsx("span",{className:"text-foreground",children:e.keysSold})]}),e.daysUntilHalving>0&&jsxs("div",{className:"flex justify-between text-muted-foreground",children:[jsx("span",{children:"Next refresh"}),jsxs("span",{children:[e.daysUntilHalving," day",e.daysUntilHalving!==1?"s":""]})]}),jsxs("div",{className:"flex justify-between border-t pt-3 font-semibold",children:[jsx("span",{className:"text-foreground",children:"Total"}),jsxs("span",{className:"text-foreground",children:["$",l.toFixed(2)]})]})]})]})}function bt({className:e,style:t}){let{config:r}=h(),{pricing:n,loading:l,error:a,refresh:s}=qe(),{mint:o,minting:i,result:d,error:c}=Ze(),{createSession:u,loading:p,error:m}=tt(),[g,x]=useState(1),[b,k]=useState(r.paymentMethods?.includes("stripe")?"stripe":"solana"),[T,B]=useState(0),[N,z]=useState(false),M=Fn.useRef(g);M.current=g;let L=Math.max(1,r.maxQuantity||5),V=[...r.paymentMethods||["solana"]].sort((j,G)=>j==="stripe"?-1:G==="stripe"?1:0);if(useEffect(()=>{if(typeof window>"u")return;let G=new URLSearchParams(window.location.search).get("session_id");if(!G){try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}return}if(/^cs_(test|live)_/.test(G)&&!N&&!d?.success){let me=false;try{me=sessionStorage.getItem("keyutils_stripe_pending")==="1";}catch{}if(!me)return;try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}z(true);let fe=new URL(window.location.href);fe.searchParams.delete("session_id"),window.history.replaceState({},"",fe.toString());let ie=M.current;try{let ye=sessionStorage.getItem("keyutils_stripe_quantity");ye&&(ie=parseInt(ye,10)||1,sessionStorage.removeItem("keyutils_stripe_quantity"));}catch{}o("stripe",G,ie);}},[N,d,o]),d?.success)return jsx("div",{className:f("flex flex-col items-center justify-center",e),style:t,children:jsx(xt,{result:d})});if(N||i)return jsx("div",{className:f("flex flex-col",e),style:t,children:jsx(yt,{})});if(l)return jsx("div",{className:f("flex flex-col",e),style:t,children:jsx(yt,{})});if(a||!n)return jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-24",e),style:t,children:[jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load pricing"}),jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a||"Please check your connection and try again."})]}),jsx("button",{onClick:()=>s(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]});let q=async j=>{B(2),await o(b,j,g);},H=()=>{u(n.priceCents,g);};return jsx("div",{className:f("flex flex-col",e),style:t,children:jsxs("div",{className:"space-y-6",children:[T===0&&jsxs(Fragment,{children:[r.keyImage&&jsx("img",{src:D(r.keyImage),alt:"Node Key",className:r.keyImageClass||"w-1/2 mx-auto"}),jsxs("div",{className:"px-6 py-10 text-center",children:[jsxs("p",{className:"text-5xl font-bold tracking-tight text-foreground md:text-6xl",children:["$",n.priceUsd.toFixed(2)]}),jsxs("p",{className:"mt-2 text-base text-muted-foreground",children:["per key \xB7 ",n.tokenAllocationFormatted||F(n.tokenAllocation)," tokens included"]})]}),jsx(Hn,{quantity:g,max:L,onChange:x}),jsx(rr,{pricing:n,quantity:g}),jsx("button",{onClick:()=>B(1),className:"w-full rounded-2xl bg-foreground py-6 text-center text-base font-semibold text-background transition-colors hover:bg-foreground/90",children:"Continue to Payment"})]}),T===1&&jsxs(Fragment,{children:[V.length>1&&jsx("div",{role:"tablist",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:V.map(j=>jsxs("button",{role:"tab","aria-selected":b===j,onClick:()=>k(j),className:f("flex flex-1 items-center justify-center gap-2.5 rounded-xl py-4 text-sm font-medium transition-colors",b===j?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[j==="stripe"?jsx(CreditCard,{className:"h-5 w-5"}):jsx(Wallet,{className:"h-5 w-5"}),j==="stripe"?"Credit Card":"Crypto"]},j))}),jsx(rr,{pricing:n,quantity:g}),b==="stripe"?jsxs(Fragment,{children:[jsx("button",{onClick:H,disabled:p,className:"flex w-full items-center justify-center gap-2 rounded-2xl bg-foreground py-6 text-base font-semibold text-background transition-colors hover:bg-foreground/90 disabled:opacity-50",children:p?jsxs(Fragment,{children:[jsx(Loader2,{className:"h-5 w-5 animate-spin"}),"Redirecting to Stripe..."]}):jsxs(Fragment,{children:[jsx(CreditCard,{className:"h-5 w-5"}),"Pay with Card"]})}),m&&jsx("p",{className:"text-center text-sm text-red-500",children:m})]}):b==="solana"?jsx(gt,{amountSol:n.priceSol??0,onSuccess:q}):null,c&&jsx("p",{className:"text-center text-sm text-red-500",children:c}),jsx("button",{type:"button",onClick:()=>B(0),className:"w-full rounded-2xl border border-border bg-transparent py-3 text-center text-sm font-medium text-foreground transition-colors hover:bg-muted/30",children:"Cancel"})]})]})})}var Yn={ios:"iOS",android:"Android",windows:"Windows",mac:"macOS",linux:"Linux"},qn=["mac","windows","linux","ios","android"],Jn="https://www.stacknet.org/download";function ht({downloads:e,className:t,style:r}){let{config:n}=h(),l=useMemo(()=>$t(),[]),a=e||qn.map(i=>({platform:i,label:Yn[i],url:Jn,compatible:i===l})),s=a.find(i=>i.compatible)||a[0],o=a.filter(i=>i.platform!==s.platform);return jsxs("div",{className:f("space-y-8",t),style:r,children:[jsxs("div",{className:"flex flex-col items-center gap-6 pt-4 mt-4",children:[n.aispImage&&jsx("img",{src:D(n.aispImage),alt:"aiSP",className:"w-full sm:w-1/2 mx-auto px-4 sm:px-0"}),jsxs("div",{className:"text-center",children:[jsx("p",{className:"text-lg sm:text-2xl font-medium text-foreground",children:"Download the AI Service Provider App"}),jsx("p",{className:"mt-1 text-sm sm:text-base text-muted-foreground",children:"Load your keys and run your node."})]}),jsxs("a",{href:D(s.url),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-3 rounded-full px-10 py-4 text-lg font-semibold text-white transition-colors hover:opacity-90",style:{backgroundColor:"#0900f4"},children:[jsx(Download,{className:"h-5 w-5"}),"Get aiSP for ",s.label]})]}),jsxs("p",{className:"text-center text-sm text-muted-foreground",children:["aiSP is also available on"," ",o.map((i,d)=>jsxs(Fn.Fragment,{children:[d>0&&(d===o.length-1?" and ":", "),jsx("a",{href:D(i.url),target:"_blank",rel:"noopener noreferrer",className:"font-medium underline transition-colors hover:text-foreground",style:{color:"#066bff"},children:i.label})]},i.platform)),"."]}),jsxs("div",{className:"flex flex-col items-center gap-2 mt-12",children:[jsxs("p",{className:"text-center text-xs text-muted-foreground flex justify-center gap-0.5 flex-wrap",children:["Source code is available on",jsx("a",{href:"https://github.com/stack-net",target:"_blank",rel:"noopener noreferrer",className:"text-foreground underline hover:text-foreground/80 color-[#0900f4]",children:"Github"})]}),jsxs("p",{className:"text-center text-xs text-muted-foreground flex justify-center gap-0.5 flex-wrap",children:["By downloading, you agree to the",jsx("a",{href:D(n.termsUrl,"/terms"),target:"_blank",rel:"noopener noreferrer",className:"text-foreground underline hover:text-foreground/80",children:"Open Source Applications Terms"})]})]})]})}var Gn={"bg-green-500":"bg-green-900/50","bg-yellow-500":"bg-yellow-900/50","bg-red-500":"bg-red-900/50"};function oe({current:e,max:t,className:r,style:n,showLabel:l=true,segments:a=40}){let s=_t(e,t),o=Dt(s),i=Gn[o]||"bg-muted",d=Math.round(s/100*a);return jsxs("div",{className:f("w-full",r),style:n,children:[l&&jsxs("div",{className:"mb-1 flex items-center justify-between text-xs text-muted-foreground",children:[jsxs("span",{children:[F(e)," / ",F(t)]}),jsxs("span",{children:[s,"%"]})]}),jsx("div",{className:"flex h-6 w-full items-stretch gap-1",children:Array.from({length:a}).map((c,u)=>jsx("div",{className:f("flex-1 rounded-[1px] transition-colors duration-300",u<d?o:i)},u))})]})}function Be({open:e,onClose:t,title:r,children:n}){let l=useRef(null),[a,s]=useState(false),[o,i]=useState(false),d=useCallback(c=>{c.key==="Escape"&&t();},[t]);return useEffect(()=>{if(e)s(true),document.addEventListener("keydown",d),document.body.style.overflow="hidden",requestAnimationFrame(()=>{requestAnimationFrame(()=>i(true));});else {i(false);let c=setTimeout(()=>{s(false),document.body.style.overflow="";},300);return document.removeEventListener("keydown",d),()=>clearTimeout(c)}return ()=>{document.removeEventListener("keydown",d);}},[e,d]),a?jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",children:[jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm transition-opacity duration-300",style:{opacity:o?1:0},onClick:t}),jsxs("div",{ref:l,className:f("relative z-10 w-full max-w-xl rounded-t-2xl bg-background shadow-2xl","max-h-[85vh] flex flex-col","transition-transform duration-300 ease-out"),style:{transform:o?"translateY(0)":"translateY(100%)"},children:[jsx("div",{className:"flex justify-center pt-3 pb-1",children:jsx("div",{className:"h-1 w-10 rounded-full bg-muted-foreground/30"})}),r&&jsxs("div",{className:"flex items-center justify-between px-5 pb-3 pt-1",children:[jsx("h3",{className:"text-lg font-semibold text-foreground",children:r}),jsx("button",{onClick:t,className:"rounded-full p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors","aria-label":"Close",children:jsx(X,{className:"h-5 w-5"})})]}),jsx("div",{className:"flex-1 overflow-y-auto px-5 pb-8",children:n})]})]}):null}var $e=[" .-----."," / (_) \\"," / \\","( )"," \\ /"," \\_______/"," || |"," || |"," || /"," || /"," || \\"," || /"," || /"," \\// "],vt=16,ts=vt*.6,or=vt*1;function Nt({className:e,style:t,color:r="currentColor",ariaLabel:n="Node key",keyImage:l,keyImageClass:a}){if(l)return jsx("img",{src:D(l),alt:n,className:f(a||"h-20 w-auto mx-auto",e),style:t});let s=$e.reduce((p,m)=>Math.max(p,m.length),0),o=$e.length,i=s*ts,c=o*or;return jsx("svg",{viewBox:`0 0 ${c} ${i}`,xmlns:"http://www.w3.org/2000/svg",className:f("block",e),style:t,role:"img","aria-label":n,preserveAspectRatio:"xMidYMid meet",children:jsx("g",{transform:`translate(0 ${i}) rotate(-90)`,children:$e.map((p,m)=>jsx("text",{x:0,y:(m+.8)*or,fill:r,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:vt,xmlSpace:"preserve",children:p},m))})})}function is(e){if(!e)return "";try{return new Date(e).toLocaleTimeString()}catch{return ""}}function ls({state:e,isLast:t}){let r=e.status==="done",n=e.status==="current",l=e.status==="failed",a=r?Check:l?AlertCircle:n?ArrowRight:Circle,s=f("flex h-8 w-8 shrink-0 items-center justify-center rounded-full",n&&"bg-foreground text-background",r&&"bg-green-500/15 text-green-500",l&&"bg-red-500/15 text-red-500",!r&&!n&&!l&&"bg-muted text-muted-foreground"),o=Se[e.id],i=r?o.done:n?o.progressing:o.pending;return jsxs("li",{className:"flex gap-3",children:[jsxs("div",{className:"relative flex flex-col items-center",children:[jsx("div",{className:s,children:jsx(a,{className:"h-4 w-4"})}),!t&&jsx("div",{className:f("w-px flex-1 mt-1",r?"bg-green-500/30":"bg-border"),style:{minHeight:32}})]}),jsxs("div",{className:f("flex-1 pb-6",t&&"pb-0"),children:[jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[jsxs("span",{className:f("text-sm font-medium lowercase",r&&"text-foreground font-bold",n&&"text-foreground",l&&"text-red-500",!r&&!n&&!l&&"text-muted-foreground"),children:[i,e.id==="confirmed"&&e.approvalsCount!=null&&e.approvalsThreshold!=null&&jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",e.approvalsCount," of ",e.approvalsThreshold,")"]})]}),e.timestampMs&&jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:is(e.timestampMs)})]}),e.detail&&jsx("p",{className:f("mt-0.5 text-xs",l?"text-red-500":"text-muted-foreground"),children:e.detail}),e.externalUrl&&jsxs("a",{href:D(e.externalUrl),target:"_blank",rel:"noopener noreferrer",className:"mt-1 inline-flex items-center gap-1 text-xs text-foreground/80 hover:text-foreground underline-offset-4 hover:underline",children:[jsx(ExternalLink,{className:"h-3 w-3"}),"view"]})]})]})}function wt({states:e,className:t}){return jsx("ol",{className:f("flex flex-col",t),children:e.map((r,n)=>jsx(ls,{state:r,isLast:n===e.length-1},r.id))})}function Pt({text:e,speedMs:t=40,playing:r,className:n}){let[l,a]=useState(()=>r?"":e);return useEffect(()=>{if(!r){a(e);return}a("");let s=0,o=false,i,d=()=>{o||(s+=1,a(e.slice(0,s)),s<e.length&&(i=setTimeout(d,t)));};return i=setTimeout(d,t),()=>{o=true,clearTimeout(i);}},[e,t,r]),jsxs("span",{className:n,children:[l,r?jsx("span",{"aria-hidden":"true",className:"font-mono font-normal opacity-70",children:"\u258A"}):null]})}function ge(e,t=6,r=6){return e?e.length<=t+r+1?e:`${e.slice(0,t)}\u2026${e.slice(-r)}`:""}function hs({value:e}){let[t,r]=useState(false);return jsx("button",{type:"button",onClick:()=>{typeof navigator>"u"||!navigator.clipboard||(navigator.clipboard.writeText(e),r(true),setTimeout(()=>r(false),1200));},className:"text-muted-foreground hover:text-foreground transition-colors","aria-label":"Copy",children:t?jsx(Check,{className:"h-3.5 w-3.5 text-green-500"}):jsx(Copy,{className:"h-3.5 w-3.5"})})}function Q({label:e,value:t,href:r,copyValue:n}){return jsxs("div",{className:"flex items-start justify-between gap-3 py-2 border-b border-border last:border-b-0",children:[jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground shrink-0",children:e}),jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r?jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"text-xs font-mono text-foreground underline underline-offset-4 break-all",children:t}):jsx("span",{className:"text-xs font-mono text-foreground break-all",children:t}),n&&jsx(hs,{value:n})]})]})}function ks({detail:e}){let[t,r]=useState(false);return jsxs("div",{className:"border border-border rounded-xl",children:[jsxs("button",{type:"button",onClick:()=>r(!t),className:"flex w-full items-center justify-between p-4 text-sm font-semibold text-foreground hover:bg-muted/40 transition-colors rounded-xl",children:["Technical details",t?jsx(ChevronUp,{className:"h-4 w-4"}):jsx(ChevronDown,{className:"h-4 w-4"})]}),t&&jsxs("div",{className:"px-4 pb-3",children:[jsx(Q,{label:"Filing ID",value:ge(e.filingId,8,8),copyValue:e.filingId}),jsx(Q,{label:"Key ID",value:ge(e.keyId,8,8),copyValue:e.keyId}),jsx(Q,{label:"File hash",value:ge(e.fileHash,8,8),copyValue:e.fileHash}),e.intentHashHex&&jsx(Q,{label:"Intent hash",value:ge(e.intentHashHex,8,8),copyValue:e.intentHashHex}),e.proofPda&&jsx(Q,{label:"Proof PDA",value:ge(e.proofPda,8,8),copyValue:e.proofPda}),e.txSignature&&jsx(Q,{label:"Tx",value:ge(e.txSignature,8,8),href:`https://solscan.io/tx/${encodeURIComponent(e.txSignature)}`,copyValue:e.txSignature}),jsx(Q,{label:"Beneficiary",value:ge(e.beneficiary,8,8),copyValue:e.beneficiary}),e.onchainBeneficiary&&e.onchainBeneficiary!==e.beneficiary&&jsx(Q,{label:"On-chain wallet",value:ge(e.onchainBeneficiary,8,8),copyValue:e.onchainBeneficiary}),jsx(Q,{label:"Payout method",value:e.payoutMethod}),jsx(Q,{label:"Memo",value:e.memo}),jsx(Q,{label:"Amount",value:Ae(e.amountUsdc)}),jsx(Q,{label:"Tokens used",value:e.tokensUsed}),jsx(Q,{label:"Filed at",value:ee(e.filedAt)}),e.stripePaymentIntentId&&jsx(Q,{label:"Stripe PI",value:ge(e.stripePaymentIntentId,6,6),copyValue:e.stripePaymentIntentId}),e.failureReason&&jsx(Q,{label:"Failure",value:e.failureReason})]})]})}function Ct({filingId:e,className:t,style:r}){let{detail:n,loading:l,error:a}=ct(e),s=Fn.useMemo(()=>Ve(n?.tracker),[n?.tracker]),o=We(s,!!n),i=s.find(d=>d.status==="failed");return a&&!n?jsxs("div",{className:f("space-y-4",t),style:r,children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx(AlertCircle,{className:"h-6 w-6 text-red-500","aria-hidden":true}),jsx("h3",{className:"text-xl font-semibold text-foreground",children:"Unable to load filing"})]}),jsx("p",{className:"text-sm text-muted-foreground",children:a})]}):jsxs("div",{className:f("space-y-5",t),style:r,children:[jsxs("div",{className:"flex flex-col gap-1",children:[jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"delivery status"}),jsx("h1",{className:f("text-4xl font-mono tracking-tight",i?"text-red-500":"text-foreground"),children:i?o.text:jsx(Pt,{text:o.text,playing:o.playing,speedMs:40})})]}),l&&!n&&jsxs("div",{className:"space-y-3",children:[jsx("div",{className:"h-5 w-40 bg-muted animate-pulse rounded"}),jsx("div",{className:"h-5 w-32 bg-muted animate-pulse rounded"}),jsx("div",{className:"h-5 w-48 bg-muted animate-pulse rounded"})]}),jsx(wt,{states:s}),n&&jsx(ks,{detail:n})]})}function Ts(e,t=6,r=6){return !e||e.length<=t+r+1?e:`${e.slice(0,t)}\u2026${e.slice(-r)}`}function Is({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 2000 2000","aria-label":"USDC",role:"img",className:e,children:[jsx("path",{d:"M1000 2000c554.17 0 1000-445.83 1000-1000S1554.17 0 1000 0 0 445.83 0 1000s445.83 1000 1000 1000z",fill:"#2775ca"}),jsx("path",{d:"M1275 1158.33c0-145.83-87.5-195.83-262.5-216.66-125-16.67-150-50-150-108.34s41.67-95.83 125-95.83c75 0 116.67 25 137.5 87.5 4.17 12.5 16.67 20.83 29.17 20.83h66.66c16.67 0 29.17-12.5 29.17-29.16v-4.17c-16.67-91.67-91.67-162.5-187.5-170.83v-100c0-16.67-12.5-29.17-33.33-33.34h-62.5c-16.67 0-29.17 12.5-33.34 33.34v95.83c-125 16.67-204.16 100-204.16 204.17 0 137.5 83.33 191.66 258.33 212.5 116.67 20.83 154.17 45.83 154.17 112.5s-58.34 112.5-137.5 112.5c-108.34 0-145.84-45.84-158.34-108.34-4.16-16.66-16.66-25-29.16-25h-70.84c-16.66 0-29.16 12.5-29.16 29.17v4.17c16.66 104.16 83.33 179.16 220.83 200v100c0 16.66 12.5 29.16 33.33 33.33h62.5c16.67 0 29.17-12.5 33.34-33.33v-100c125-20.84 208.33-108.34 208.33-220.84z",fill:"#fff"}),jsx("path",{d:"M787.5 1595.83c-325-116.66-491.67-479.16-370.83-800 62.5-175 200-308.33 370.83-370.83 16.67-8.33 25-20.83 25-41.67V325c0-16.67-8.33-29.17-25-33.33-4.17 0-12.5 0-16.67 4.16-395.83 125-612.5 545.84-487.5 941.67 75 233.33 254.17 412.5 487.5 487.5 16.67 8.33 33.34 0 37.5-16.67 4.17-4.16 4.17-8.33 4.17-16.66v-58.34c0-12.5-12.5-29.16-25-37.5zM1229.17 295.83c-16.67-8.33-33.34 0-37.5 16.67-4.17 4.17-4.17 8.33-4.17 16.67v58.33c0 16.67 12.5 33.33 25 41.67 325 116.66 491.67 479.16 370.83 800-62.5 175-200 308.33-370.83 370.83-16.67 8.33-25 20.83-25 41.67V1700c0 16.67 8.33 29.17 25 33.33 4.17 0 12.5 0 16.67-4.16 395.83-125 612.5-545.84 487.5-941.67-75-237.5-258.34-416.67-487.5-491.67z",fill:"#fff"})]})}function Us({nodeKey:e,stackName:t}){let r=Math.max(0,e.maxTokens-e.tokenBalance);return jsxs("div",{className:"rounded-xl bg-muted/30 p-5 space-y-2 text-sm",children:[e.keyIndex!=null&&jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Key #"}),jsxs("span",{className:"text-foreground font-semibold",children:["#",e.keyIndex]})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Key ID"}),jsx("code",{className:"text-xs text-foreground",children:Ts(e.id,8,8)})]}),t&&jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Originating Stack"}),jsx("span",{className:"text-foreground",children:t})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Compute tokens used"}),jsxs("span",{className:"text-foreground",children:[F(r)," / ",F(e.maxTokens)]})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Created"}),jsx("span",{className:"text-foreground",children:ee(e.createdAt)})]})]})}function St({keyId:e,onComplete:t,onBack:r,onViewFiling:n,onConfigureEarnings:l,className:a,style:s}){let{config:o}=h(),{keys:i,loading:d,error:c,refresh:u}=te(),p=i.find(le=>le.id===e),{account:m,loading:g,error:x}=Ue(p?.stackId),{filePaperwork:b,filing:k,result:T,error:B}=st(),[N,z]=useState(false),[M,L]=useState(false),V=le=>M?"* * * *":le;useEffect(()=>{T&&!N&&(z(true),t?.(T),u());},[T,N,t,u]);let q=!!p?.paperWork&&p.paperWork!=="0",H=!!m?.method,j=q&&H&&!k&&!T,G=async()=>{if(!j||!p)return;let le=m?.method==="solana"?"usdc":m?.method==="stripe"?"stripe":null;await b(p.id,le);};if(T)return jsxs("div",{className:f("space-y-6",a),style:s,children:[jsx(Ct,{filingId:T.filingId}),jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[n&&jsx("button",{type:"button",onClick:()=>n(T.filingId),className:"flex-1 rounded-xl bg-foreground text-background py-3 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:"Open filing"}),r&&jsx("button",{type:"button",onClick:r,className:"flex-1 rounded-xl border border-border bg-background text-foreground py-3 text-sm font-semibold hover:bg-muted/50 transition-colors",children:"Back to dashboard"})]})]});if(d||g)return jsxs("div",{className:f("space-y-4",a),style:s,children:[jsx("div",{className:"h-7 w-48 bg-muted animate-pulse rounded-xl"}),jsx("div",{className:"h-32 w-full bg-muted animate-pulse rounded-xl"}),jsx("div",{className:"h-12 w-full bg-muted animate-pulse rounded-xl"})]});if(c||!p)return jsxs("div",{className:f("space-y-4",a),style:s,children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx(AlertCircle,{className:"h-6 w-6 text-red-500","aria-hidden":true}),jsx("h3",{className:"text-xl font-semibold text-foreground",children:c?"Unable to load keys":"Key not found"})]}),jsx("p",{className:"text-sm text-muted-foreground",children:c||`No key with id ${e} on this account.`}),jsx("button",{type:"button",onClick:()=>u(),className:"rounded-xl bg-foreground text-background px-4 py-3 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:"Try again"})]});let me=p.stackName||o.stackName,fe=null,ie=null,ye="";return m?.method==="solana"&&m.solana?(ie=jsx(Is,{className:"h-7 w-7 shrink-0"}),ye="USDC",fe=jsx("code",{className:"text-xs text-foreground break-all",children:V(m.solana.address)})):m?.method==="stripe"&&m.stripe&&(ie=jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-foreground text-background",children:jsx(CreditCard,{className:"h-4 w-4"})}),ye="USD via Stripe",fe=jsxs("span",{className:"text-xs text-foreground",children:["Stripe account ",jsx("code",{className:"text-xs",children:V(m.stripe.accountIdMasked)}),!m.stripe.payoutsEnabled&&jsx("span",{className:"ml-2 text-amber-600",children:"(payouts pending)"})]})),jsxs("div",{className:f("space-y-6",a),style:s,children:[jsx("p",{className:"text-sm text-muted-foreground",children:"Your earnings will be deposited into your earnings account."}),jsx(Us,{nodeKey:p,stackName:me}),!q&&jsx("div",{className:"rounded-xl bg-muted/30 p-4 text-sm text-muted-foreground",children:"This key has no pending paperwork. Run your node to earn Paper, then return to file."}),x&&!H&&jsxs("div",{className:"rounded-xl bg-muted/30 p-4 text-sm text-muted-foreground",children:["Couldn't load your earnings account (",x,"). Try again in a moment."]}),!H&&!x?jsxs("div",{className:"rounded-xl border border-border p-4 space-y-3",children:[jsxs("div",{className:"flex items-start gap-3",children:[jsx(Info,{className:"h-5 w-5 mt-0.5 text-foreground shrink-0","aria-hidden":true}),jsxs("div",{className:"space-y-1",children:[jsx("p",{className:"text-sm font-semibold text-foreground",children:"Earnings account required"}),jsx("p",{className:"text-sm text-muted-foreground",children:"Connect a payout destination before filing. You only do this once."})]})]}),l&&jsxs("button",{type:"button",onClick:l,className:"inline-flex items-center gap-2 rounded-xl bg-foreground text-background px-4 py-2 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:[jsx(ExternalLink,{className:"h-4 w-4"}),"Set up earnings account"]})]}):H&&q?jsxs("div",{className:"space-y-2",children:[jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Payout"}),jsxs("div",{className:"rounded-xl bg-muted/30 p-4 flex items-start gap-3",children:[ie,jsxs("div",{className:"flex flex-col gap-1 min-w-0",children:[jsx("span",{className:"text-sm font-semibold text-foreground",children:ye}),fe]}),jsx("button",{type:"button",onClick:()=>L(le=>!le),"aria-label":M?"Show address":"Hide address","aria-pressed":M,className:"ml-auto mt-0.5 p-0.5 text-muted-foreground hover:text-foreground transition-colors shrink-0",children:M?jsx(Eye,{className:"h-4 w-4"}):jsx(EyeOff,{className:"h-4 w-4"})})]})]}):null,B&&jsx("p",{className:"text-sm text-red-500",children:B}),jsx("button",{type:"button",onClick:G,disabled:!j,className:f("w-full rounded-xl py-4 text-sm font-semibold transition-colors",j?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:k?"Filing\u2026":"File Paperwork"})]})}function Fs({nodeKey:e,onSuccess:t}){let{transferKey:r,transferring:n,result:l,error:a}=Ie(),[s,o]=useState(""),[i,d]=useState(false),c=s.trim()===e.userId,u=s.trim().length>0&&i&&!c&&!n,p=async()=>{if(!u)return;await r(e.id,s.trim())&&t();};return l?jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[jsx(CheckCircle,{className:"h-12 w-12 text-green-500"}),jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Transfer Complete"}),jsx("p",{className:"text-sm text-muted-foreground",children:"Key transferred successfully"})]}):jsxs("div",{className:"space-y-5",children:[jsxs("div",{children:[jsx("label",{className:"mb-1.5 block text-sm font-semibold text-foreground",children:"Recipient User ID"}),jsx("input",{type:"text",value:s,onChange:m=>{o(m.target.value),d(false);},placeholder:"Enter recipient's user ID or global ID",className:"w-full rounded-xl border border-border bg-background px-4 py-3 text-sm text-foreground placeholder:text-muted-foreground focus:border-foreground/30 focus:outline-none focus:ring-1 focus:ring-foreground/10"}),c&&jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),s.trim().length>0&&!c&&jsx("div",{className:"rounded-xl border border-amber-500/30 bg-amber-500/5 p-4",children:jsxs("div",{className:"flex items-start gap-3",children:[jsx(AlertTriangle,{className:"mt-0.5 h-5 w-5 shrink-0 text-amber-500"}),jsxs("div",{className:"space-y-3",children:[jsxs("div",{children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Confirm Transfer"}),jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Transferring key"," ",jsx("span",{className:"font-mono font-medium",children:e.keyIndex?`#${e.keyIndex}`:e.id.slice(0,12)})," ","(",F(e.tokenBalance)," tokens) to"," ",jsxs("span",{className:"font-mono font-medium",children:[s.trim().slice(0,20),s.trim().length>20?"...":""]})]})]}),jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsx("input",{type:"checkbox",checked:i,onChange:m=>d(m.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border"}),jsx("span",{className:"text-xs text-muted-foreground",children:"I confirm this transfer is permanent and cannot be undone."})]})]})]})}),a&&jsx("p",{className:"text-sm text-red-500",children:a}),jsx("button",{onClick:p,disabled:!u,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",u?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:n?jsxs(Fragment,{children:[jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Transferring..."]}):jsxs(Fragment,{children:[jsx(Send,{className:"h-4 w-4"}),"Transfer Key"]})})]})}function As({nodeKey:e,onSuccess:t}){let{config:r}=h(),{listKey:n,listing:l,result:a,error:s}=Te(),[o,i]=useState(""),[d,c]=useState(false),u=parseInt(o.replace(/[^0-9]/g,""),10)||0,m=u>0&&Number.isFinite(u)&&d&&!l,g=async()=>{if(!m)return;let x=u*100;await n(e.id,x)&&t();};return a?jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[jsx(CheckCircle,{className:"h-12 w-12 text-green-500"}),jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Key Listed!"}),jsx("p",{className:"text-sm text-muted-foreground",children:"Your key is now on the marketplace."}),jsxs("p",{className:"text-xs text-muted-foreground",children:["Listing ID: ",jsx("code",{children:a.listingId})]}),jsxs("a",{href:`https://market.stacknet.org/keys/${encodeURIComponent(a.keyId)}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 rounded-xl bg-foreground px-6 py-3 text-sm font-semibold text-background transition-colors hover:bg-foreground/90",children:[jsx(ExternalLink,{className:"h-4 w-4"}),"View Listing"]})]}):jsxs("div",{className:"space-y-5",children:[jsxs("div",{children:[jsx("label",{htmlFor:"listing-price",className:"mb-2 block text-sm font-semibold text-foreground",children:"Listing Price (USD)"}),jsxs("div",{className:"relative",children:[jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-2xl font-bold text-muted-foreground",children:"$"}),jsx("input",{id:"listing-price",type:"text",inputMode:"numeric",value:o,onChange:x=>{let b=x.target.value.replace(/[^0-9]/g,""),k=parseInt(b,10);i(isNaN(k)?"":k.toLocaleString("en-US"));},placeholder:"0",className:"w-full rounded-xl border bg-background py-6 pl-10 pr-4 text-3xl font-bold text-foreground placeholder:text-muted-foreground/30 focus:outline-none focus:ring-2 focus:ring-foreground/20"})]})]}),jsxs("div",{className:"flex items-start gap-3",children:[jsx("button",{type:"button",role:"checkbox","aria-checked":d,onClick:()=>c(!d),className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",d?"border-foreground bg-foreground":"border-muted-foreground/40"),children:d&&jsx(Check,{className:"h-3 w-3 text-background"})}),jsxs("span",{className:"text-xs text-muted-foreground leading-relaxed",children:["I agree to list this key on the Global Open AI Network marketplace. The key will be deactivated upon sale and transferred to the buyer. Listing fees may apply."," ",jsx("a",{href:D(r.termsUrl,"/terms"),className:"text-foreground underline",target:"_blank",rel:"noopener noreferrer",children:"Terms"})]})]}),s&&jsx("p",{className:"text-sm text-red-500",children:s}),jsxs("button",{onClick:g,disabled:!m,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",m?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:[jsx(ExternalLink,{className:"h-4 w-4"}),l?"Listing...":"List on Marketplace"]})]})}function Ms({nodeKey:e,onSuccess:t,onClose:r,onViewFiling:n,onConfigureEarnings:l}){return jsx(St,{keyId:e.id,onComplete:t,onBack:r,onViewFiling:n,onConfigureEarnings:l})}function Rt({nodeKey:e,onBack:t,onKeysChanged:r,onViewFiling:n,onConfigureEarnings:l,className:a,style:s}){let{config:o}=h(),{entries:i,loading:d}=Re(e.id),[c,u]=useState(null),[p,m]=useState(false),g=()=>{u(null),r?.();},x=T=>{},b=()=>{e.key&&(navigator.clipboard.writeText(e.key),m(true),setTimeout(()=>m(false),2e3));},k=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsxs("div",{className:f("space-y-5",a),style:s,children:[jsxs("button",{onClick:t,className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors",children:[jsx(ArrowLeft,{className:"h-4 w-4"}),"View All"]}),jsx(Nt,{className:f("mx-auto text-foreground px-0 sm:px-0",o.keyImage?"w-2/3 h-auto":"h-20 w-auto"),keyImage:o.keyImage,keyImageClass:o.keyImageClass}),jsx("div",{className:"space-y-1",children:jsxs("div",{className:"flex items-center justify-between",children:[jsx("h2",{className:"text-3xl font-bold text-foreground",children:e.keyIndex?`Key #${e.keyIndex}`:e.label||e.id.slice(0,16)}),jsx("span",{className:f("text-sm font-medium capitalize",k),children:e.status})]})}),e.key&&jsxs("div",{className:"flex items-center gap-2",children:[jsx("code",{className:"flex-1 truncate px-0 py-2 text-lg text-muted-foreground",children:e.key}),jsx("button",{onClick:b,"aria-label":"Copy key",className:"shrink-0 rounded-lg p-2 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",children:p?jsx(Check,{className:"h-4 w-4 text-green-500"}):jsx(Copy,{className:"h-4 w-4"})})]}),jsx(oe,{current:e.tokenBalance,max:e.maxTokens,showLabel:true}),jsxs("div",{className:"rounded-xl bg-muted/30 p-5 space-y-2.5 text-sm",children:[(o.stackName||e.stackName)&&jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Stack"}),jsx("span",{className:"text-foreground",children:e.stackName||o.stackName})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Created"}),jsx("span",{className:"text-foreground",children:ee(e.createdAt)})]}),e.expiresAt&&jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Expires"}),jsx("span",{className:"text-foreground",children:ee(e.expiresAt)})]})]}),e.paperWork&&e.paperWork!=="0"&&jsxs("div",{className:"rounded-xl p-5",children:[jsx("h3",{className:"text-sm font-semibold text-foreground mb-2",children:"Paperwork"}),jsx("p",{className:"text-2xl font-semibold tabular-nums text-foreground",children:Ae(e.paperWork)})]}),e.status==="active"&&jsxs("div",{className:"grid grid-cols-3 gap-3",children:[jsx("button",{onClick:()=>u("transfer"),className:"flex items-center justify-center rounded-xl border border-border p-4 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors",children:"Transfer"}),jsx("button",{onClick:()=>u("sell"),className:"flex items-center justify-center rounded-xl border border-border p-4 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors",children:"Sell"}),jsx("button",{onClick:()=>u("file"),className:"flex items-center justify-center rounded-xl border border-border p-4 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors",children:"File"})]}),jsx(Be,{open:c==="transfer",onClose:()=>u(null),title:"Transfer Key",children:jsx(Fs,{nodeKey:e,onSuccess:g})}),jsx(Be,{open:c==="sell",onClose:()=>u(null),title:"Sell Key",children:jsx(As,{nodeKey:e,onSuccess:g})}),jsx(Be,{open:c==="file",onClose:()=>u(null),title:"File Paperwork",children:jsx(Ms,{nodeKey:e,onSuccess:x,onClose:()=>u(null),onViewFiling:n,onConfigureEarnings:l})})]})}function _s({nodeKey:e,onClick:t}){let r=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsx("button",{onClick:t,className:"flex w-full items-start gap-3 rounded-xl border border-border p-4 text-left transition-all hover:border-foreground/20 hover:bg-muted/30",children:jsxs("div",{className:"min-w-0 flex-1",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsx("span",{className:f("text-xs font-medium capitalize",r),children:e.status})]}),jsx(oe,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"}),e.paperWork&&jsx("span",{className:"mt-1.5 inline-block text-xs text-muted-foreground",children:"Has paperwork"})]})})}function Tt({onViewFiling:e,onConfigureEarnings:t,className:r,style:n}){let{keys:l,totalBalance:a,loading:s,error:o,refresh:i}=te(),[d,c]=useState(null),[u,p]=useState("active"),m=l.filter(b=>b.status===u),g=m.reduce((b,k)=>b+k.tokenBalance,0),x=l.find(b=>b.id===d);return x?jsx(Rt,{nodeKey:x,onBack:()=>c(null),onKeysChanged:()=>{c(null),i();},onViewFiling:e,onConfigureEarnings:t,className:r,style:n}):s?jsxs("div",{className:f("space-y-4",r),style:n,children:[jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsx(he,{count:3})]}):o?jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-16",r),style:n,children:[jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o})]}),jsx("button",{onClick:()=>i(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]}):l.length===0?jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 rounded-xl border border-dashed py-16",r),style:n,children:[jsx(KeyRound,{className:"h-10 w-10 text-muted-foreground"}),jsxs("div",{className:"text-center",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys yet"}),jsx("p",{className:"text-xs text-muted-foreground",children:"Get your first node key to start earning."})]})]}):jsxs("div",{className:f("space-y-4",r),style:n,children:[jsxs("div",{className:"flex items-center justify-between mt-3",children:[jsx("h3",{className:"text-2xl font-semibold text-foreground",children:"Your Keys"}),jsxs("span",{className:"hidden text-xs text-muted-foreground sm:inline",children:[m.length," key",m.length!==1?"s":""," \xB7 ",F(g)," tokens"]}),jsx("div",{className:"flex gap-1 rounded-lg bg-muted/50 p-1",children:["active","listed"].map(b=>jsx("button",{onClick:()=>p(b),className:f("rounded-md px-3 py-1 text-xs font-medium capitalize transition-all",u===b?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:b},b))})]}),m.length===0?jsxs("div",{className:"flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-12",children:[jsx(KeyRound,{className:"h-8 w-8 text-muted-foreground"}),jsxs("p",{className:"text-sm text-muted-foreground",children:["No ",u," keys."]})]}):jsx("div",{className:"space-y-2",children:m.map(b=>jsx(_s,{nodeKey:b,onClick:()=>c(b.id)},b.id))})]})}var $s=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function js({active:e,onChange:t}){return jsx("div",{role:"tablist","aria-label":"Key actions",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:$s.map(({id:r,label:n})=>jsx("button",{role:"tab","aria-selected":e===r,"aria-controls":`panel-${r}`,id:`tab-${r}`,onClick:()=>t(r),className:f("flex flex-1 items-center justify-center gap-2.5 rounded-xl py-3.5 text-sm font-medium transition-all",e===r?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:jsx("span",{className:"inline",children:n})},r))})}function Os({defaultTab:e="buy",onViewFiling:t,onConfigureEarnings:r,className:n,style:l}){let[a,s]=useState(e);return jsxs("div",{className:f("flex flex-col",n),style:l,children:[jsx("div",{className:"sticky top-0 z-10 bg-background/80 px-5 pb-3 pt-2 sm:pt-5 backdrop-blur-sm sm:px-10 md:px-16 lg:px-20",children:jsx("div",{className:"mx-auto max-w-xl",children:jsx(js,{active:a,onChange:s})})}),jsx("div",{className:"flex flex-1 flex-col px-5 pb-8 sm:px-10 md:px-16 md:pb-12 lg:px-20",children:jsx("div",{className:"mx-auto w-full max-w-xl flex-1",children:jsxs("div",{role:"tabpanel",id:`panel-${a}`,"aria-labelledby":`tab-${a}`,children:[a==="buy"&&jsx(bt,{className:"flex-1"}),a==="use"&&jsx(ht,{className:"flex-1"}),a==="keys"&&jsx(Tt,{className:"flex-1",onViewFiling:t,onConfigureEarnings:r})]})})})]})}function Hs({apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:n,merchantWallet:l,stripePublicKey:a,theme:s,maxQuantity:o,keyImage:i,keyImageClass:d,aispImage:c,termsUrl:u,onMintSuccess:p,onMintError:m,onPaymentStart:g,onPaymentComplete:x,onListingCreated:b,onTransferComplete:k,onFilingComplete:T,onFilingError:B,defaultTab:N,onViewFiling:z,onConfigureEarnings:M,className:L,style:V}){return jsx(ze,{config:{apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:n,merchantWallet:l,stripePublicKey:a,theme:s,maxQuantity:o,keyImage:i,keyImageClass:d,aispImage:c,termsUrl:u},callbacks:{onMintSuccess:p,onMintError:m,onPaymentStart:g,onPaymentComplete:x,onListingCreated:b,onTransferComplete:k,onFilingComplete:T,onFilingError:B},children:jsx(Os,{defaultTab:N,onViewFiling:z,onConfigureEarnings:M,className:L,style:V})})}function zs({nodeKey:e,selected:t,onSelect:r}){return jsxs("button",{onClick:r,className:f("flex w-full items-start gap-3 rounded-xl border p-4 text-left transition-all",t?"border-foreground/30 bg-foreground/5 ring-1 ring-foreground/10":"border-border hover:border-foreground/20"),children:[jsx("div",{className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors",t?"border-foreground bg-foreground":"border-muted-foreground/40"),children:t&&jsx(Check,{className:"h-3 w-3 text-background"})}),jsxs("div",{className:"min-w-0 flex-1",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsx("span",{className:f("text-xs font-medium capitalize",e.status==="active"?"text-green-500":"text-muted-foreground"),children:e.status})]}),jsx(oe,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function Ys({className:e,style:t}){let{config:r}=h(),{keys:n,loading:l,error:a,refresh:s}=te(),{listKey:o,listing:i,result:d,error:c}=Te(),[u,p]=useState(null),[m,g]=useState(""),[x,b]=useState(false),k=n.find(L=>L.id===u),T=parseInt(m.replace(/[^0-9]/g,""),10)||0,B=T>0&&Number.isFinite(T),N=!!k&&B&&x&&!i,z=async()=>{if(!N||!k)return;let L=T*100;await o(k.id,L)&&s();};if(d)return jsxs("div",{className:f("flex flex-col items-center gap-4 rounded-xl bg-green-500/10 py-12",e),style:t,children:[jsx(CheckCircle,{className:"h-12 w-12 text-green-500"}),jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Key Listed!"}),jsx("p",{className:"text-sm text-muted-foreground",children:"Your key is now on the Global Open AI Network marketplace."}),jsxs("p",{className:"text-xs text-muted-foreground",children:["Listing ID: ",jsx("code",{children:d.listingId})]}),jsxs("a",{href:`https://market.stacknet.org/keys/${encodeURIComponent(d.keyId)}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 rounded-xl bg-foreground px-6 py-3 text-sm font-semibold text-background transition-colors hover:bg-foreground/90",children:[jsx(ExternalLink,{className:"h-4 w-4"}),"View Listing"]})]});if(l)return jsxs("div",{className:f("space-y-5 px-1",e),style:t,children:[jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsx(he,{count:2})]});if(a)return jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-16",e),style:t,children:[jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a})]}),jsx("button",{onClick:()=>s(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]});let M=n.filter(L=>L.status==="active");return M.length===0?jsxs("div",{className:f("flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16",e),style:t,children:[jsx(AlertTriangle,{className:"h-8 w-8 text-muted-foreground"}),jsx("p",{className:"text-sm text-muted-foreground",children:"No active keys to sell."})]}):jsxs("div",{className:f("space-y-5",e),style:t,children:[jsxs("div",{children:[jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsx("div",{className:"space-y-2",children:M.map(L=>jsx(zs,{nodeKey:L,selected:u===L.id,onSelect:()=>p(L.id)},L.id))})]}),k&&jsxs("div",{className:"rounded-xl border bg-muted/30 p-5 space-y-2 text-sm",children:[k.keyIndex&&jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Key #"}),jsxs("span",{className:"text-foreground font-semibold",children:["#",k.keyIndex]})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Key ID"}),jsx("code",{className:"text-xs text-foreground",children:k.id})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Originating Stack"}),jsx("span",{className:"text-foreground",children:r.stackName||"Unknown"})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Tokens (remaining / total)"}),jsxs("span",{className:"text-foreground",children:[F(k.tokenBalance)," / ",F(k.maxTokens)]})]}),k.paperWork&&jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Paper earned"}),jsx("span",{className:"text-foreground",children:k.paperWork})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Created"}),jsx("span",{className:"text-foreground",children:ee(k.createdAt)})]})]}),jsxs("div",{children:[jsx("label",{htmlFor:"listing-price",className:"mb-2 block text-sm sm:text-lg font-semibold text-foreground",children:"Listing Price (USD)"}),jsxs("div",{className:"relative",children:[jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-2xl font-bold text-muted-foreground",children:"$"}),jsx("input",{id:"listing-price",type:"text",inputMode:"numeric",value:m,onChange:L=>{let V=L.target.value.replace(/[^0-9]/g,""),q=parseInt(V,10);g(isNaN(q)?"":q.toLocaleString("en-US"));},placeholder:"0",className:"w-full rounded-xl border bg-background py-6 pl-10 pr-4 text-3xl font-bold text-foreground placeholder:text-muted-foreground/30 focus:outline-none focus:ring-2 focus:ring-foreground/20"})]})]}),jsxs("div",{className:"flex items-start gap-3",children:[jsx("button",{type:"button",role:"checkbox","aria-checked":x,onClick:()=>b(!x),className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",x?"border-foreground bg-foreground":"border-muted-foreground/40"),children:x&&jsx(Check,{className:"h-3 w-3 text-background"})}),jsxs("span",{className:"text-xs text-muted-foreground leading-relaxed",children:["I agree to list this key on the Global Open AI Network marketplace. The key will be deactivated upon sale and transferred to the buyer. Listing fees may apply."," ",jsx("a",{href:D(r.termsUrl,"/terms"),className:"text-foreground underline",target:"_blank",rel:"noopener noreferrer",children:"Terms"})]})]}),c&&jsx("p",{className:"text-sm text-red-500",children:c}),jsxs("button",{onClick:z,disabled:!N,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",N?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:[jsx(ExternalLink,{className:"h-4 w-4"}),i?"Listing...":"List on Marketplace"]})]})}var Ut=20;function Et({nodeKey:e,className:t,style:r}){let[n,l]=useState(false),[a,s]=useState(false),o=useRef(null),{entries:i,loading:d}=Re(n?e.id:null);useEffect(()=>()=>{o.current&&clearTimeout(o.current);},[]);let c=useCallback(()=>{e.key&&(navigator.clipboard.writeText(e.key),s(true),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>s(false),2e3));},[e.key]),u=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500",p=i.slice(0,Ut);return jsxs("div",{className:f("rounded-lg border bg-background",t),style:r,children:[jsxs("div",{className:"p-4",children:[jsxs("div",{className:"mb-3 flex items-center justify-between",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("button",{onClick:()=>l(!n),"aria-expanded":n,"aria-label":n?"Collapse ledger":"Expand ledger",className:"text-muted-foreground hover:text-foreground",children:n?jsx(ChevronDown,{className:"h-4 w-4"}):jsx(ChevronRight,{className:"h-4 w-4"})}),jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]})]}),jsx("span",{className:f("text-xs font-medium capitalize",u),children:e.status})]}),e.key&&jsxs("div",{className:"mb-3 flex items-center gap-2",children:[jsx("code",{className:"flex-1 truncate rounded bg-muted px-2 py-1 text-xs text-muted-foreground",children:e.key}),jsx("button",{onClick:c,"aria-label":"Copy key to clipboard",className:"shrink-0 rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:a?jsx(Check,{className:"h-3.5 w-3.5 text-green-500"}):jsx(Copy,{className:"h-3.5 w-3.5"})})]}),jsx(oe,{current:e.tokenBalance,max:e.maxTokens}),jsxs("div",{className:"mt-2 flex items-center justify-between text-xs text-muted-foreground",children:[jsxs("span",{children:["Created ",ee(e.createdAt)]}),e.expiresAt&&jsxs("span",{children:["Expires ",ee(e.expiresAt)]})]})]}),n&&jsxs("div",{className:"border-t px-4 py-3",children:[jsx("h4",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Ledger"}),d?jsx("p",{className:"text-xs text-muted-foreground",children:"Loading..."}):p.length===0?jsx("p",{className:"text-xs text-muted-foreground",children:"No ledger entries."}):jsxs("div",{className:"space-y-1.5",children:[p.map(m=>jsxs("div",{className:"flex items-center justify-between text-xs",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsxs("span",{className:f("font-medium",m.type==="credit"||m.type==="reward"?"text-green-500":"text-red-500"),children:[m.type==="credit"||m.type==="reward"?"+":"-",F(Math.abs(m.amount))]}),jsx("span",{className:"text-muted-foreground",children:m.description})]}),jsx("span",{className:"text-muted-foreground",children:ee(m.createdAt)})]},m.id)),i.length>Ut&&jsxs("p",{className:"pt-1 text-xs text-muted-foreground",children:["Showing ",Ut," of ",i.length," entries"]})]})]})]})}var ro=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function je({baseHref:e}){return jsx("div",{className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5 mb-6",children:ro.map(({id:t,label:r})=>jsx("a",{href:`${e}?tab=${t}`,className:"flex flex-1 items-center justify-center gap-2.5 rounded-xl py-3.5 text-sm font-medium text-muted-foreground hover:text-foreground transition-all",children:r},t))})}function no({getKeyHref:e="/keys/get",showTabs:t=true,className:r,style:n}){let{keys:l,totalBalance:a,loading:s,error:o,refresh:i}=te();return s?jsxs("div",{className:f("space-y-4",r),style:n,children:[t&&e&&jsx(je,{baseHref:e}),jsx(he,{count:3})]}):o?jsxs("div",{className:f("space-y-4",r),style:n,children:[t&&e&&jsx(je,{baseHref:e}),jsxs("div",{className:"flex flex-col items-center justify-center gap-4 py-12",children:[jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o})]}),jsx("button",{onClick:()=>i(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]})]}):l.length===0?jsxs("div",{className:f("space-y-4",r),style:n,children:[t&&e&&jsx(je,{baseHref:e}),jsxs("div",{className:"flex flex-col items-center justify-center gap-4 rounded-lg border border-dashed py-12",children:[jsx(KeyRound,{className:"h-10 w-10 text-muted-foreground"}),jsxs("div",{className:"text-center",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys yet"}),jsx("p",{className:"text-xs text-muted-foreground",children:"Get your first node key to start earning."})]}),e&&jsx("a",{href:e,className:"rounded-lg bg-foreground px-4 py-2 text-sm font-medium text-background transition-colors hover:bg-foreground/90",children:"Get a Key"})]})]}):jsxs("div",{className:f("space-y-4",r),style:n,children:[t&&e&&jsx(je,{baseHref:e}),jsxs("div",{className:"flex items-center justify-between",children:[jsxs("p",{className:"text-sm text-muted-foreground",children:[l.length," key",l.length!==1?"s":""," \xB7 Total balance: ",F(a)]}),e&&jsx("a",{href:e,className:"rounded-md bg-foreground px-3 py-1.5 text-xs font-medium text-background transition-colors hover:bg-foreground/90",children:"Get a Key"})]}),l.map(d=>jsx(Et,{nodeKey:d},d.id))]})}function lo({nodeKey:e,selected:t,onSelect:r}){return jsxs("button",{onClick:r,className:f("flex w-full items-start gap-3 rounded-xl border p-4 text-left transition-all",t?"border-foreground/30 bg-foreground/5 ring-1 ring-foreground/10":"border-border hover:border-foreground/20"),children:[jsx("div",{className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors",t?"border-foreground bg-foreground":"border-muted-foreground/40"),children:t&&jsx(Check,{className:"h-3 w-3 text-background"})}),jsxs("div",{className:"min-w-0 flex-1",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsx("span",{className:"text-xs font-medium capitalize text-green-500",children:e.status})]}),jsx(oe,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function co({className:e,style:t}){let{keys:r,loading:n}=te(),{transferKey:l,transferring:a,result:s,error:o}=Ie(),[i,d]=useState(null),[c,u]=useState(""),[p,m]=useState(false),g=r.filter(N=>N.status==="active"),x=g.find(N=>N.id===i),b=x&&c.trim()===x.userId,k=i&&c.trim().length>0&&p&&!b&&!a,T=async()=>{!i||!c.trim()||await l(i,c.trim());},B=()=>{d(null),u(""),m(false);};return s?jsxs("div",{className:f("flex flex-col items-center gap-4 py-8",e),style:t,children:[jsx(CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxs("div",{className:"text-center",children:[jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Transfer Complete"}),jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Key transferred successfully"})]}),jsxs("div",{className:"w-full max-w-sm space-y-2 rounded-xl border border-border bg-muted/30 p-4 text-sm",children:[jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Key"}),jsxs("span",{className:"font-mono text-foreground",children:[s.keyId.slice(0,20),"..."]})]}),jsxs("div",{className:"flex justify-between",children:[jsx("span",{className:"text-muted-foreground",children:"Recipient"}),jsxs("span",{className:"font-mono text-foreground",children:[s.toUserId.slice(0,20),"..."]})]})]}),jsx("button",{onClick:B,className:"mt-2 rounded-lg border border-border px-4 py-2 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors",children:"Transfer Another"})]}):jsxs("div",{className:f("space-y-5",e),style:t,children:[jsxs("div",{children:[jsx("h3",{className:"mb-3 text-sm font-medium text-foreground",children:"Select Key to Transfer"}),n?jsx(he,{count:2}):g.length===0?jsx("p",{className:"text-sm text-muted-foreground",children:"No active keys available for transfer."}):jsx("div",{className:"space-y-2",children:g.map(N=>jsx(lo,{nodeKey:N,selected:i===N.id,onSelect:()=>d(N.id)},N.id))})]}),i&&jsxs("div",{children:[jsx("label",{className:"mb-1.5 block text-sm font-medium text-foreground",children:"Recipient User ID"}),jsx("input",{type:"text",value:c,onChange:N=>{u(N.target.value),m(false);},placeholder:"Enter recipient's user ID or global ID",className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:border-foreground/30 focus:outline-none focus:ring-1 focus:ring-foreground/10"}),b&&jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),x&&c.trim().length>0&&!b&&jsx("div",{className:"rounded-xl border border-amber-500/30 bg-amber-500/5 p-4",children:jsxs("div",{className:"flex items-start gap-3",children:[jsx(AlertTriangle,{className:"mt-0.5 h-5 w-5 shrink-0 text-amber-500"}),jsxs("div",{className:"space-y-3",children:[jsxs("div",{children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Confirm Transfer"}),jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["You are about to transfer key"," ",jsx("span",{className:"font-mono font-medium",children:x.keyIndex?`#${x.keyIndex}`:x.id.slice(0,12)})," ","(",F(x.tokenBalance)," tokens) to"," ",jsxs("span",{className:"font-mono font-medium",children:[c.trim().slice(0,20),"..."]})]})]}),jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsx("input",{type:"checkbox",checked:p,onChange:N=>m(N.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border"}),jsx("span",{className:"text-xs text-muted-foreground",children:"I confirm this transfer is permanent and cannot be undone."})]})]})]})}),o&&jsx("p",{className:"text-sm text-red-500",children:o}),jsx("button",{onClick:T,disabled:!k,className:f("flex w-full items-center justify-center gap-2 rounded-lg px-4 py-3 text-sm font-medium transition-all",k?"bg-foreground text-background hover:opacity-90":"bg-muted text-muted-foreground cursor-not-allowed"),children:a?jsxs(Fragment,{children:[jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Transferring..."]}):jsxs(Fragment,{children:[jsx(Send,{className:"h-4 w-4"}),"Transfer Key"]})})]})}function fo(e){return e.status==="active"}function po({count:e=3}){return jsx("div",{className:"space-y-2",children:Array.from({length:e}).map((t,r)=>jsxs("div",{className:"bg-muted/30 p-4 space-y-3",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("div",{className:"h-4 w-40 bg-muted animate-pulse"}),jsx("div",{className:"h-4 w-16 bg-muted animate-pulse"})]}),jsx("div",{className:"h-3 w-32 bg-muted animate-pulse"})]},r))})}function go({nodeKey:e,onSelect:t}){let r=Math.max(0,e.maxTokens-e.tokenBalance);return jsxs("button",{type:"button",onClick:t,className:"group flex w-full items-center gap-4 bg-muted/30 p-4 text-left transition-colors hover:bg-muted/50",children:[jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsxs("span",{className:"text-sm font-semibold text-foreground",children:[e.keyIndex!=null?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsx("span",{className:"text-xs text-muted-foreground",children:e.stackName||""})]}),jsxs("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[jsxs("span",{className:"tabular-nums",children:[F(r)," / ",F(e.maxTokens)," compute used"]}),jsx("span",{className:"text-foreground",children:"Eligible"})]})]}),jsx(ChevronRight,{className:"h-5 w-5 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5","aria-hidden":true})]})}function xo({onSelect:e,className:t,style:r}){let{keys:n,loading:l,error:a,refresh:s}=te();if(l)return jsx("div",{className:f("space-y-3",t),style:r,children:jsx(po,{count:3})});if(a)return jsx("div",{className:f("space-y-3",t),style:r,children:jsxs("div",{className:"bg-muted/30 p-5 text-center",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a}),jsx("button",{type:"button",onClick:()=>s(),className:"mt-3 bg-foreground text-background px-4 py-2 text-xs font-semibold hover:bg-foreground/90 transition-colors",children:"Try again"})]})});let o=n.filter(fo);return o.length===0?jsxs("div",{className:f("flex flex-col items-center justify-center gap-3 bg-muted/20 py-16",t),style:r,children:[jsx(FileText,{className:"h-10 w-10 text-muted-foreground","aria-hidden":true}),jsxs("div",{className:"text-center",children:[jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys with pending paperwork"}),jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Run a node to earn Paper, then return here to file."})]})]}):jsx("div",{className:f("space-y-2",t),style:r,children:o.map(i=>jsx(go,{nodeKey:i,onSelect:()=>e(i.id)},i.id))})}function hr({label:e,sub:t,icon:r,selected:n,enabled:l,disabledLabel:a,onClick:s}){let o=l;return jsxs("button",{type:"button",onClick:o?s:void 0,disabled:!o,"aria-disabled":!o,className:f("flex flex-col items-start gap-1 rounded-xl border p-4 text-left transition-colors",o?n?"border-foreground bg-foreground/5 cursor-pointer":"border-border hover:bg-muted/50 cursor-pointer":"border-border bg-muted/20 cursor-not-allowed opacity-70"),children:[jsxs("div",{className:"flex w-full items-center justify-between",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:f("flex h-7 w-7 items-center justify-center rounded-md",n&&l?"bg-foreground text-background":"bg-muted text-foreground"),children:r}),jsx("span",{className:"text-sm font-semibold text-foreground",children:e})]}),!l&&jsx(Lock,{className:"h-3.5 w-3.5 text-muted-foreground","aria-hidden":true})]}),jsx("p",{className:f("text-xs",l?"text-muted-foreground":"text-muted-foreground/80"),children:l?t:a??t})]})}function ko({caps:e,value:t,onChange:r,className:n,disabled:l=false}){let a=e.stripe.enabled&&!l,s=e.usdc.enabled&&!l,o=`disabled by ${e.stackName} stack`,i=`disabled by ${e.stackName} stack`;return jsxs("div",{className:f("space-y-2",n),children:[jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Payout method"}),jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[jsx(hr,{label:"USDC",sub:"On-chain payout to your stack address",icon:jsx(Wallet,{className:"h-4 w-4"}),selected:t==="usdc",enabled:s,disabledLabel:i,onClick:()=>r("usdc")}),jsx(hr,{label:"Stripe",sub:"USD payout to your bank via Stripe",icon:jsx(CreditCard,{className:"h-4 w-4"}),selected:t==="stripe",enabled:a,disabledLabel:o,onClick:()=>r("stripe")})]})]})}function Oe({ok:e,label:t}){return jsxs("span",{className:f("inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-[11px] font-medium",e?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"),children:[e?jsx(CheckCircle2,{className:"h-3 w-3"}):jsx(AlertCircle,{className:"h-3 w-3"}),t]})}function Nr({active:e,onClick:t,icon:r,label:n,sub:l}){return jsxs("button",{type:"button",onClick:t,className:f("flex flex-1 items-start gap-3 rounded-xl border p-4 text-left transition-colors",e?"border-foreground bg-foreground/5":"border-border hover:bg-muted/40"),children:[jsx("span",{className:f("flex h-8 w-8 shrink-0 items-center justify-center rounded-md",e?"bg-foreground text-background":"bg-muted text-foreground"),children:r}),jsxs("span",{className:"flex flex-col",children:[jsx("span",{className:"text-sm font-semibold text-foreground",children:n}),jsx("span",{className:"text-xs text-muted-foreground",children:l})]})]})}function To({stackId:e,onChange:t,className:r,style:n}){let{account:l,loading:a,error:s,refresh:o,disconnect:i,disconnecting:d}=Ue(e),{caps:c,loading:u}=it(e),{startStripeConnect:p,starting:m,error:g}=ut(e),{connectAndVerify:x,connecting:b,error:k}=mt(),T=!!c?.stripe.enabled,B=l?.method??null,[N,z]=useState(B??"solana");useEffect(()=>{B?z(B):!T&&N==="stripe"&&z("solana");},[B,T,N]);let M=async()=>{await p(),t?.();},L=async()=>{await x()&&(await o(),t?.());},V=async()=>{await i(B==="stripe"?e:void 0)&&t?.();};if(a||u)return jsxs("div",{className:f("space-y-3",r),style:n,children:[jsx("div",{className:"h-5 w-40 bg-muted animate-pulse rounded"}),jsx("div",{className:"h-24 w-full bg-muted animate-pulse rounded-xl"})]});if(s)return jsxs("div",{className:f("space-y-3",r),style:n,children:[jsx("h3",{className:"text-base font-semibold text-foreground",children:"Earnings Account"}),jsxs("div",{className:"rounded-xl border border-border bg-muted/20 p-4 text-sm text-muted-foreground space-y-3",children:[jsx("p",{children:"Earnings onboarding is temporarily unavailable. Try again in a moment."}),jsxs("button",{type:"button",onClick:()=>o(),className:"inline-flex items-center gap-1 text-xs text-foreground underline-offset-4 hover:underline",children:[jsx(RefreshCw,{className:"h-3 w-3"}),"retry"]})]})]});let q=l?.solana,H=l?.stripe,j=T||B==="stripe";return jsxs("div",{className:f("space-y-4",r),style:n,children:[jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[jsxs("div",{children:[jsx("h3",{className:"text-base font-semibold text-foreground",children:"Earnings Account"}),jsx("p",{className:"text-sm text-muted-foreground",children:"Connect a destination so you can be paid for filings."})]}),B&&jsxs("button",{type:"button",onClick:V,disabled:d,className:"inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-red-500 transition-colors disabled:opacity-50",children:[jsx(X,{className:"h-3 w-3"}),d?"disconnecting\u2026":"disconnect"]})]}),j&&jsxs("div",{className:"flex gap-2",children:[jsx(Nr,{active:N==="solana",onClick:()=>z("solana"),icon:jsx(Wallet,{className:"h-4 w-4"}),label:"Crypto (Solana)",sub:"Connect a wallet, sign once"}),jsx(Nr,{active:N==="stripe",onClick:()=>z("stripe"),icon:jsx(CreditCard,{className:"h-4 w-4"}),label:"Bank (Stripe)",sub:"Stripe-hosted onboarding"})]}),N==="solana"&&jsx("div",{className:"space-y-3 rounded-xl border border-border p-4",children:q?jsxs("div",{className:"space-y-2",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Connected wallet"}),jsx(Oe,{ok:true,label:"verified"})]}),jsx("code",{className:"block text-xs text-foreground break-all",children:q.address}),jsxs("p",{className:"text-xs text-muted-foreground",children:["You signed a server-issued nonce on ",new Date(q.verifiedAt).toLocaleString(),"."]})]}):jsxs(Fragment,{children:[jsx("p",{className:"text-sm text-foreground",children:"Connect your Phantom wallet and sign a one-time message to prove you control the address. Filings paid in USDC will land here."}),k&&jsx("p",{className:"text-sm text-red-500",children:k}),jsxs("button",{type:"button",onClick:L,disabled:b,className:f("inline-flex items-center gap-2 rounded-md bg-foreground text-background px-4 py-2 text-sm font-semibold transition-colors","hover:bg-foreground/90 disabled:opacity-50 disabled:cursor-not-allowed"),children:[jsx(Wallet,{className:"h-4 w-4"}),b?"Waiting for signature\u2026":"Connect Phantom & sign"]})]})}),N==="stripe"&&jsx("div",{className:"space-y-3 rounded-xl border border-border p-4",children:H?jsxs("div",{className:"space-y-3",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Stripe account"}),jsx("code",{className:"text-xs text-foreground",children:H.accountIdMasked})]}),jsxs("div",{className:"flex flex-wrap gap-2",children:[jsx(Oe,{ok:H.detailsSubmitted,label:"details"}),jsx(Oe,{ok:H.chargesEnabled,label:"charges"}),jsx(Oe,{ok:H.payoutsEnabled,label:"payouts"})]}),H.pendingOnboardingUrl&&jsxs("a",{href:D(H.pendingOnboardingUrl),className:"inline-flex items-center gap-1 text-sm text-foreground underline-offset-4 hover:underline",children:[jsx(ExternalLink,{className:"h-3.5 w-3.5"}),"Finish Stripe onboarding"]})]}):jsxs(Fragment,{children:[jsx("p",{className:"text-sm text-foreground",children:"We'll create a Stripe Express account under this stack's platform credentials and hand you off to Stripe to enter your bank details. Filings paid in USD will land in your bank."}),g&&jsx("p",{className:"text-sm text-red-500",children:g}),jsxs("button",{type:"button",onClick:M,disabled:m,className:f("inline-flex items-center gap-2 rounded-md bg-foreground text-background px-4 py-2 text-sm font-semibold transition-colors","hover:bg-foreground/90 disabled:opacity-50 disabled:cursor-not-allowed"),children:[jsx(CreditCard,{className:"h-4 w-4"}),m?"Opening Stripe\u2026":"Connect with Stripe"]})]})})]})}
2
+ export{$e as ASCII_KEY_ART,Be as BottomSheet,Hs as BuyKeyWidget,bt as BuyPanel,Nt as DefaultKeyArt,xo as FilePaperworkList,St as FilePaperworkView,Ct as FilingDetailView,wt as FilingTracker,oe as KeyBalanceBar,Et as KeyCard,Rt as KeyDetailView,no as KeyList,ze as KeyUtilsProvider,Tt as KeysPanel,Sr as MAX_ERROR_LEN,xt as MintSuccess,To as PayoutAccountPanel,ko as PayoutMethodPicker,Ys as SellPanel,gt as SolanaPayButton,He as TRACKER_LABELS,Se as TRACKER_VERBS,co as TransferPanel,Pt as TypingText,ht as UsePanel,_t as calculateBalancePercentage,Bt as clampErrorMessage,f as cn,Hr as createKeyClient,O as csrfHeaders,Ft as currentState,Ve as deriveTrackerStates,$t as detectPlatform,ee as formatDate,Ae as formatPaperUsd,F as formatTokens,Dt as getBalanceColor,Mt as hasFailed,At as isAllDone,We as pickHeadline,C as readErrorMessage,D as safeUrl,mt as useCryptoConnect,st as useFilePaperwork,ct as useFilingDetail,an as useFilingHistory,Re as useKeyLedger,h as useKeyUtilsContext,te as useKeys,Te as useListKey,Ze as useMintKey,Ue as usePayoutAccount,qe as usePricing,Xr as useSolanaPayment,it as useStackPayoutCapabilities,tt as useStripeCheckout,ut as useStripeConnect,Ie as useTransferKey,vn as useUserStripeStacks};