@stacknet/keyutils 0.4.6 → 0.4.7

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-[3px]",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",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))})}
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-[3px]",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
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacknet/keyutils",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "Reusable components for buying and managing StackNet node keys",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",