@stacknet/keyutils 0.4.1 → 0.4.3

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.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),yr=require('react'),jsxRuntime=require('react/jsx-runtime'),lucideReact=require('lucide-react');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var yr__default=/*#__PURE__*/_interopDefault(yr);function G(){if(typeof document>"u")return {};let e=document.cookie.match(/(?:^|;\s*)__csrf=([^;]*)/);return e?{"x-csrf-token":e[1]}:{}}var Et=500;function rt(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 rt(r.error,t)}catch{}return t}function A(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 tailwindMerge.twMerge(clsx.clsx(e))}function R(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 st(e,t){return t<=0?0:Math.min(100,Math.round(e/t*100))}function nt(e){return e>=70?"bg-green-500":e>=30?"bg-yellow-500":"bg-red-500"}function J(e){let t=typeof e=="string"&&/^\d+$/.test(e)?Number(e):e,r=new Date(t);return isNaN(r.getTime())?String(e):r.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function ot(){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 at=yr.createContext(null);function h(){let e=yr.useContext(at);if(!e)throw new Error("useKeyUtilsContext must be used within a KeyUtilsProvider");return e}function Re({config:e,callbacks:t={},children:r}){typeof e.apiBaseUrl!="string"&&console.error("[KeyUtils] apiBaseUrl must be a string");let s=yr.useMemo(()=>({config:e,callbacks:t}),[e,t]);return jsxRuntime.jsx(at.Provider,{value:s,children:r})}function Ie(){let{config:e}=h(),[t,r]=yr.useState(null),[s,d]=yr.useState(true),[c,a]=yr.useState(null),o=yr.useRef(true),n=yr.useRef(e.apiBaseUrl);n.current=e.apiBaseUrl;let i=async()=>{try{o.current&&(d(!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 u=await l.json();o.current&&r(u);}catch(l){o.current&&a(l instanceof Error?l.message:"Failed to fetch pricing");}finally{o.current&&d(false);}};return yr.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 Vt(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]=yr.useState([]),[s,d]=yr.useState(true),[c,a]=yr.useState(null),o=yr.useRef(true),n=e.apiBaseUrl,i=yr.useCallback(async()=>{try{d(!0),a(null);let u=await fetch(`${n}/api/keys`,{credentials:"include"});if(!u.ok)throw new Error(await U(u,`Failed to fetch keys (${u.status})`));let p=await u.json(),m=Array.isArray(p)?p:p.keys??[];o.current&&r(m.map(Vt));}catch(u){o.current&&a(u instanceof Error?u.message:"Failed to fetch keys");}finally{o.current&&d(false);}},[n]);yr.useEffect(()=>(o.current=true,i(),()=>{o.current=false;}),[i]);let l=t.reduce((u,p)=>u+p.tokenBalance,0);return {keys:t,totalBalance:l,loading:s,error:c,refresh:i}}function ge(e){let{config:t}=h(),[r,s]=yr.useState([]),[d,c]=yr.useState(false),[a,o]=yr.useState(null),n=yr.useRef(true),i=t.apiBaseUrl,l=yr.useCallback(async()=>{if(e)try{c(!0),o(null);let u=await fetch(`${i}/api/keys/${encodeURIComponent(e)}/ledger`,{credentials:"include"});if(!u.ok)throw new Error(await U(u,`Failed to fetch ledger (${u.status})`));let p=await u.json();n.current&&s(Array.isArray(p)?p:p.entries??[]);}catch(u){n.current&&o(u instanceof Error?u.message:"Failed to fetch ledger");}finally{n.current&&c(false);}},[i,e]);return yr.useEffect(()=>(n.current=true,l(),()=>{n.current=false;}),[l]),{entries:r,loading:d,error:a,refresh:l}}function Le(){let{config:e,callbacks:t}=h(),[r,s]=yr.useState(false),[d,c]=yr.useState(null),[a,o]=yr.useState(null);return {mint:yr.useCallback(async(i,l,u=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:u,stackId:e.stackId})});if(!p.ok)throw new Error(await U(p,`Key generation failed (${p.status})`));let m=await p.json(),x=m.keys?.[0]||m,b={success:!0,key:{id:x.keyId||x.id||"",key:x.key||"",userId:x.userId||"",status:"active",tokenBalance:x.tokenBalance??x.currentTokenBalance??0,maxTokens:x.initialTokenBalance??x.tokenBalance??0,createdAt:String(x.createdAt||Date.now())},transactionId:l};return c(b),t.onMintSuccess?.(b),b}catch(p){let m=p instanceof Error?p:new Error("Key generation failed");return o(m.message),t.onMintError?.(m),{success:false,error:m.message}}finally{s(false);}},[e.apiBaseUrl,t]),minting:r,result:d,error:a}}function xe(){let{config:e,callbacks:t}=h(),[r,s]=yr.useState(false),[d,c]=yr.useState(null),[a,o]=yr.useState(null),n=yr.useRef(true),i=yr.useCallback(async(u,p)=>{try{s(!0),o(null);let m=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/list`,{method:"POST",headers:{"Content-Type":"application/json",...G()},credentials:"include",body:JSON.stringify({askPriceCents:p,stackId:e.stackId,stackName:e.stackName})});if(!m.ok)throw new Error(await U(m,`Listing failed (${m.status})`));let x=await m.json();return n.current&&(c(x),t.onListingCreated?.(x)),x}catch(m){let x=m instanceof Error?m.message:"Listing failed";return n.current&&o(x),null}finally{n.current&&s(false);}},[e.apiBaseUrl,e.stackId,e.stackName,t]),l=yr.useCallback(async u=>{try{s(!0),o(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/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 m=p instanceof Error?p.message:"Delist failed";return n.current&&o(m),false}finally{n.current&&s(false);}},[e.apiBaseUrl]);return {listKey:i,delistKey:l,listing:r,result:d,error:a}}function Fe(){let{config:e}=h(),[t,r]=yr.useState(false),[s,d]=yr.useState(null),c=yr.useRef(true);return {createSession:yr.useCallback(async(o,n)=>{try{r(!0),d(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 u;try{u=new URL(l);}catch{throw new Error("Invalid checkout URL")}if(u.protocol!=="https:"||!/(^|\.)stripe\.com$/.test(u.hostname))throw new Error("Refusing to redirect to non-Stripe URL");try{sessionStorage.setItem("keyutils_stripe_pending","1"),sessionStorage.setItem("keyutils_stripe_quantity",String(n));}catch{}window.location.href=u.toString();}catch(i){if(c.current){let l=i instanceof Error?i.message:"Checkout failed";d(l),r(false);}}},[e.apiBaseUrl,e.stackId]),loading:t,error:s}}var ut=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function er(){let{config:e}=h(),[t,r]=yr.useState(false),[s,d]=yr.useState(null);return {pay:yr.useCallback(async a=>{if(!e.merchantWallet||!ut.test(e.merchantWallet))throw new Error("Merchant wallet not configured");try{r(!0),d(null);let{Connection:o,PublicKey:n,Transaction:i,SystemProgram:l}=await import('@solana/web3.js'),u=typeof window<"u"?window.solana:void 0;if(!u||typeof u!="object"||!u.isPhantom)throw new Error("Phantom wallet not found. Please install Phantom.");let p=u,m=new n(e.merchantWallet),x=await p.connect(),b=new n(x.publicKey.toString()),T="https://api.mainnet-beta.solana.com",w=A(e.solanaRpcUrl,T),L=w==="#"?T:w,_=new o(L),{blockhash:P}=await _.getLatestBlockhash(),z=BigInt(Math.floor(a*1e9)),E=e.protocolTreasuryWallet,F=e.protocolFeeBps??500,Y=new i({recentBlockhash:P,feePayer:b});if(E&&ut.test(E)&&F>0){let ue=z*BigInt(F)/10000n,D=z-ue,X=new n(E);Y.add(l.transfer({fromPubkey:b,toPubkey:m,lamports:Number(D)}),l.transfer({fromPubkey:b,toPubkey:X,lamports:Number(ue)}));}else Y.add(l.transfer({fromPubkey:b,toPubkey:m,lamports:Number(z)}));let{signature:ne}=await p.signAndSendTransaction(Y);return ne}catch(o){let n=o instanceof Error?o:new Error("SOL payment failed");throw d(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]=yr.useState(false),[d,c]=yr.useState(null),[a,o]=yr.useState(null),n=yr.useRef(true);return {transferKey:yr.useCallback(async(l,u)=>{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:u})});if(!p.ok)throw new Error(await U(p,`Transfer failed (${p.status})`));let m=await p.json();return n.current&&(c(m),t.onTransferComplete?.(m)),m}catch(p){let m=p instanceof Error?p.message:"Transfer failed";return n.current&&o(m),null}finally{n.current&&s(false);}},[e.apiBaseUrl,t]),transferring:r,result:d,error:a}}function _e(){let{config:e,callbacks:t}=h(),[r,s]=yr.useState(false),[d,c]=yr.useState(null),[a,o]=yr.useState(null),n=yr.useRef(true),i=yr.useCallback(async u=>{try{s(!0),o(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/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 m=await p.json();return n.current&&(c(m),t.onFilingComplete?.(m)),m}catch(p){let m=p instanceof Error?p:new Error("Filing failed");return n.current&&o(m.message),t.onFilingError?.(m),null}finally{n.current&&s(false);}},[e.apiBaseUrl,e.stackId,t]),l=yr.useCallback(()=>{c(null),o(null);},[]);return {filePaperwork:i,filing:r,result:d,error:a,reset:l}}function ir(){let{config:e}=h(),[t,r]=yr.useState([]),[s,d]=yr.useState(true),[c,a]=yr.useState(null),o=yr.useRef(true),n=e.apiBaseUrl,i=yr.useCallback(async()=>{try{d(!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 u=await l.json(),p=Array.isArray(u)?u:u.filings??[];o.current&&r(p);}catch(l){o.current&&a(l instanceof Error?l.message:"Failed to fetch filings");}finally{o.current&&d(false);}},[n]);return yr.useEffect(()=>(o.current=true,i(),()=>{o.current=false;}),[i]),{entries:t,loading:s,error:c,refresh:i}}var pt=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function We({amountSol:e,onSuccess:t,onError:r,disabled:s,className:d,style:c}){let{config:a}=h(),[o,n]=yr.useState(false),[i,l]=yr.useState(null),u=!!(a.merchantWallet&&pt.test(a.merchantWallet)),p=yr.useCallback(async()=>{if(u)try{n(!0),l(null);let{Connection:m,PublicKey:x,Transaction:b,SystemProgram:T,LAMPORTS_PER_SOL:w}=await import('@solana/web3.js'),L=typeof window<"u"?window.solana:void 0;if(!L||typeof L!="object"||!L.isPhantom)throw new Error("Phantom wallet not found. Please install Phantom.");let _=L,P;try{P=new x(a.merchantWallet);}catch{throw new Error("Invalid merchant wallet address.")}let z=await _.connect(),E=new x(z.publicKey.toString()),F="https://api.mainnet-beta.solana.com",Y=A(a.solanaRpcUrl,F),ne=Y==="#"?F:Y,ue=new m(ne),{blockhash:D}=await ue.getLatestBlockhash(),X=BigInt(Math.floor(e*1e9)),me=a.protocolTreasuryWallet,pe=a.protocolFeeBps??500,fe=new b({recentBlockhash:D,feePayer:E});if(me&&pt.test(me)&&pe>0){let tt=X*BigInt(pe)/10000n,Bt=X-tt,Lt=new x(me);fe.add(T.transfer({fromPubkey:E,toPubkey:P,lamports:Number(Bt)}),T.transfer({fromPubkey:E,toPubkey:Lt,lamports:Number(tt)}));}else fe.add(T.transfer({fromPubkey:E,toPubkey:P,lamports:Number(X)}));let{signature:he}=await _.signAndSendTransaction(fe);t(he);}catch(m){let x=m instanceof Error?m:new Error("Payment failed");l(x.message),r?.(x);}finally{n(false);}},[e,a.merchantWallet,u,t,r]);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("button",{onClick:p,disabled:s||o||!u,"aria-label":`Pay ${e.toFixed(4)} SOL`,className:f("flex w-full items-center justify-center gap-2 rounded-lg bg-purple-600 px-4 py-6 font-medium text-white transition-colors hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed",d),style:c,children:o?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader2,{className:"h-4 w-4 animate-spin"}),"Processing..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Pay ",e.toFixed(4)," SOL"]})}),i&&jsxRuntime.jsx("p",{className:"mt-2 text-center text-xs text-red-500",children:i})]})}function Oe({result:e,className:t,style:r}){let[s,d]=yr.useState(false),c=yr.useRef(null);yr.useEffect(()=>()=>{c.current&&clearTimeout(c.current);},[]);let a=yr.useCallback(()=>{e.key?.key&&(navigator.clipboard.writeText(e.key.key),d(true),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>d(false),2e3));},[e.key?.key]);return !e.success||!e.key?null:jsxRuntime.jsxs("div",{className:f("rounded-lg border border-green-500/20 bg-green-500/10 p-6 text-center",t),style:r,children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"mx-auto mb-3 h-12 w-12 text-green-500"}),jsxRuntime.jsx("h3",{className:"mb-2 text-lg font-semibold text-foreground",children:"Key Generated!"}),jsxRuntime.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Your node key has been successfully generated."}),jsxRuntime.jsxs("div",{className:"mx-auto flex max-w-md items-center gap-2 rounded-md border bg-background p-3",children:[jsxRuntime.jsx("code",{className:"flex-1 truncate text-xs text-foreground",children:e.key.key}),jsxRuntime.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?jsxRuntime.jsx(lucideReact.Check,{className:"h-4 w-4 text-green-500"}):jsxRuntime.jsx(lucideReact.Copy,{className:"h-4 w-4"})})]})]})}function te({className:e}){return jsxRuntime.jsx("div",{className:f("animate-pulse rounded-xl bg-muted",e)})}function He(){return jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"px-6 py-10 flex flex-col items-center gap-3",children:[jsxRuntime.jsx(te,{className:"h-14 w-48"}),jsxRuntime.jsx(te,{className:"h-5 w-64"})]}),jsxRuntime.jsx(te,{className:"h-[72px] w-full rounded-2xl"}),jsxRuntime.jsx(te,{className:"h-[68px] w-full rounded-2xl"}),jsxRuntime.jsx(te,{className:"h-[60px] w-full rounded-2xl"})]})}function oe({count:e=3}){return jsxRuntime.jsx("div",{className:"space-y-3",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsxs("div",{className:"rounded-xl border p-4 space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(te,{className:"h-4 w-32"}),jsxRuntime.jsx(te,{className:"h-4 w-16"})]}),jsxRuntime.jsx(te,{className:"h-2 w-full rounded-full"}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(te,{className:"h-3 w-24"}),jsxRuntime.jsx(te,{className:"h-3 w-20"})]})]},r))})}function Cr({quantity:e,max:t,onChange:r}){return jsxRuntime.jsxs("div",{className:"flex items-center justify-between rounded-2xl bg-muted/20 px-6 py-6",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-foreground",children:"Quantity"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-0 rounded-xl bg-background",children:[jsxRuntime.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:jsxRuntime.jsx(lucideReact.Minus,{className:"h-5 w-5"})}),jsxRuntime.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}),jsxRuntime.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:jsxRuntime.jsx(lucideReact.Plus,{className:"h-5 w-5"})})]})]})}function bt({pricing:e,quantity:t}){let[r,s]=yr.useState(false),d=e.priceUsd*t;return jsxRuntime.jsxs("div",{className:"rounded-2xl border bg-background",children:[jsxRuntime.jsxs("button",{onClick:()=>s(!r),"aria-expanded":r,className:"flex w-full items-center justify-between px-6 py-6 text-left",children:[jsxRuntime.jsxs("span",{className:"text-foreground",children:[jsxRuntime.jsxs("span",{className:"text-xl font-bold",children:["$",d.toFixed(2)]})," ",jsxRuntime.jsx("span",{className:"text-sm text-muted-foreground",children:"total fees included"})]}),r?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"h-5 w-5 text-muted-foreground"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-5 w-5 text-muted-foreground"})]}),r&&jsxRuntime.jsxs("div",{className:"border-t px-6 pb-8 pt-4 space-y-3 text-sm",children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsxs("span",{className:"text-muted-foreground",children:["Node Key \xD7 ",t]}),jsxRuntime.jsxs("span",{className:"text-foreground",children:["$",(e.priceUsd*t).toFixed(2)]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Keys sold"}),jsxRuntime.jsx("span",{className:"text-foreground",children:e.keysSold})]}),e.daysUntilHalving>0&&jsxRuntime.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[jsxRuntime.jsx("span",{children:"Next refresh"}),jsxRuntime.jsxs("span",{children:[e.daysUntilHalving," day",e.daysUntilHalving!==1?"s":""]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between border-t pt-3 font-semibold",children:[jsxRuntime.jsx("span",{className:"text-foreground",children:"Total"}),jsxRuntime.jsxs("span",{className:"text-foreground",children:["$",d.toFixed(2)]})]})]})]})}function Ve({className:e,style:t}){let{config:r}=h(),{pricing:s,loading:d,error:c,refresh:a}=Ie(),{mint:o,minting:n,result:i,error:l}=Le(),{createSession:u,loading:p,error:m}=Fe(),[x,b]=yr.useState(1),[T,w]=yr.useState(r.paymentMethods?.includes("stripe")?"stripe":"solana"),[L,_]=yr.useState(0),[P,z]=yr.useState(false),E=yr__default.default.useRef(x);E.current=x;let F=Math.max(1,r.maxQuantity||5),Y=[...r.paymentMethods||["solana"]].sort((D,X)=>D==="stripe"?-1:X==="stripe"?1:0);if(yr.useEffect(()=>{if(typeof window>"u")return;let X=new URLSearchParams(window.location.search).get("session_id");if(!X){try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}return}if(/^cs_(test|live)_/.test(X)&&!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",X,fe);}},[P,i,o]),i?.success)return jsxRuntime.jsx("div",{className:f("flex flex-col items-center justify-center",e),style:t,children:jsxRuntime.jsx(Oe,{result:i})});if(P||n)return jsxRuntime.jsx("div",{className:f("flex flex-col",e),style:t,children:jsxRuntime.jsx(He,{})});if(d)return jsxRuntime.jsx("div",{className:f("flex flex-col",e),style:t,children:jsxRuntime.jsx(He,{})});if(c||!s)return jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-24",e),style:t,children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load pricing"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c||"Please check your connection and try again."})]}),jsxRuntime.jsx("button",{onClick:()=>a(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]});let ne=async D=>{_(2),await o(T,D,x);},ue=()=>{u(s.priceCents,x);};return jsxRuntime.jsx("div",{className:f("flex flex-col",e),style:t,children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[L===0&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[r.keyImage&&jsxRuntime.jsx("img",{src:A(r.keyImage),alt:"Node Key",className:r.keyImageClass||"w-1/2 mx-auto"}),jsxRuntime.jsxs("div",{className:"px-6 py-10 text-center",children:[jsxRuntime.jsxs("p",{className:"text-5xl font-bold tracking-tight text-foreground md:text-6xl",children:["$",s.priceUsd.toFixed(2)]}),jsxRuntime.jsxs("p",{className:"mt-2 text-base text-muted-foreground",children:["per key \xB7 ",s.tokenAllocationFormatted||R(s.tokenAllocation)," tokens included"]})]}),jsxRuntime.jsx(Cr,{quantity:x,max:F,onChange:b}),jsxRuntime.jsx(bt,{pricing:s,quantity:x}),jsxRuntime.jsx("button",{onClick:()=>_(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"})]}),L===1&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[Y.length>1&&jsxRuntime.jsx("div",{role:"tablist",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:Y.map(D=>jsxRuntime.jsxs("button",{role:"tab","aria-selected":T===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",T===D?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[D==="stripe"?jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-5 w-5"}):jsxRuntime.jsx(lucideReact.Wallet,{className:"h-5 w-5"}),D==="stripe"?"Credit Card":"Crypto"]},D))}),jsxRuntime.jsx(bt,{pricing:s,quantity:x}),T==="stripe"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.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?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin"}),"Redirecting to Stripe..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-5 w-5"}),"Pay with Card"]})}),m&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-500",children:m})]}):T==="solana"?jsxRuntime.jsx(We,{amountSol:s.priceSol??0,onSuccess:ne,className:"rounded-2xl py-5 text-base"}):null,l&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-500",children:l}),jsxRuntime.jsx("button",{onClick:()=>_(0),className:"w-full py-3 text-center text-sm text-muted-foreground hover:text-foreground transition-colors",children:"\u2190 Back"})]})]})})}var Ir={ios:"iOS",android:"Android",windows:"Windows",mac:"macOS",linux:"Linux"},Tr=["mac","windows","linux","ios","android"];function qe({downloads:e,className:t,style:r}){let{config:s}=h(),d=yr.useMemo(()=>ot(),[]),c=e||Tr.map(n=>({platform:n,label:Ir[n],url:"#",compatible:n===d})),a=c.find(n=>n.compatible)||c[0],o=c.filter(n=>n.platform!==a.platform);return jsxRuntime.jsxs("div",{className:f("space-y-8",t),style:r,children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-6 pt-4 mt-4",children:[s.aispImage&&jsxRuntime.jsx("img",{src:A(s.aispImage),alt:"aiSP",className:"w-full sm:w-1/2 mx-auto px-4 sm:px-0"}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("p",{className:"text-lg sm:text-2xl font-medium text-foreground",children:"Download the AI Service Provider App"}),jsxRuntime.jsx("p",{className:"mt-1 text-sm sm:text-base text-muted-foreground",children:"Load your keys and run your node."})]}),jsxRuntime.jsxs("a",{href:A(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:[jsxRuntime.jsx(lucideReact.Download,{className:"h-5 w-5"}),"Get aiSP for ",a.label]})]}),jsxRuntime.jsxs("p",{className:"text-center text-sm text-muted-foreground",children:["aiSP is also available on"," ",o.map((n,i)=>jsxRuntime.jsxs(yr__default.default.Fragment,{children:[i>0&&(i===o.length-1?" and ":", "),jsxRuntime.jsx("a",{href:A(n.url),target:"_blank",rel:"noopener noreferrer",className:"font-medium underline transition-colors hover:text-foreground",style:{color:"#066bff"},children:n.label})]},n.platform)),"."]}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-2 mt-12",children:[jsxRuntime.jsxs("p",{className:"text-center text-xs text-muted-foreground flex justify-center gap-0.5 flex-wrap",children:["Source code is available on",jsxRuntime.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"})]}),jsxRuntime.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",jsxRuntime.jsx("a",{href:A(s.termsUrl,"/terms"),target:"_blank",rel:"noopener noreferrer",className:"text-foreground underline hover:text-foreground/80",children:"Open Source Applications Terms"})]})]})]})}function Z({current:e,max:t,className:r,style:s,showLabel:d=true}){let c=st(e,t),a=nt(c);return jsxRuntime.jsxs("div",{className:f("w-full",r),style:s,children:[d&&jsxRuntime.jsxs("div",{className:"mb-1 flex items-center justify-between text-xs text-muted-foreground",children:[jsxRuntime.jsxs("span",{children:[R(e)," / ",R(t)]}),jsxRuntime.jsxs("span",{children:[c,"%"]})]}),jsxRuntime.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-muted",children:jsxRuntime.jsx("div",{className:f("h-full rounded-full transition-all duration-500",a),style:{width:`${c}%`}})})]})}function ve({open:e,onClose:t,title:r,children:s}){let d=yr.useRef(null),[c,a]=yr.useState(false),[o,n]=yr.useState(false),i=yr.useCallback(l=>{l.key==="Escape"&&t();},[t]);return yr.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?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",children:[jsxRuntime.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm transition-opacity duration-300",style:{opacity:o?1:0},onClick:t}),jsxRuntime.jsxs("div",{ref:d,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:[jsxRuntime.jsx("div",{className:"flex justify-center pt-3 pb-1",children:jsxRuntime.jsx("div",{className:"h-1 w-10 rounded-full bg-muted-foreground/30"})}),r&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-5 pb-3 pt-1",children:[jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:r}),jsxRuntime.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:jsxRuntime.jsx(lucideReact.X,{className:"h-5 w-5"})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto px-5 pb-8",children:s})]})]}):null}function Ar({nodeKey:e,onSuccess:t}){let{transferKey:r,transferring:s,result:d,error:c}=ye(),[a,o]=yr.useState(""),[n,i]=yr.useState(false),l=a.trim()===e.userId,u=a.trim().length>0&&n&&!l&&!s,p=async()=>{if(!u)return;await r(e.id,a.trim())&&t();};return d?jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Transfer Complete"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Key transferred successfully"})]}):jsxRuntime.jsxs("div",{className:"space-y-5",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"mb-1.5 block text-sm font-semibold text-foreground",children:"Recipient User ID"}),jsxRuntime.jsx("input",{type:"text",value:a,onChange:m=>{o(m.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&&jsxRuntime.jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),a.trim().length>0&&!l&&jsxRuntime.jsx("div",{className:"rounded-xl border border-amber-500/30 bg-amber-500/5 p-4",children:jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.jsx(lucideReact.AlertTriangle,{className:"mt-0.5 h-5 w-5 shrink-0 text-amber-500"}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Confirm Transfer"}),jsxRuntime.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Transferring key"," ",jsxRuntime.jsx("span",{className:"font-mono font-medium",children:e.keyIndex?`#${e.keyIndex}`:e.id.slice(0,12)})," ","(",R(e.tokenBalance)," tokens) to"," ",jsxRuntime.jsxs("span",{className:"font-mono font-medium",children:[a.trim().slice(0,20),a.trim().length>20?"...":""]})]})]}),jsxRuntime.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:n,onChange:m=>i(m.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border"}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"I confirm this transfer is permanent and cannot be undone."})]})]})]})}),c&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:c}),jsxRuntime.jsx("button",{onClick:p,disabled:!u,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",u?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:s?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Transferring..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Send,{className:"h-4 w-4"}),"Transfer Key"]})})]})}function $r({nodeKey:e,onSuccess:t}){let{config:r}=h(),{listKey:s,listing:d,result:c,error:a}=xe(),[o,n]=yr.useState(""),[i,l]=yr.useState(false),u=parseInt(o.replace(/[^0-9]/g,""),10)||0,m=u>0&&Number.isFinite(u)&&i&&!d,x=async()=>{if(!m)return;let b=u*100;await s(e.id,b)&&t();};return c?jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Key Listed!"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Your key is now on the marketplace."}),jsxRuntime.jsxs("p",{className:"text-xs text-muted-foreground",children:["Listing ID: ",jsxRuntime.jsx("code",{children:c.listingId})]})]}):jsxRuntime.jsxs("div",{className:"space-y-5",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{htmlFor:"listing-price",className:"mb-2 block text-sm font-semibold text-foreground",children:"Listing Price (USD)"}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-2xl font-bold text-muted-foreground",children:"$"}),jsxRuntime.jsx("input",{id:"listing-price",type:"text",inputMode:"numeric",value:o,onChange:b=>{let T=b.target.value.replace(/[^0-9]/g,""),w=parseInt(T,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"})]})]}),jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.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&&jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 text-background"})}),jsxRuntime.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."," ",jsxRuntime.jsx("a",{href:A(r.termsUrl,"/terms"),className:"text-foreground underline",target:"_blank",rel:"noopener noreferrer",children:"Terms"})]})]}),a&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:a}),jsxRuntime.jsxs("button",{onClick:x,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:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),d?"Listing...":"List on Marketplace"]})]})}function Dr({nodeKey:e}){let[t,r]=yr.useState(false);if(!e.paperWork)return jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-3 py-12",children:[jsxRuntime.jsx(lucideReact.FileText,{className:"h-10 w-10 text-muted-foreground"}),jsxRuntime.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 jsxRuntime.jsxs("div",{className:"space-y-5",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"mb-2 block text-sm font-semibold text-foreground",children:"Paperwork"}),jsxRuntime.jsxs("div",{className:"relative rounded-xl border bg-muted/30 p-4",children:[jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap break-all text-sm text-foreground font-mono",children:e.paperWork}),jsxRuntime.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?jsxRuntime.jsx(lucideReact.Check,{className:"h-4 w-4 text-green-500"}):jsxRuntime.jsx(lucideReact.Copy,{className:"h-4 w-4"})})]})]}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Filing paperwork submits the key's documentation on-chain for permanent record."}),jsxRuntime.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:[jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4"}),"File Paperwork (Coming Soon)"]})]})}function Ge({nodeKey:e,onBack:t,onKeysChanged:r,className:s,style:d}){let{config:c}=h(),{entries:a,loading:o}=ge(e.id),[n,i]=yr.useState(null),[l,u]=yr.useState(false),p=()=>{i(null),r?.();},m=()=>{e.key&&(navigator.clipboard.writeText(e.key),u(true),setTimeout(()=>u(false),2e3));},x=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsxRuntime.jsxs("div",{className:f("space-y-5",s),style:d,children:[jsxRuntime.jsxs("button",{onClick:t,className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors",children:[jsxRuntime.jsx(lucideReact.ArrowLeft,{className:"h-4 w-4"}),"Back to Keys"]}),jsxRuntime.jsx("div",{className:"space-y-1",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("h2",{className:"text-2xl font-bold text-foreground",children:e.keyIndex?`Key #${e.keyIndex}`:e.label||e.id.slice(0,16)}),jsxRuntime.jsx("span",{className:f("text-sm font-medium capitalize",x),children:e.status})]})}),e.key&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("code",{className:"flex-1 truncate rounded-lg bg-muted px-3 py-2 text-xs text-muted-foreground",children:e.key}),jsxRuntime.jsx("button",{onClick:m,"aria-label":"Copy key",className:"shrink-0 rounded-lg p-2 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",children:l?jsxRuntime.jsx(lucideReact.Check,{className:"h-4 w-4 text-green-500"}):jsxRuntime.jsx(lucideReact.Copy,{className:"h-4 w-4"})})]}),jsxRuntime.jsx(Z,{current:e.tokenBalance,max:e.maxTokens,showLabel:true}),jsxRuntime.jsxs("div",{className:"rounded-xl bg-muted/30 p-5 space-y-2.5 text-sm",children:[e.keyIndex&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key #"}),jsxRuntime.jsxs("span",{className:"text-foreground font-semibold",children:["#",e.keyIndex]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key ID"}),jsxRuntime.jsx("code",{className:"text-xs text-foreground",children:e.id})]}),(c.stackName||e.stackName)&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Stack"}),jsxRuntime.jsx("span",{className:"text-foreground",children:e.stackName||c.stackName})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Tokens"}),jsxRuntime.jsxs("span",{className:"text-foreground",children:[R(e.tokenBalance)," / ",R(e.maxTokens)]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Created"}),jsxRuntime.jsx("span",{className:"text-foreground",children:J(e.createdAt)})]}),e.expiresAt&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Expires"}),jsxRuntime.jsx("span",{className:"text-foreground",children:J(e.expiresAt)})]})]}),e.paperWork&&jsxRuntime.jsxs("div",{className:"rounded-xl border bg-muted/30 p-5",children:[jsxRuntime.jsx("h3",{className:"text-sm font-semibold text-foreground mb-2",children:"Paperwork"}),jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap break-all text-xs text-muted-foreground font-mono",children:e.paperWork})]}),e.status==="active"&&jsxRuntime.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[jsxRuntime.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"}),jsxRuntime.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"}),jsxRuntime.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"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-sm font-semibold text-foreground mb-3",children:"Ledger"}),o?jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading ledger..."}):a.length===0?jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"No ledger entries."}):jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[a.slice(0,20).map(b=>jsxRuntime.jsxs("div",{className:"flex items-center justify-between text-xs",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("span",{className:f("font-medium",b.type==="credit"||b.type==="reward"?"text-green-500":"text-red-500"),children:[b.type==="credit"||b.type==="reward"?"+":"-",R(Math.abs(b.amount))]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:b.description})]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:J(b.createdAt)})]},b.id)),a.length>20&&jsxRuntime.jsxs("p",{className:"pt-1 text-xs text-muted-foreground",children:["Showing 20 of ",a.length," entries"]})]})]}),jsxRuntime.jsx(ve,{open:n==="transfer",onClose:()=>i(null),title:"Transfer Key",children:jsxRuntime.jsx(Ar,{nodeKey:e,onSuccess:p})}),jsxRuntime.jsx(ve,{open:n==="sell",onClose:()=>i(null),title:"Sell Key",children:jsxRuntime.jsx($r,{nodeKey:e,onSuccess:p})}),jsxRuntime.jsx(ve,{open:n==="file",onClose:()=>i(null),title:"File Paperwork",children:jsxRuntime.jsx(Dr,{nodeKey:e})})]})}function Wr({nodeKey:e,onClick:t}){let r=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsxRuntime.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:jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:f("text-xs font-medium capitalize",r),children:e.status})]}),jsxRuntime.jsx(Z,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"}),e.paperWork&&jsxRuntime.jsx("span",{className:"mt-1.5 inline-block text-xs text-muted-foreground",children:"Has paperwork"})]})})}function Je({className:e,style:t}){let{keys:r,totalBalance:s,loading:d,error:c,refresh:a}=H(),[o,n]=yr.useState(null),[i,l]=yr.useState("active"),u=r.filter(x=>x.status===i),p=u.reduce((x,b)=>x+b.tokenBalance,0),m=r.find(x=>x.id===o);return m?jsxRuntime.jsx(Ge,{nodeKey:m,onBack:()=>n(null),onKeysChanged:()=>{n(null),a();},className:e,style:t}):d?jsxRuntime.jsxs("div",{className:f("space-y-4",e),style:t,children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx(oe,{count:3})]}):c?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-16",e),style:t,children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c})]}),jsxRuntime.jsx("button",{onClick:()=>a(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]}):r.length===0?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 rounded-xl border border-dashed py-16",e),style:t,children:[jsxRuntime.jsx(lucideReact.KeyRound,{className:"h-10 w-10 text-muted-foreground"}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys yet"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Get your first node key to start earning."})]})]}):jsxRuntime.jsxs("div",{className:f("space-y-4",e),style:t,children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mt-3",children:[jsxRuntime.jsx("h3",{className:"text-2xl font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsxs("span",{className:"text-xs text-muted-foreground",children:[u.length," key",u.length!==1?"s":""," \xB7 ",R(p)," tokens"]}),jsxRuntime.jsx("div",{className:"flex gap-1 rounded-lg bg-muted/50 p-1",children:["active","listed"].map(x=>jsxRuntime.jsx("button",{onClick:()=>l(x),className:f("rounded-md px-3 py-1 text-xs font-medium capitalize transition-all",i===x?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:x},x))})]}),u.length===0?jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-12",children:[jsxRuntime.jsx(lucideReact.KeyRound,{className:"h-8 w-8 text-muted-foreground"}),jsxRuntime.jsxs("p",{className:"text-sm text-muted-foreground",children:["No ",i," keys."]})]}):jsxRuntime.jsx("div",{className:"space-y-2",children:u.map(x=>jsxRuntime.jsx(Wr,{nodeKey:x,onClick:()=>n(x.id)},x.id))})]})}var Hr=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function Vr({active:e,onChange:t}){return jsxRuntime.jsx("div",{role:"tablist","aria-label":"Key actions",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:Hr.map(({id:r,label:s})=>jsxRuntime.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:jsxRuntime.jsx("span",{className:"inline",children:s})},r))})}function qr({defaultTab:e="buy",className:t,style:r}){let[s,d]=yr.useState(e);return jsxRuntime.jsxs("div",{className:f("flex flex-col",t),style:r,children:[jsxRuntime.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:jsxRuntime.jsx("div",{className:"mx-auto max-w-xl",children:jsxRuntime.jsx(Vr,{active:s,onChange:d})})}),jsxRuntime.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:jsxRuntime.jsx("div",{className:"mx-auto w-full max-w-xl flex-1",children:jsxRuntime.jsxs("div",{role:"tabpanel",id:`panel-${s}`,"aria-labelledby":`tab-${s}`,children:[s==="buy"&&jsxRuntime.jsx(Ve,{className:"flex-1"}),s==="use"&&jsxRuntime.jsx(qe,{className:"flex-1"}),s==="keys"&&jsxRuntime.jsx(Je,{className:"flex-1"})]})})})]})}function zr({apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:s,merchantWallet:d,stripePublicKey:c,theme:a,maxQuantity:o,keyImage:n,keyImageClass:i,aispImage:l,termsUrl:u,onMintSuccess:p,onMintError:m,onPaymentStart:x,onPaymentComplete:b,onListingCreated:T,onTransferComplete:w,defaultTab:L,className:_,style:P}){return jsxRuntime.jsx(Re,{config:{apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:s,merchantWallet:d,stripePublicKey:c,theme:a,maxQuantity:o,keyImage:n,keyImageClass:i,aispImage:l,termsUrl:u},callbacks:{onMintSuccess:p,onMintError:m,onPaymentStart:x,onPaymentComplete:b,onListingCreated:T,onTransferComplete:w},children:jsxRuntime.jsx(qr,{defaultTab:L,className:_,style:P})})}function Jr({nodeKey:e,selected:t,onSelect:r}){return jsxRuntime.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:[jsxRuntime.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&&jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 text-background"})}),jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:f("text-xs font-medium capitalize",e.status==="active"?"text-green-500":"text-muted-foreground"),children:e.status})]}),jsxRuntime.jsx(Z,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function Qr({className:e,style:t}){let{config:r}=h(),{keys:s,loading:d,error:c,refresh:a}=H(),{listKey:o,listing:n,result:i,error:l}=xe(),[u,p]=yr.useState(null),[m,x]=yr.useState(""),[b,T]=yr.useState(false),w=s.find(F=>F.id===u),L=parseInt(m.replace(/[^0-9]/g,""),10)||0,_=L>0&&Number.isFinite(L),P=!!w&&_&&b&&!n,z=async()=>{if(!P||!w)return;let F=L*100;await o(w.id,F)&&a();};if(i)return jsxRuntime.jsxs("div",{className:f("flex flex-col items-center gap-4 rounded-xl bg-green-500/10 py-12",e),style:t,children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Key Listed!"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Your key is now on the Global Open AI Network marketplace."}),jsxRuntime.jsxs("p",{className:"text-xs text-muted-foreground",children:["Listing ID: ",jsxRuntime.jsx("code",{children:i.listingId})]}),jsxRuntime.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:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),"View Listing"]})]});if(d)return jsxRuntime.jsxs("div",{className:f("space-y-5 px-1",e),style:t,children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx(oe,{count:2})]});if(c)return jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-16",e),style:t,children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c})]}),jsxRuntime.jsx("button",{onClick:()=>a(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]});let E=s.filter(F=>F.status==="active");return E.length===0?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16",e),style:t,children:[jsxRuntime.jsx(lucideReact.AlertTriangle,{className:"h-8 w-8 text-muted-foreground"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"No active keys to sell."})]}):jsxRuntime.jsxs("div",{className:f("space-y-5",e),style:t,children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx("div",{className:"space-y-2",children:E.map(F=>jsxRuntime.jsx(Jr,{nodeKey:F,selected:u===F.id,onSelect:()=>p(F.id)},F.id))})]}),w&&jsxRuntime.jsxs("div",{className:"rounded-xl border bg-muted/30 p-5 space-y-2 text-sm",children:[w.keyIndex&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key #"}),jsxRuntime.jsxs("span",{className:"text-foreground font-semibold",children:["#",w.keyIndex]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key ID"}),jsxRuntime.jsx("code",{className:"text-xs text-foreground",children:w.id})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Originating Stack"}),jsxRuntime.jsx("span",{className:"text-foreground",children:r.stackName||"Unknown"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Tokens (remaining / total)"}),jsxRuntime.jsxs("span",{className:"text-foreground",children:[R(w.tokenBalance)," / ",R(w.maxTokens)]})]}),w.paperWork&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Paper earned"}),jsxRuntime.jsx("span",{className:"text-foreground",children:w.paperWork})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Created"}),jsxRuntime.jsx("span",{className:"text-foreground",children:J(w.createdAt)})]})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{htmlFor:"listing-price",className:"mb-2 block text-sm sm:text-lg font-semibold text-foreground",children:"Listing Price (USD)"}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-2xl font-bold text-muted-foreground",children:"$"}),jsxRuntime.jsx("input",{id:"listing-price",type:"text",inputMode:"numeric",value:m,onChange:F=>{let Y=F.target.value.replace(/[^0-9]/g,""),ne=parseInt(Y,10);x(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"})]})]}),jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.jsx("button",{type:"button",role:"checkbox","aria-checked":b,onClick:()=>T(!b),className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",b?"border-foreground bg-foreground":"border-muted-foreground/40"),children:b&&jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 text-background"})}),jsxRuntime.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."," ",jsxRuntime.jsx("a",{href:A(r.termsUrl,"/terms"),className:"text-foreground underline",target:"_blank",rel:"noopener noreferrer",children:"Terms"})]})]}),l&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:l}),jsxRuntime.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:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),n?"Listing...":"List on Marketplace"]})]})}var Xe=20;function Ze({nodeKey:e,className:t,style:r}){let[s,d]=yr.useState(false),[c,a]=yr.useState(false),o=yr.useRef(null),{entries:n,loading:i}=ge(s?e.id:null);yr.useEffect(()=>()=>{o.current&&clearTimeout(o.current);},[]);let l=yr.useCallback(()=>{e.key&&(navigator.clipboard.writeText(e.key),a(true),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>a(false),2e3));},[e.key]),u=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500",p=n.slice(0,Xe);return jsxRuntime.jsxs("div",{className:f("rounded-lg border bg-background",t),style:r,children:[jsxRuntime.jsxs("div",{className:"p-4",children:[jsxRuntime.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("button",{onClick:()=>d(!s),"aria-expanded":s,"aria-label":s?"Collapse ledger":"Expand ledger",className:"text-muted-foreground hover:text-foreground",children:s?jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-4 w-4"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4"})}),jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]})]}),jsxRuntime.jsx("span",{className:f("text-xs font-medium capitalize",u),children:e.status})]}),e.key&&jsxRuntime.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[jsxRuntime.jsx("code",{className:"flex-1 truncate rounded bg-muted px-2 py-1 text-xs text-muted-foreground",children:e.key}),jsxRuntime.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?jsxRuntime.jsx(lucideReact.Check,{className:"h-3.5 w-3.5 text-green-500"}):jsxRuntime.jsx(lucideReact.Copy,{className:"h-3.5 w-3.5"})})]}),jsxRuntime.jsx(Z,{current:e.tokenBalance,max:e.maxTokens}),jsxRuntime.jsxs("div",{className:"mt-2 flex items-center justify-between text-xs text-muted-foreground",children:[jsxRuntime.jsxs("span",{children:["Created ",J(e.createdAt)]}),e.expiresAt&&jsxRuntime.jsxs("span",{children:["Expires ",J(e.expiresAt)]})]})]}),s&&jsxRuntime.jsxs("div",{className:"border-t px-4 py-3",children:[jsxRuntime.jsx("h4",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Ledger"}),i?jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading..."}):p.length===0?jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"No ledger entries."}):jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[p.map(m=>jsxRuntime.jsxs("div",{className:"flex items-center justify-between text-xs",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("span",{className:f("font-medium",m.type==="credit"||m.type==="reward"?"text-green-500":"text-red-500"),children:[m.type==="credit"||m.type==="reward"?"+":"-",R(Math.abs(m.amount))]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:m.description})]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:J(m.createdAt)})]},m.id)),n.length>Xe&&jsxRuntime.jsxs("p",{className:"pt-1 text-xs text-muted-foreground",children:["Showing ",Xe," of ",n.length," entries"]})]})]})]})}var as=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function Pe({baseHref:e}){return jsxRuntime.jsx("div",{className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5 mb-6",children:as.map(({id:t,label:r})=>jsxRuntime.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 is({getKeyHref:e="/keys/get",showTabs:t=true,className:r,style:s}){let{keys:d,totalBalance:c,loading:a,error:o,refresh:n}=H();return a?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:s,children:[t&&e&&jsxRuntime.jsx(Pe,{baseHref:e}),jsxRuntime.jsx(oe,{count:3})]}):o?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:s,children:[t&&e&&jsxRuntime.jsx(Pe,{baseHref:e}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 py-12",children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o})]}),jsxRuntime.jsx("button",{onClick:()=>n(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]})]}):d.length===0?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:s,children:[t&&e&&jsxRuntime.jsx(Pe,{baseHref:e}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 rounded-lg border border-dashed py-12",children:[jsxRuntime.jsx(lucideReact.KeyRound,{className:"h-10 w-10 text-muted-foreground"}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys yet"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Get your first node key to start earning."})]}),e&&jsxRuntime.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"})]})]}):jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:s,children:[t&&e&&jsxRuntime.jsx(Pe,{baseHref:e}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("p",{className:"text-sm text-muted-foreground",children:[d.length," key",d.length!==1?"s":""," \xB7 Total balance: ",R(c)]}),e&&jsxRuntime.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"})]}),d.map(i=>jsxRuntime.jsx(Ze,{nodeKey:i},i.id))]})}function ms({nodeKey:e,selected:t,onSelect:r}){return jsxRuntime.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:[jsxRuntime.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&&jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 text-background"})}),jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:"text-xs font-medium capitalize text-green-500",children:e.status})]}),jsxRuntime.jsx(Z,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function fs({className:e,style:t}){let{keys:r,loading:s}=H(),{transferKey:d,transferring:c,result:a,error:o}=ye(),[n,i]=yr.useState(null),[l,u]=yr.useState(""),[p,m]=yr.useState(false),x=r.filter(P=>P.status==="active"),b=x.find(P=>P.id===n),T=b&&l.trim()===b.userId,w=n&&l.trim().length>0&&p&&!T&&!c,L=async()=>{!n||!l.trim()||await d(n,l.trim());},_=()=>{i(null),u(""),m(false);};return a?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center gap-4 py-8",e),style:t,children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Transfer Complete"}),jsxRuntime.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Key transferred successfully"})]}),jsxRuntime.jsxs("div",{className:"w-full max-w-sm space-y-2 rounded-xl border border-border bg-muted/30 p-4 text-sm",children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key"}),jsxRuntime.jsxs("span",{className:"font-mono text-foreground",children:[a.keyId.slice(0,20),"..."]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Recipient"}),jsxRuntime.jsxs("span",{className:"font-mono text-foreground",children:[a.toUserId.slice(0,20),"..."]})]})]}),jsxRuntime.jsx("button",{onClick:_,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"})]}):jsxRuntime.jsxs("div",{className:f("space-y-5",e),style:t,children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"mb-3 text-sm font-medium text-foreground",children:"Select Key to Transfer"}),s?jsxRuntime.jsx(oe,{count:2}):x.length===0?jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"No active keys available for transfer."}):jsxRuntime.jsx("div",{className:"space-y-2",children:x.map(P=>jsxRuntime.jsx(ms,{nodeKey:P,selected:n===P.id,onSelect:()=>i(P.id)},P.id))})]}),n&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"mb-1.5 block text-sm font-medium text-foreground",children:"Recipient User ID"}),jsxRuntime.jsx("input",{type:"text",value:l,onChange:P=>{u(P.target.value),m(false);},placeholder:"Enter recipient's user ID or global ID",className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:border-foreground/30 focus:outline-none focus:ring-1 focus:ring-foreground/10"}),T&&jsxRuntime.jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),b&&l.trim().length>0&&!T&&jsxRuntime.jsx("div",{className:"rounded-xl border border-amber-500/30 bg-amber-500/5 p-4",children:jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.jsx(lucideReact.AlertTriangle,{className:"mt-0.5 h-5 w-5 shrink-0 text-amber-500"}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Confirm Transfer"}),jsxRuntime.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["You are about to transfer key"," ",jsxRuntime.jsx("span",{className:"font-mono font-medium",children:b.keyIndex?`#${b.keyIndex}`:b.id.slice(0,12)})," ","(",R(b.tokenBalance)," tokens) to"," ",jsxRuntime.jsxs("span",{className:"font-mono font-medium",children:[l.trim().slice(0,20),"..."]})]})]}),jsxRuntime.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:p,onChange:P=>m(P.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border"}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"I confirm this transfer is permanent and cannot be undone."})]})]})]})}),o&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:o}),jsxRuntime.jsx("button",{onClick:L,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?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Transferring..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Send,{className:"h-4 w-4"}),"Transfer Key"]})})]})}function Se(e,t=6,r=6){return !e||e.length<=t+r+1?e:`${e.slice(0,t)}\u2026${e.slice(-r)}`}function ys({nodeKey:e,stackName:t}){let r=Math.max(0,e.maxTokens-e.tokenBalance);return jsxRuntime.jsxs("div",{className:"bg-muted/30 p-5 space-y-2 text-sm",children:[e.keyIndex!=null&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key #"}),jsxRuntime.jsxs("span",{className:"text-foreground font-semibold",children:["#",e.keyIndex]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key ID"}),jsxRuntime.jsx("code",{className:"text-xs text-foreground",children:Se(e.id,8,8)})]}),t&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Originating Stack"}),jsxRuntime.jsx("span",{className:"text-foreground",children:t})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Compute tokens used"}),jsxRuntime.jsxs("span",{className:"text-foreground",children:[R(r)," / ",R(e.maxTokens)]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Created"}),jsxRuntime.jsx("span",{className:"text-foreground",children:J(e.createdAt)})]})]})}function Ce(){return jsxRuntime.jsxs("div",{className:"bg-stacknet-blue text-white p-8 lg:w-2/5 flex flex-col justify-between min-h-[260px]",children:[jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("p",{className:"text-sm font-mono opacity-80",children:"stacknet | filing"}),jsxRuntime.jsx("h2",{className:"text-2xl font-semibold leading-snug",children:"File paperwork to redeem Paper."}),jsxRuntime.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."})]}),jsxRuntime.jsx("p",{className:"text-xs opacity-60 mt-8",children:"Powered by StackNet"})]})}function bs({keyId:e,paymentAddress:t,onComplete:r,onConfigurePayment:s,onBack:d,className:c,style:a}){let{config:o}=h(),{keys:n,loading:i,error:l,refresh:u}=H(),{filePaperwork:p,filing:m,result:x,error:b,reset:T}=_e(),w=n.find(E=>E.id===e),L=!!w?.paperWork&&w.paperWork.length>0,_=!!t&&t.length>0,P=L&&_&&!m&&!x,z=async()=>{if(!P||!w)return;let E=await p(w.id);E&&(u(),r?.(E));};return x?jsxRuntime.jsxs("div",{className:f("flex flex-col lg:flex-row",c),style:a,children:[jsxRuntime.jsx(Ce,{}),jsxRuntime.jsxs("div",{className:"flex-1 bg-background p-8 space-y-6",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(lucideReact.CheckCircle2,{className:"h-7 w-7 text-green-500","aria-hidden":true}),jsxRuntime.jsx("h3",{className:"text-2xl font-semibold text-foreground",children:"Paperwork filed"})]}),jsxRuntime.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."}),jsxRuntime.jsxs("div",{className:"bg-muted/30 p-5 space-y-3 text-sm",children:[jsxRuntime.jsxs("div",{className:"flex justify-between gap-4",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Status"}),jsxRuntime.jsx("span",{className:"text-foreground capitalize",children:x.status})]}),jsxRuntime.jsxs("div",{className:"flex justify-between gap-4",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Paper amount"}),jsxRuntime.jsxs("span",{className:"text-foreground tabular-nums",children:[(x.paperAmount/1e6).toLocaleString(void 0,{maximumFractionDigits:6})," Paper"]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between gap-4",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"File hash"}),jsxRuntime.jsx("code",{className:"text-xs text-foreground break-all",children:Se(x.fileHash,10,10)})]}),x.txSignature&&jsxRuntime.jsxs("div",{className:"flex justify-between gap-4",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Tx"}),jsxRuntime.jsx("a",{href:`https://solscan.io/tx/${encodeURIComponent(x.txSignature)}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-foreground underline underline-offset-4",children:Se(x.txSignature,8,8)})]}),jsxRuntime.jsxs("div",{className:"flex justify-between gap-4",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Beneficiary"}),jsxRuntime.jsx("code",{className:"text-xs text-foreground",children:Se(x.beneficiary,6,6)})]})]}),d&&jsxRuntime.jsx("button",{type:"button",onClick:()=>{T(),d();},className:"w-full bg-foreground text-background py-4 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:"Back to dashboard"})]})]}):i?jsxRuntime.jsxs("div",{className:f("flex flex-col lg:flex-row",c),style:a,children:[jsxRuntime.jsx(Ce,{}),jsxRuntime.jsxs("div",{className:"flex-1 bg-background p-8 space-y-4",children:[jsxRuntime.jsx("div",{className:"h-7 w-48 bg-muted animate-pulse"}),jsxRuntime.jsx("div",{className:"h-32 w-full bg-muted animate-pulse"}),jsxRuntime.jsx("div",{className:"h-12 w-full bg-muted animate-pulse"})]})]}):l||!w?jsxRuntime.jsxs("div",{className:f("flex flex-col lg:flex-row",c),style:a,children:[jsxRuntime.jsx(Ce,{}),jsxRuntime.jsxs("div",{className:"flex-1 bg-background p-8 space-y-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-6 w-6 text-red-500","aria-hidden":true}),jsxRuntime.jsx("h3",{className:"text-xl font-semibold text-foreground",children:l?"Unable to load keys":"Key not found"})]}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:l||`No key with id ${e} on this account.`}),jsxRuntime.jsx("button",{type:"button",onClick:()=>u(),className:"bg-foreground text-background px-4 py-3 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:"Try again"})]})]}):jsxRuntime.jsxs("div",{className:f("flex flex-col lg:flex-row",c),style:a,children:[jsxRuntime.jsx(Ce,{}),jsxRuntime.jsxs("div",{className:"flex-1 bg-background p-8 space-y-6",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h2",{className:"text-2xl font-semibold text-foreground",children:"File paperwork"}),jsxRuntime.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Review the key and beneficiary, then submit your filing."})]}),jsxRuntime.jsx(ys,{nodeKey:w,stackName:o.stackName}),!L&&jsxRuntime.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."}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Beneficiary (payment address)"}),_?jsxRuntime.jsx("div",{className:"bg-muted/30 p-4",children:jsxRuntime.jsx("code",{className:"text-xs text-foreground break-all",children:t})}):jsxRuntime.jsxs("div",{className:"bg-muted/30 p-4 space-y-3",children:[jsxRuntime.jsx("p",{className:"text-sm text-foreground",children:"You haven't set a payment address yet."}),s&&jsxRuntime.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"})]})]}),jsxRuntime.jsxs("div",{className:"bg-muted/30 p-4 flex gap-3",children:[jsxRuntime.jsx(lucideReact.Info,{className:"h-5 w-5 shrink-0 text-foreground mt-0.5","aria-hidden":true}),jsxRuntime.jsxs("p",{className:"text-sm text-foreground leading-relaxed",children:[jsxRuntime.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."]})]}),b&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:b}),jsxRuntime.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:m?"Filing\u2026":"File Paperwork"})]})]})}function vs(e){return typeof e.paperWork=="string"&&e.paperWork.length>0}function hs({count:e=3}){return jsxRuntime.jsx("div",{className:"space-y-2",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsxs("div",{className:"bg-muted/30 p-4 space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("div",{className:"h-4 w-40 bg-muted animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 w-16 bg-muted animate-pulse"})]}),jsxRuntime.jsx("div",{className:"h-3 w-32 bg-muted animate-pulse"})]},r))})}function ws({nodeKey:e,onSelect:t}){let r=Math.max(0,e.maxTokens-e.tokenBalance);return jsxRuntime.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:[jsxRuntime.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsxs("span",{className:"text-sm font-semibold text-foreground",children:[e.keyIndex!=null?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:e.stackName||""})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[jsxRuntime.jsxs("span",{className:"tabular-nums",children:[R(r)," / ",R(e.maxTokens)," compute used"]}),jsxRuntime.jsx("span",{className:"text-foreground",children:"Eligible"})]})]}),jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-5 w-5 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5","aria-hidden":true})]})}function Ps({onSelect:e,className:t,style:r}){let{keys:s,loading:d,error:c,refresh:a}=H();if(d)return jsxRuntime.jsx("div",{className:f("space-y-3",t),style:r,children:jsxRuntime.jsx(hs,{count:3})});if(c)return jsxRuntime.jsx("div",{className:f("space-y-3",t),style:r,children:jsxRuntime.jsxs("div",{className:"bg-muted/30 p-5 text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c}),jsxRuntime.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(vs);return o.length===0?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-3 bg-muted/20 py-16",t),style:r,children:[jsxRuntime.jsx(lucideReact.FileText,{className:"h-10 w-10 text-muted-foreground","aria-hidden":true}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys with pending paperwork"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Run a node to earn Paper, then return here to file."})]})]}):jsxRuntime.jsx("div",{className:f("space-y-2",t),style:r,children:o.map(n=>jsxRuntime.jsx(ws,{nodeKey:n,onSelect:()=>e(n.id)},n.id))})}function Cs(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 Ss(e){if(!e)return {};let t=e();return t instanceof Promise?await t:t}async function ae(e,t={}){let{getHeaders:r,...s}=t,d=await Ss(r),c=await fetch(e,{...s,headers:{"Content-Type":"application/json",...d,...s.headers},credentials:"include"});if(!c.ok)throw new Error(await U(c,`Request failed (${c.status})`));return c.json()}function Rs(e){let{apiBaseUrl:t,stackId:r,stackName:s,getHeaders:d}=e,c=`${t}/api/keys`;return {async getKeys(){let a=await ae(c,{getHeaders:d});return (Array.isArray(a)?a:a.keys??[]).map(Cs)},async getLedger(a){let o=await ae(`${c}/${encodeURIComponent(a)}/ledger`,{getHeaders:d});return Array.isArray(o)?o:o.entries??[]},async getPricing(){return ae(`${c}/pricing`,{getHeaders:d})},async mint(a,o,n=1){try{let i=await ae(c+"/mint",{method:"POST",body:JSON.stringify({paymentMethod:a,paymentRef:o,quantity:n,stackId:r}),getHeaders:d}),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 ae(`${c}/${encodeURIComponent(a)}/list`,{method:"POST",body:JSON.stringify({askPriceCents:o,stackId:r,stackName:s}),getHeaders:d})},async delistKey(a){await ae(`${c}/${encodeURIComponent(a)}/list`,{method:"DELETE",getHeaders:d});},async transferKey(a,o){return ae(`${c}/${encodeURIComponent(a)}/transfer`,{method:"POST",body:JSON.stringify({recipientId:o}),getHeaders:d})},async createStripeSession(a,o,n){return ae(`${c}/stripe-session`,{method:"POST",body:JSON.stringify({priceCents:a,quantity:o,stackId:r,referrerUrl:n}),getHeaders:d})}}}
2
- exports.BottomSheet=ve;exports.BuyKeyWidget=zr;exports.BuyPanel=Ve;exports.FilePaperworkList=Ps;exports.FilePaperworkView=bs;exports.KeyBalanceBar=Z;exports.KeyCard=Ze;exports.KeyDetailView=Ge;exports.KeyList=is;exports.KeyUtilsProvider=Re;exports.KeysPanel=Je;exports.MAX_ERROR_LEN=Et;exports.MintSuccess=Oe;exports.SellPanel=Qr;exports.SolanaPayButton=We;exports.TransferPanel=fs;exports.UsePanel=qe;exports.calculateBalancePercentage=st;exports.clampErrorMessage=rt;exports.cn=f;exports.createKeyClient=Rs;exports.csrfHeaders=G;exports.detectPlatform=ot;exports.formatDate=J;exports.formatTokens=R;exports.getBalanceColor=nt;exports.readErrorMessage=U;exports.safeUrl=A;exports.useFilePaperwork=_e;exports.useFilingHistory=ir;exports.useKeyLedger=ge;exports.useKeyUtilsContext=h;exports.useKeys=H;exports.useListKey=xe;exports.useMintKey=Le;exports.usePricing=Ie;exports.useSolanaPayment=er;exports.useStripeCheckout=Fe;exports.useTransferKey=ye;
1
+ 'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),Ir=require('react'),jsxRuntime=require('react/jsx-runtime'),lucideReact=require('lucide-react');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Ir__default=/*#__PURE__*/_interopDefault(Ir);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 tailwindMerge.twMerge(clsx.clsx(e))}function K(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=Ir.createContext(null);function h(){let e=Ir.useContext(ut);if(!e)throw new Error("useKeyUtilsContext must be used within a KeyUtilsProvider");return e}function Ke({config:e,callbacks:t={},children:r}){typeof e.apiBaseUrl!="string"&&console.error("[KeyUtils] apiBaseUrl must be a string");let s=Ir.useMemo(()=>({config:e,callbacks:t}),[e,t]);return jsxRuntime.jsx(ut.Provider,{value:s,children:r})}function Ue(){let{config:e}=h(),[t,r]=Ir.useState(null),[s,u]=Ir.useState(true),[i,a]=Ir.useState(null),o=Ir.useRef(true),n=Ir.useRef(e.apiBaseUrl);n.current=e.apiBaseUrl;let c=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 Ir.useEffect(()=>{o.current=true,c();let l=setInterval(c,6e4);return ()=>{o.current=false,clearInterval(l);}},[]),{pricing:t,loading:s,error:i,refresh:c}}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]=Ir.useState([]),[s,u]=Ir.useState(true),[i,a]=Ir.useState(null),o=Ir.useRef(true),n=e.apiBaseUrl,c=Ir.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]);Ir.useEffect(()=>(o.current=true,c(),()=>{o.current=false;}),[c]);let l=t.reduce((m,p)=>m+p.tokenBalance,0);return {keys:t,totalBalance:l,loading:s,error:i,refresh:c}}function Le(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),i=await fetch(e,{...s,headers:{"Content-Type":"application/json",...u,...s.headers},credentials:"include"});if(!i.ok)throw new Error(await U(i,`Request failed (${i.status})`));return i.json()}function rr(e){let{apiBaseUrl:t,stackId:r,stackName:s,getHeaders:u}=e,i=`${t}/api/keys`;return {async getKeys(){let a=await oe(i,{getHeaders:u});return (Array.isArray(a)?a:a.keys??[]).map(er)},async getLedger(a){let o=await oe(`${i}/${encodeURIComponent(a)}/ledger`,{getHeaders:u});return (Array.isArray(o)?o:o.entries??[]).map(Le)},async getPricing(){return oe(`${i}/pricing`,{getHeaders:u})},async mint(a,o,n=1){try{let c=await oe(i+"/mint",{method:"POST",body:JSON.stringify({paymentMethod:a,paymentRef:o,quantity:n,stackId:r}),getHeaders:u}),l=c.keys?.[0]||c;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(c){return {success:false,error:c instanceof Error?c.message:"Key generation failed"}}},async listKey(a,o){return oe(`${i}/${encodeURIComponent(a)}/list`,{method:"POST",body:JSON.stringify({askPriceCents:o,stackId:r,stackName:s}),getHeaders:u})},async delistKey(a){await oe(`${i}/${encodeURIComponent(a)}/list`,{method:"DELETE",getHeaders:u});},async transferKey(a,o){return oe(`${i}/${encodeURIComponent(a)}/transfer`,{method:"POST",body:JSON.stringify({recipientId:o}),getHeaders:u})},async createStripeSession(a,o,n){return oe(`${i}/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]=Ir.useState([]),[u,i]=Ir.useState(false),[a,o]=Ir.useState(null),n=Ir.useRef(true),c=t.apiBaseUrl,l=Ir.useCallback(async()=>{if(e)try{i(!0),o(null);let m=await fetch(`${c}/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(Le));}catch(m){n.current&&o(m instanceof Error?m.message:"Failed to fetch ledger");}finally{n.current&&i(false);}},[c,e]);return Ir.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]=Ir.useState(false),[u,i]=Ir.useState(null),[a,o]=Ir.useState(null);return {mint:Ir.useCallback(async(c,l,m=1)=>{try{s(!0),o(null),t.onPaymentComplete?.(c,l);let p=await fetch(`${e.apiBaseUrl}/api/keys/mint`,{method:"POST",headers:{"Content-Type":"application/json",...G()},credentials:"include",body:JSON.stringify({paymentMethod:c,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,N={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 i(N),t.onMintSuccess?.(N),N}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]=Ir.useState(false),[u,i]=Ir.useState(null),[a,o]=Ir.useState(null),n=Ir.useRef(true),c=Ir.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&&(i(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=Ir.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&&i(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:c,delistKey:l,listing:r,result:u,error:a}}function Me(){let{config:e}=h(),[t,r]=Ir.useState(false),[s,u]=Ir.useState(null),i=Ir.useRef(true);return {createSession:Ir.useCallback(async(o,n)=>{try{r(!0),u(null);let c=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(!c.ok)throw new Error(await U(c,`Checkout failed (${c.status})`));let{url:l}=await c.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(c){if(i.current){let l=c instanceof Error?c.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]=Ir.useState(false),[s,u]=Ir.useState(null);return {pay:Ir.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:c,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(),N=new n(g.publicKey.toString()),T="https://api.mainnet-beta.solana.com",w=F(e.solanaRpcUrl,T),L=w==="#"?T:w,j=new o(L),{blockhash:P}=await j.getLatestBlockhash(),Y=BigInt(Math.floor(a*1e9)),E=e.protocolTreasuryWallet,_=e.protocolFeeBps??500,q=new c({recentBlockhash:P,feePayer:N});if(E&&xt.test(E)&&_>0){let ue=Y*BigInt(_)/10000n,D=Y-ue,Q=new n(E);q.add(l.transfer({fromPubkey:N,toPubkey:d,lamports:Number(D)}),l.transfer({fromPubkey:N,toPubkey:Q,lamports:Number(ue)}));}else q.add(l.transfer({fromPubkey:N,toPubkey:d,lamports:Number(Y)}));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]=Ir.useState(false),[u,i]=Ir.useState(null),[a,o]=Ir.useState(null),n=Ir.useRef(true);return {transferKey:Ir.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&&(i(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]=Ir.useState(false),[u,i]=Ir.useState(null),[a,o]=Ir.useState(null),n=Ir.useRef(true),c=Ir.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&&(i(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=Ir.useCallback(()=>{i(null),o(null);},[]);return {filePaperwork:c,filing:r,result:u,error:a,reset:l}}function br(){let{config:e}=h(),[t,r]=Ir.useState([]),[s,u]=Ir.useState(true),[i,a]=Ir.useState(null),o=Ir.useRef(true),n=e.apiBaseUrl,c=Ir.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 Ir.useEffect(()=>(o.current=true,c(),()=>{o.current=false;}),[c]),{entries:t,loading:s,error:i,refresh:c}}var kt=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function Ve({amountSol:e,onSuccess:t,onError:r,disabled:s,className:u,style:i}){let{config:a}=h(),[o,n]=Ir.useState(false),[c,l]=Ir.useState(null),m=!!(a.merchantWallet&&kt.test(a.merchantWallet)),p=Ir.useCallback(async()=>{if(m)try{n(!0),l(null);let{Connection:d,PublicKey:g,Transaction:N,SystemProgram:T,LAMPORTS_PER_SOL:w}=await import('@solana/web3.js'),L=typeof window<"u"?window.solana:void 0;if(!L||typeof L!="object"||!L.isPhantom)throw new Error("Phantom wallet not found. Please install Phantom.");let j=L,P;try{P=new g(a.merchantWallet);}catch{throw new Error("Invalid merchant wallet address.")}let Y=await j.connect(),E=new g(Y.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 N({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(T.transfer({fromPubkey:E,toPubkey:P,lamports:Number(jt)}),T.transfer({fromPubkey:E,toPubkey:$t,lamports:Number(at)}));}else fe.add(T.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 jsxRuntime.jsxs("div",{children:[jsxRuntime.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-lg bg-purple-600 px-4 py-6 font-medium text-white transition-colors hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed",u),style:i,children:o?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader2,{className:"h-4 w-4 animate-spin"}),"Processing..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Pay ",e.toFixed(4)," SOL"]})}),c&&jsxRuntime.jsx("p",{className:"mt-2 text-center text-xs text-red-500",children:c})]})}function ze({result:e,className:t,style:r}){let[s,u]=Ir.useState(false),i=Ir.useRef(null);Ir.useEffect(()=>()=>{i.current&&clearTimeout(i.current);},[]);let a=Ir.useCallback(()=>{e.key?.key&&(navigator.clipboard.writeText(e.key.key),u(true),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>u(false),2e3));},[e.key?.key]);return !e.success||!e.key?null:jsxRuntime.jsxs("div",{className:f("rounded-lg border border-green-500/20 bg-green-500/10 p-6 text-center",t),style:r,children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"mx-auto mb-3 h-12 w-12 text-green-500"}),jsxRuntime.jsx("h3",{className:"mb-2 text-lg font-semibold text-foreground",children:"Key Generated!"}),jsxRuntime.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Your node key has been successfully generated."}),jsxRuntime.jsxs("div",{className:"mx-auto flex max-w-md items-center gap-2 rounded-md border bg-background p-3",children:[jsxRuntime.jsx("code",{className:"flex-1 truncate text-xs text-foreground",children:e.key.key}),jsxRuntime.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?jsxRuntime.jsx(lucideReact.Check,{className:"h-4 w-4 text-green-500"}):jsxRuntime.jsx(lucideReact.Copy,{className:"h-4 w-4"})})]})]})}function te({className:e}){return jsxRuntime.jsx("div",{className:f("animate-pulse rounded-xl bg-muted",e)})}function Ye(){return jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"px-6 py-10 flex flex-col items-center gap-3",children:[jsxRuntime.jsx(te,{className:"h-14 w-48"}),jsxRuntime.jsx(te,{className:"h-5 w-64"})]}),jsxRuntime.jsx(te,{className:"h-[72px] w-full rounded-2xl"}),jsxRuntime.jsx(te,{className:"h-[68px] w-full rounded-2xl"}),jsxRuntime.jsx(te,{className:"h-[60px] w-full rounded-2xl"})]})}function ae({count:e=3}){return jsxRuntime.jsx("div",{className:"space-y-3",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsxs("div",{className:"rounded-xl border p-4 space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(te,{className:"h-4 w-32"}),jsxRuntime.jsx(te,{className:"h-4 w-16"})]}),jsxRuntime.jsx(te,{className:"h-2 w-full rounded-full"}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(te,{className:"h-3 w-24"}),jsxRuntime.jsx(te,{className:"h-3 w-20"})]})]},r))})}function Ar({quantity:e,max:t,onChange:r}){return jsxRuntime.jsxs("div",{className:"flex items-center justify-between rounded-2xl bg-muted/20 px-6 py-6",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-foreground",children:"Quantity"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-0 rounded-xl bg-background",children:[jsxRuntime.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:jsxRuntime.jsx(lucideReact.Minus,{className:"h-5 w-5"})}),jsxRuntime.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}),jsxRuntime.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:jsxRuntime.jsx(lucideReact.Plus,{className:"h-5 w-5"})})]})]})}function wt({pricing:e,quantity:t}){let[r,s]=Ir.useState(false),u=e.priceUsd*t;return jsxRuntime.jsxs("div",{className:"rounded-2xl border bg-background",children:[jsxRuntime.jsxs("button",{onClick:()=>s(!r),"aria-expanded":r,className:"flex w-full items-center justify-between px-6 py-6 text-left",children:[jsxRuntime.jsxs("span",{className:"text-foreground",children:[jsxRuntime.jsxs("span",{className:"text-xl font-bold",children:["$",u.toFixed(2)]})," ",jsxRuntime.jsx("span",{className:"text-sm text-muted-foreground",children:"total fees included"})]}),r?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"h-5 w-5 text-muted-foreground"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-5 w-5 text-muted-foreground"})]}),r&&jsxRuntime.jsxs("div",{className:"border-t px-6 pb-8 pt-4 space-y-3 text-sm",children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsxs("span",{className:"text-muted-foreground",children:["Node Key \xD7 ",t]}),jsxRuntime.jsxs("span",{className:"text-foreground",children:["$",(e.priceUsd*t).toFixed(2)]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Keys sold"}),jsxRuntime.jsx("span",{className:"text-foreground",children:e.keysSold})]}),e.daysUntilHalving>0&&jsxRuntime.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[jsxRuntime.jsx("span",{children:"Next refresh"}),jsxRuntime.jsxs("span",{children:[e.daysUntilHalving," day",e.daysUntilHalving!==1?"s":""]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between border-t pt-3 font-semibold",children:[jsxRuntime.jsx("span",{className:"text-foreground",children:"Total"}),jsxRuntime.jsxs("span",{className:"text-foreground",children:["$",u.toFixed(2)]})]})]})]})}function qe({className:e,style:t}){let{config:r}=h(),{pricing:s,loading:u,error:i,refresh:a}=Ue(),{mint:o,minting:n,result:c,error:l}=Ae(),{createSession:m,loading:p,error:d}=Me(),[g,N]=Ir.useState(1),[T,w]=Ir.useState(r.paymentMethods?.includes("stripe")?"stripe":"solana"),[L,j]=Ir.useState(0),[P,Y]=Ir.useState(false),E=Ir__default.default.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(Ir.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&&!c?.success){let me=false;try{me=sessionStorage.getItem("keyutils_stripe_pending")==="1";}catch{}if(!me)return;try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}Y(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,c,o]),c?.success)return jsxRuntime.jsx("div",{className:f("flex flex-col items-center justify-center",e),style:t,children:jsxRuntime.jsx(ze,{result:c})});if(P||n)return jsxRuntime.jsx("div",{className:f("flex flex-col",e),style:t,children:jsxRuntime.jsx(Ye,{})});if(u)return jsxRuntime.jsx("div",{className:f("flex flex-col",e),style:t,children:jsxRuntime.jsx(Ye,{})});if(i||!s)return jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-24",e),style:t,children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load pricing"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i||"Please check your connection and try again."})]}),jsxRuntime.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(T,D,g);},ue=()=>{m(s.priceCents,g);};return jsxRuntime.jsx("div",{className:f("flex flex-col",e),style:t,children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[L===0&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[r.keyImage&&jsxRuntime.jsx("img",{src:F(r.keyImage),alt:"Node Key",className:r.keyImageClass||"w-1/2 mx-auto"}),jsxRuntime.jsxs("div",{className:"px-6 py-10 text-center",children:[jsxRuntime.jsxs("p",{className:"text-5xl font-bold tracking-tight text-foreground md:text-6xl",children:["$",s.priceUsd.toFixed(2)]}),jsxRuntime.jsxs("p",{className:"mt-2 text-base text-muted-foreground",children:["per key \xB7 ",s.tokenAllocationFormatted||K(s.tokenAllocation)," tokens included"]})]}),jsxRuntime.jsx(Ar,{quantity:g,max:_,onChange:N}),jsxRuntime.jsx(wt,{pricing:s,quantity:g}),jsxRuntime.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"})]}),L===1&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[q.length>1&&jsxRuntime.jsx("div",{role:"tablist",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:q.map(D=>jsxRuntime.jsxs("button",{role:"tab","aria-selected":T===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",T===D?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[D==="stripe"?jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-5 w-5"}):jsxRuntime.jsx(lucideReact.Wallet,{className:"h-5 w-5"}),D==="stripe"?"Credit Card":"Crypto"]},D))}),jsxRuntime.jsx(wt,{pricing:s,quantity:g}),T==="stripe"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.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?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin"}),"Redirecting to Stripe..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-5 w-5"}),"Pay with Card"]})}),d&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-500",children:d})]}):T==="solana"?jsxRuntime.jsx(Ve,{amountSol:s.priceSol??0,onSuccess:ne,className:"rounded-2xl py-5 text-base"}):null,l&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-500",children:l}),jsxRuntime.jsx("button",{onClick:()=>j(0),className:"w-full py-3 text-center text-sm text-muted-foreground hover:text-foreground transition-colors",children:"\u2190 Back"})]})]})})}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=Ir.useMemo(()=>dt(),[]),i=e||Dr.map(n=>({platform:n,label:$r[n],url:Wr,compatible:n===u})),a=i.find(n=>n.compatible)||i[0],o=i.filter(n=>n.platform!==a.platform);return jsxRuntime.jsxs("div",{className:f("space-y-8",t),style:r,children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-6 pt-4 mt-4",children:[s.aispImage&&jsxRuntime.jsx("img",{src:F(s.aispImage),alt:"aiSP",className:"w-full sm:w-1/2 mx-auto px-4 sm:px-0"}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("p",{className:"text-lg sm:text-2xl font-medium text-foreground",children:"Download the AI Service Provider App"}),jsxRuntime.jsx("p",{className:"mt-1 text-sm sm:text-base text-muted-foreground",children:"Load your keys and run your node."})]}),jsxRuntime.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:[jsxRuntime.jsx(lucideReact.Download,{className:"h-5 w-5"}),"Get aiSP for ",a.label]})]}),jsxRuntime.jsxs("p",{className:"text-center text-sm text-muted-foreground",children:["aiSP is also available on"," ",o.map((n,c)=>jsxRuntime.jsxs(Ir__default.default.Fragment,{children:[c>0&&(c===o.length-1?" and ":", "),jsxRuntime.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)),"."]}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-2 mt-12",children:[jsxRuntime.jsxs("p",{className:"text-center text-xs text-muted-foreground flex justify-center gap-0.5 flex-wrap",children:["Source code is available on",jsxRuntime.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"})]}),jsxRuntime.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",jsxRuntime.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"})]})]})]})}function Z({current:e,max:t,className:r,style:s,showLabel:u=true}){let i=lt(e,t),a=ct(i);return jsxRuntime.jsxs("div",{className:f("w-full",r),style:s,children:[u&&jsxRuntime.jsxs("div",{className:"mb-1 flex items-center justify-between text-xs text-muted-foreground",children:[jsxRuntime.jsxs("span",{children:[K(e)," / ",K(t)]}),jsxRuntime.jsxs("span",{children:[i,"%"]})]}),jsxRuntime.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-muted",children:jsxRuntime.jsx("div",{className:f("h-full rounded-full transition-all duration-500",a),style:{width:`${i}%`}})})]})}function ve({open:e,onClose:t,title:r,children:s}){let u=Ir.useRef(null),[i,a]=Ir.useState(false),[o,n]=Ir.useState(false),c=Ir.useCallback(l=>{l.key==="Escape"&&t();},[t]);return Ir.useEffect(()=>{if(e)a(true),document.addEventListener("keydown",c),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",c),()=>clearTimeout(l)}return ()=>{document.removeEventListener("keydown",c);}},[e,c]),i?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",children:[jsxRuntime.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm transition-opacity duration-300",style:{opacity:o?1:0},onClick:t}),jsxRuntime.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:[jsxRuntime.jsx("div",{className:"flex justify-center pt-3 pb-1",children:jsxRuntime.jsx("div",{className:"h-1 w-10 rounded-full bg-muted-foreground/30"})}),r&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-5 pb-3 pt-1",children:[jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:r}),jsxRuntime.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:jsxRuntime.jsx(lucideReact.X,{className:"h-5 w-5"})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto px-5 pb-8",children:s})]})]}):null}var Ce=[" .-----."," / (_) \\"," / \\","( )"," \\ /"," \\_______/"," || |"," || |"," || /"," || /"," || \\"," || /"," || /"," \\// "],Qe=16,Yr=Qe*.6,St=Qe*1;function Xe({className:e,style:t,color:r="currentColor",ariaLabel:s="Node key",keyImage:u,keyImageClass:i}){if(u)return jsxRuntime.jsx("img",{src:F(u),alt:s,className:f(i||"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*Yr,l=o*St;return jsxRuntime.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:jsxRuntime.jsx("g",{transform:`translate(0 ${n}) rotate(-90)`,children:Ce.map((p,d)=>jsxRuntime.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 Qr({nodeKey:e,onSuccess:t}){let{transferKey:r,transferring:s,result:u,error:i}=ye(),[a,o]=Ir.useState(""),[n,c]=Ir.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?jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Transfer Complete"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Key transferred successfully"})]}):jsxRuntime.jsxs("div",{className:"space-y-5",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"mb-1.5 block text-sm font-semibold text-foreground",children:"Recipient User ID"}),jsxRuntime.jsx("input",{type:"text",value:a,onChange:d=>{o(d.target.value),c(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&&jsxRuntime.jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),a.trim().length>0&&!l&&jsxRuntime.jsx("div",{className:"rounded-xl border border-amber-500/30 bg-amber-500/5 p-4",children:jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.jsx(lucideReact.AlertTriangle,{className:"mt-0.5 h-5 w-5 shrink-0 text-amber-500"}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Confirm Transfer"}),jsxRuntime.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Transferring key"," ",jsxRuntime.jsx("span",{className:"font-mono font-medium",children:e.keyIndex?`#${e.keyIndex}`:e.id.slice(0,12)})," ","(",K(e.tokenBalance)," tokens) to"," ",jsxRuntime.jsxs("span",{className:"font-mono font-medium",children:[a.trim().slice(0,20),a.trim().length>20?"...":""]})]})]}),jsxRuntime.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:n,onChange:d=>c(d.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border"}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"I confirm this transfer is permanent and cannot be undone."})]})]})]})}),i&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:i}),jsxRuntime.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?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Transferring..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Send,{className:"h-4 w-4"}),"Transfer Key"]})})]})}function Xr({nodeKey:e,onSuccess:t}){let{config:r}=h(),{listKey:s,listing:u,result:i,error:a}=xe(),[o,n]=Ir.useState(""),[c,l]=Ir.useState(false),m=parseInt(o.replace(/[^0-9]/g,""),10)||0,d=m>0&&Number.isFinite(m)&&c&&!u,g=async()=>{if(!d)return;let N=m*100;await s(e.id,N)&&t();};return i?jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Key Listed!"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Your key is now on the marketplace."}),jsxRuntime.jsxs("p",{className:"text-xs text-muted-foreground",children:["Listing ID: ",jsxRuntime.jsx("code",{children:i.listingId})]}),jsxRuntime.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:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),"View Listing"]})]}):jsxRuntime.jsxs("div",{className:"space-y-5",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{htmlFor:"listing-price",className:"mb-2 block text-sm font-semibold text-foreground",children:"Listing Price (USD)"}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-2xl font-bold text-muted-foreground",children:"$"}),jsxRuntime.jsx("input",{id:"listing-price",type:"text",inputMode:"numeric",value:o,onChange:N=>{let T=N.target.value.replace(/[^0-9]/g,""),w=parseInt(T,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"})]})]}),jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.jsx("button",{type:"button",role:"checkbox","aria-checked":c,onClick:()=>l(!c),className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",c?"border-foreground bg-foreground":"border-muted-foreground/40"),children:c&&jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 text-background"})}),jsxRuntime.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."," ",jsxRuntime.jsx("a",{href:F(r.termsUrl,"/terms"),className:"text-foreground underline",target:"_blank",rel:"noopener noreferrer",children:"Terms"})]})]}),a&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:a}),jsxRuntime.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:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),u?"Listing...":"List on Marketplace"]})]})}function Zr({nodeKey:e}){let[t,r]=Ir.useState(false);if(!e.paperWork)return jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-3 py-12",children:[jsxRuntime.jsx(lucideReact.FileText,{className:"h-10 w-10 text-muted-foreground"}),jsxRuntime.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 jsxRuntime.jsxs("div",{className:"space-y-5",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"mb-2 block text-sm font-semibold text-foreground",children:"Paperwork"}),jsxRuntime.jsxs("div",{className:"relative rounded-xl border bg-muted/30 p-4",children:[jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap break-all text-sm text-foreground font-mono",children:e.paperWork}),jsxRuntime.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?jsxRuntime.jsx(lucideReact.Check,{className:"h-4 w-4 text-green-500"}):jsxRuntime.jsx(lucideReact.Copy,{className:"h-4 w-4"})})]})]}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Filing paperwork submits the key's documentation on-chain for permanent record."}),jsxRuntime.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:[jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4"}),"File Paperwork (Coming Soon)"]})]})}function et({nodeKey:e,onBack:t,onKeysChanged:r,className:s,style:u}){let{config:i}=h(),{entries:a,loading:o}=ge(e.id),[n,c]=Ir.useState(null),[l,m]=Ir.useState(false),p=()=>{c(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 jsxRuntime.jsxs("div",{className:f("space-y-5",s),style:u,children:[jsxRuntime.jsxs("button",{onClick:t,className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors",children:[jsxRuntime.jsx(lucideReact.ArrowLeft,{className:"h-4 w-4"}),"Back to Keys"]}),jsxRuntime.jsx(Xe,{className:f("mx-auto text-foreground",i.keyImage?"w-2/3 h-auto":"h-20 w-auto"),keyImage:i.keyImage,keyImageClass:i.keyImageClass}),jsxRuntime.jsx("div",{className:"space-y-1",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("h2",{className:"text-2xl font-bold text-foreground",children:e.keyIndex?`Key #${e.keyIndex}`:e.label||e.id.slice(0,16)}),jsxRuntime.jsx("span",{className:f("text-sm font-medium capitalize",g),children:e.status})]})}),e.key&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("code",{className:"flex-1 truncate rounded-lg bg-muted px-3 py-2 text-xs text-muted-foreground",children:e.key}),jsxRuntime.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?jsxRuntime.jsx(lucideReact.Check,{className:"h-4 w-4 text-green-500"}):jsxRuntime.jsx(lucideReact.Copy,{className:"h-4 w-4"})})]}),jsxRuntime.jsx(Z,{current:e.tokenBalance,max:e.maxTokens,showLabel:true}),jsxRuntime.jsxs("div",{className:"rounded-xl bg-muted/30 p-5 space-y-2.5 text-sm",children:[e.keyIndex&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key #"}),jsxRuntime.jsxs("span",{className:"text-foreground font-semibold",children:["#",e.keyIndex]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key ID"}),jsxRuntime.jsx("code",{className:"text-xs text-foreground",children:e.id})]}),(i.stackName||e.stackName)&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Stack"}),jsxRuntime.jsx("span",{className:"text-foreground",children:e.stackName||i.stackName})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Tokens"}),jsxRuntime.jsxs("span",{className:"text-foreground",children:[K(e.tokenBalance)," / ",K(e.maxTokens)]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Created"}),jsxRuntime.jsx("span",{className:"text-foreground",children:X(e.createdAt)})]}),e.expiresAt&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Expires"}),jsxRuntime.jsx("span",{className:"text-foreground",children:X(e.expiresAt)})]})]}),e.paperWork&&jsxRuntime.jsxs("div",{className:"rounded-xl border bg-muted/30 p-5",children:[jsxRuntime.jsx("h3",{className:"text-sm font-semibold text-foreground mb-2",children:"Paperwork"}),jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap break-all text-xs text-muted-foreground font-mono",children:e.paperWork})]}),e.status==="active"&&jsxRuntime.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[jsxRuntime.jsx("button",{onClick:()=>c("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"}),jsxRuntime.jsx("button",{onClick:()=>c("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"}),jsxRuntime.jsx("button",{onClick:()=>c("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"})]}),jsxRuntime.jsx(ve,{open:n==="transfer",onClose:()=>c(null),title:"Transfer Key",children:jsxRuntime.jsx(Qr,{nodeKey:e,onSuccess:p})}),jsxRuntime.jsx(ve,{open:n==="sell",onClose:()=>c(null),title:"Sell Key",children:jsxRuntime.jsx(Xr,{nodeKey:e,onSuccess:p})}),jsxRuntime.jsx(ve,{open:n==="file",onClose:()=>c(null),title:"File Paperwork",children:jsxRuntime.jsx(Zr,{nodeKey:e})})]})}function es({nodeKey:e,onClick:t}){let r=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsxRuntime.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:jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:f("text-xs font-medium capitalize",r),children:e.status})]}),jsxRuntime.jsx(Z,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"}),e.paperWork&&jsxRuntime.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:i,refresh:a}=H(),[o,n]=Ir.useState(null),[c,l]=Ir.useState("active"),m=r.filter(g=>g.status===c),p=m.reduce((g,N)=>g+N.tokenBalance,0),d=r.find(g=>g.id===o);return d?jsxRuntime.jsx(et,{nodeKey:d,onBack:()=>n(null),onKeysChanged:()=>{n(null),a();},className:e,style:t}):u?jsxRuntime.jsxs("div",{className:f("space-y-4",e),style:t,children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx(ae,{count:3})]}):i?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-16",e),style:t,children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i})]}),jsxRuntime.jsx("button",{onClick:()=>a(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]}):r.length===0?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 rounded-xl border border-dashed py-16",e),style:t,children:[jsxRuntime.jsx(lucideReact.KeyRound,{className:"h-10 w-10 text-muted-foreground"}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys yet"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Get your first node key to start earning."})]})]}):jsxRuntime.jsxs("div",{className:f("space-y-4",e),style:t,children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mt-3",children:[jsxRuntime.jsx("h3",{className:"text-2xl font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsxs("span",{className:"text-xs text-muted-foreground",children:[m.length," key",m.length!==1?"s":""," \xB7 ",K(p)," tokens"]}),jsxRuntime.jsx("div",{className:"flex gap-1 rounded-lg bg-muted/50 p-1",children:["active","listed"].map(g=>jsxRuntime.jsx("button",{onClick:()=>l(g),className:f("rounded-md px-3 py-1 text-xs font-medium capitalize transition-all",c===g?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:g},g))})]}),m.length===0?jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-12",children:[jsxRuntime.jsx(lucideReact.KeyRound,{className:"h-8 w-8 text-muted-foreground"}),jsxRuntime.jsxs("p",{className:"text-sm text-muted-foreground",children:["No ",c," keys."]})]}):jsxRuntime.jsx("div",{className:"space-y-2",children:m.map(g=>jsxRuntime.jsx(es,{nodeKey:g,onClick:()=>n(g.id)},g.id))})]})}var rs=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function ss({active:e,onChange:t}){return jsxRuntime.jsx("div",{role:"tablist","aria-label":"Key actions",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:rs.map(({id:r,label:s})=>jsxRuntime.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:jsxRuntime.jsx("span",{className:"inline",children:s})},r))})}function ns({defaultTab:e="buy",className:t,style:r}){let[s,u]=Ir.useState(e);return jsxRuntime.jsxs("div",{className:f("flex flex-col",t),style:r,children:[jsxRuntime.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:jsxRuntime.jsx("div",{className:"mx-auto max-w-xl",children:jsxRuntime.jsx(ss,{active:s,onChange:u})})}),jsxRuntime.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:jsxRuntime.jsx("div",{className:"mx-auto w-full max-w-xl flex-1",children:jsxRuntime.jsxs("div",{role:"tabpanel",id:`panel-${s}`,"aria-labelledby":`tab-${s}`,children:[s==="buy"&&jsxRuntime.jsx(qe,{className:"flex-1"}),s==="use"&&jsxRuntime.jsx(Ge,{className:"flex-1"}),s==="keys"&&jsxRuntime.jsx(tt,{className:"flex-1"})]})})})]})}function os({apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:s,merchantWallet:u,stripePublicKey:i,theme:a,maxQuantity:o,keyImage:n,keyImageClass:c,aispImage:l,termsUrl:m,onMintSuccess:p,onMintError:d,onPaymentStart:g,onPaymentComplete:N,onListingCreated:T,onTransferComplete:w,defaultTab:L,className:j,style:P}){return jsxRuntime.jsx(Ke,{config:{apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:s,merchantWallet:u,stripePublicKey:i,theme:a,maxQuantity:o,keyImage:n,keyImageClass:c,aispImage:l,termsUrl:m},callbacks:{onMintSuccess:p,onMintError:d,onPaymentStart:g,onPaymentComplete:N,onListingCreated:T,onTransferComplete:w},children:jsxRuntime.jsx(ns,{defaultTab:L,className:j,style:P})})}function ls({nodeKey:e,selected:t,onSelect:r}){return jsxRuntime.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:[jsxRuntime.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&&jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 text-background"})}),jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:f("text-xs font-medium capitalize",e.status==="active"?"text-green-500":"text-muted-foreground"),children:e.status})]}),jsxRuntime.jsx(Z,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function cs({className:e,style:t}){let{config:r}=h(),{keys:s,loading:u,error:i,refresh:a}=H(),{listKey:o,listing:n,result:c,error:l}=xe(),[m,p]=Ir.useState(null),[d,g]=Ir.useState(""),[N,T]=Ir.useState(false),w=s.find(_=>_.id===m),L=parseInt(d.replace(/[^0-9]/g,""),10)||0,j=L>0&&Number.isFinite(L),P=!!w&&j&&N&&!n,Y=async()=>{if(!P||!w)return;let _=L*100;await o(w.id,_)&&a();};if(c)return jsxRuntime.jsxs("div",{className:f("flex flex-col items-center gap-4 rounded-xl bg-green-500/10 py-12",e),style:t,children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Key Listed!"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Your key is now on the Global Open AI Network marketplace."}),jsxRuntime.jsxs("p",{className:"text-xs text-muted-foreground",children:["Listing ID: ",jsxRuntime.jsx("code",{children:c.listingId})]}),jsxRuntime.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:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),"View Listing"]})]});if(u)return jsxRuntime.jsxs("div",{className:f("space-y-5 px-1",e),style:t,children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx(ae,{count:2})]});if(i)return jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-16",e),style:t,children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i})]}),jsxRuntime.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?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16",e),style:t,children:[jsxRuntime.jsx(lucideReact.AlertTriangle,{className:"h-8 w-8 text-muted-foreground"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"No active keys to sell."})]}):jsxRuntime.jsxs("div",{className:f("space-y-5",e),style:t,children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx("div",{className:"space-y-2",children:E.map(_=>jsxRuntime.jsx(ls,{nodeKey:_,selected:m===_.id,onSelect:()=>p(_.id)},_.id))})]}),w&&jsxRuntime.jsxs("div",{className:"rounded-xl border bg-muted/30 p-5 space-y-2 text-sm",children:[w.keyIndex&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key #"}),jsxRuntime.jsxs("span",{className:"text-foreground font-semibold",children:["#",w.keyIndex]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key ID"}),jsxRuntime.jsx("code",{className:"text-xs text-foreground",children:w.id})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Originating Stack"}),jsxRuntime.jsx("span",{className:"text-foreground",children:r.stackName||"Unknown"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Tokens (remaining / total)"}),jsxRuntime.jsxs("span",{className:"text-foreground",children:[K(w.tokenBalance)," / ",K(w.maxTokens)]})]}),w.paperWork&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Paper earned"}),jsxRuntime.jsx("span",{className:"text-foreground",children:w.paperWork})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Created"}),jsxRuntime.jsx("span",{className:"text-foreground",children:X(w.createdAt)})]})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{htmlFor:"listing-price",className:"mb-2 block text-sm sm:text-lg font-semibold text-foreground",children:"Listing Price (USD)"}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-2xl font-bold text-muted-foreground",children:"$"}),jsxRuntime.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"})]})]}),jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.jsx("button",{type:"button",role:"checkbox","aria-checked":N,onClick:()=>T(!N),className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",N?"border-foreground bg-foreground":"border-muted-foreground/40"),children:N&&jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 text-background"})}),jsxRuntime.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."," ",jsxRuntime.jsx("a",{href:F(r.termsUrl,"/terms"),className:"text-foreground underline",target:"_blank",rel:"noopener noreferrer",children:"Terms"})]})]}),l&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:l}),jsxRuntime.jsxs("button",{onClick:Y,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:[jsxRuntime.jsx(lucideReact.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]=Ir.useState(false),[i,a]=Ir.useState(false),o=Ir.useRef(null),{entries:n,loading:c}=ge(s?e.id:null);Ir.useEffect(()=>()=>{o.current&&clearTimeout(o.current);},[]);let l=Ir.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 jsxRuntime.jsxs("div",{className:f("rounded-lg border bg-background",t),style:r,children:[jsxRuntime.jsxs("div",{className:"p-4",children:[jsxRuntime.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("button",{onClick:()=>u(!s),"aria-expanded":s,"aria-label":s?"Collapse ledger":"Expand ledger",className:"text-muted-foreground hover:text-foreground",children:s?jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-4 w-4"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4"})}),jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]})]}),jsxRuntime.jsx("span",{className:f("text-xs font-medium capitalize",m),children:e.status})]}),e.key&&jsxRuntime.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[jsxRuntime.jsx("code",{className:"flex-1 truncate rounded bg-muted px-2 py-1 text-xs text-muted-foreground",children:e.key}),jsxRuntime.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:i?jsxRuntime.jsx(lucideReact.Check,{className:"h-3.5 w-3.5 text-green-500"}):jsxRuntime.jsx(lucideReact.Copy,{className:"h-3.5 w-3.5"})})]}),jsxRuntime.jsx(Z,{current:e.tokenBalance,max:e.maxTokens}),jsxRuntime.jsxs("div",{className:"mt-2 flex items-center justify-between text-xs text-muted-foreground",children:[jsxRuntime.jsxs("span",{children:["Created ",X(e.createdAt)]}),e.expiresAt&&jsxRuntime.jsxs("span",{children:["Expires ",X(e.expiresAt)]})]})]}),s&&jsxRuntime.jsxs("div",{className:"border-t px-4 py-3",children:[jsxRuntime.jsx("h4",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Ledger"}),c?jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading..."}):p.length===0?jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"No ledger entries."}):jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[p.map(d=>jsxRuntime.jsxs("div",{className:"flex items-center justify-between text-xs",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.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"?"+":"-",K(Math.abs(d.amount))]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:d.description})]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:X(d.createdAt)})]},d.id)),n.length>st&&jsxRuntime.jsxs("p",{className:"pt-1 text-xs text-muted-foreground",children:["Showing ",st," of ",n.length," entries"]})]})]})]})}var bs=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function Se({baseHref:e}){return jsxRuntime.jsx("div",{className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5 mb-6",children:bs.map(({id:t,label:r})=>jsxRuntime.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 ks({getKeyHref:e="/keys/get",showTabs:t=true,className:r,style:s}){let{keys:u,totalBalance:i,loading:a,error:o,refresh:n}=H();return a?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:s,children:[t&&e&&jsxRuntime.jsx(Se,{baseHref:e}),jsxRuntime.jsx(ae,{count:3})]}):o?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:s,children:[t&&e&&jsxRuntime.jsx(Se,{baseHref:e}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 py-12",children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o})]}),jsxRuntime.jsx("button",{onClick:()=>n(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]})]}):u.length===0?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:s,children:[t&&e&&jsxRuntime.jsx(Se,{baseHref:e}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 rounded-lg border border-dashed py-12",children:[jsxRuntime.jsx(lucideReact.KeyRound,{className:"h-10 w-10 text-muted-foreground"}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys yet"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Get your first node key to start earning."})]}),e&&jsxRuntime.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"})]})]}):jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:s,children:[t&&e&&jsxRuntime.jsx(Se,{baseHref:e}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("p",{className:"text-sm text-muted-foreground",children:[u.length," key",u.length!==1?"s":""," \xB7 Total balance: ",K(i)]}),e&&jsxRuntime.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(c=>jsxRuntime.jsx(nt,{nodeKey:c},c.id))]})}function Ps({nodeKey:e,selected:t,onSelect:r}){return jsxRuntime.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:[jsxRuntime.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&&jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 text-background"})}),jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:"text-xs font-medium capitalize text-green-500",children:e.status})]}),jsxRuntime.jsx(Z,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function Cs({className:e,style:t}){let{keys:r,loading:s}=H(),{transferKey:u,transferring:i,result:a,error:o}=ye(),[n,c]=Ir.useState(null),[l,m]=Ir.useState(""),[p,d]=Ir.useState(false),g=r.filter(P=>P.status==="active"),N=g.find(P=>P.id===n),T=N&&l.trim()===N.userId,w=n&&l.trim().length>0&&p&&!T&&!i,L=async()=>{!n||!l.trim()||await u(n,l.trim());},j=()=>{c(null),m(""),d(false);};return a?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center gap-4 py-8",e),style:t,children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Transfer Complete"}),jsxRuntime.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Key transferred successfully"})]}),jsxRuntime.jsxs("div",{className:"w-full max-w-sm space-y-2 rounded-xl border border-border bg-muted/30 p-4 text-sm",children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key"}),jsxRuntime.jsxs("span",{className:"font-mono text-foreground",children:[a.keyId.slice(0,20),"..."]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Recipient"}),jsxRuntime.jsxs("span",{className:"font-mono text-foreground",children:[a.toUserId.slice(0,20),"..."]})]})]}),jsxRuntime.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"})]}):jsxRuntime.jsxs("div",{className:f("space-y-5",e),style:t,children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"mb-3 text-sm font-medium text-foreground",children:"Select Key to Transfer"}),s?jsxRuntime.jsx(ae,{count:2}):g.length===0?jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"No active keys available for transfer."}):jsxRuntime.jsx("div",{className:"space-y-2",children:g.map(P=>jsxRuntime.jsx(Ps,{nodeKey:P,selected:n===P.id,onSelect:()=>c(P.id)},P.id))})]}),n&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"mb-1.5 block text-sm font-medium text-foreground",children:"Recipient User ID"}),jsxRuntime.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"}),T&&jsxRuntime.jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),N&&l.trim().length>0&&!T&&jsxRuntime.jsx("div",{className:"rounded-xl border border-amber-500/30 bg-amber-500/5 p-4",children:jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.jsx(lucideReact.AlertTriangle,{className:"mt-0.5 h-5 w-5 shrink-0 text-amber-500"}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Confirm Transfer"}),jsxRuntime.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["You are about to transfer key"," ",jsxRuntime.jsx("span",{className:"font-mono font-medium",children:N.keyIndex?`#${N.keyIndex}`:N.id.slice(0,12)})," ","(",K(N.tokenBalance)," tokens) to"," ",jsxRuntime.jsxs("span",{className:"font-mono font-medium",children:[l.trim().slice(0,20),"..."]})]})]}),jsxRuntime.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:p,onChange:P=>d(P.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border"}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"I confirm this transfer is permanent and cannot be undone."})]})]})]})}),o&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:o}),jsxRuntime.jsx("button",{onClick:L,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:i?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Transferring..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Send,{className:"h-4 w-4"}),"Transfer Key"]})})]})}function Ie(e,t=6,r=6){return !e||e.length<=t+r+1?e:`${e.slice(0,t)}\u2026${e.slice(-r)}`}function Ks({nodeKey:e,stackName:t}){let r=Math.max(0,e.maxTokens-e.tokenBalance);return jsxRuntime.jsxs("div",{className:"bg-muted/30 p-5 space-y-2 text-sm",children:[e.keyIndex!=null&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key #"}),jsxRuntime.jsxs("span",{className:"text-foreground font-semibold",children:["#",e.keyIndex]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key ID"}),jsxRuntime.jsx("code",{className:"text-xs text-foreground",children:Ie(e.id,8,8)})]}),t&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Originating Stack"}),jsxRuntime.jsx("span",{className:"text-foreground",children:t})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Compute tokens used"}),jsxRuntime.jsxs("span",{className:"text-foreground",children:[K(r)," / ",K(e.maxTokens)]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Created"}),jsxRuntime.jsx("span",{className:"text-foreground",children:X(e.createdAt)})]})]})}function Re(){return jsxRuntime.jsxs("div",{className:"bg-stacknet-blue text-white p-8 lg:w-2/5 flex flex-col justify-between min-h-[260px]",children:[jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("p",{className:"text-sm font-mono opacity-80",children:"stacknet | filing"}),jsxRuntime.jsx("h2",{className:"text-2xl font-semibold leading-snug",children:"File paperwork to redeem Paper."}),jsxRuntime.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."})]}),jsxRuntime.jsx("p",{className:"text-xs opacity-60 mt-8",children:"Powered by StackNet"})]})}function Ts({keyId:e,paymentAddress:t,onComplete:r,onConfigurePayment:s,onBack:u,className:i,style:a}){let{config:o}=h(),{keys:n,loading:c,error:l,refresh:m}=H(),{filePaperwork:p,filing:d,result:g,error:N,reset:T}=De(),w=n.find(E=>E.id===e),L=!!w?.paperWork&&w.paperWork.length>0,j=!!t&&t.length>0,P=L&&j&&!d&&!g,Y=async()=>{if(!P||!w)return;let E=await p(w.id);E&&(m(),r?.(E));};return g?jsxRuntime.jsxs("div",{className:f("flex flex-col lg:flex-row",i),style:a,children:[jsxRuntime.jsx(Re,{}),jsxRuntime.jsxs("div",{className:"flex-1 bg-background p-8 space-y-6",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(lucideReact.CheckCircle2,{className:"h-7 w-7 text-green-500","aria-hidden":true}),jsxRuntime.jsx("h3",{className:"text-2xl font-semibold text-foreground",children:"Paperwork filed"})]}),jsxRuntime.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."}),jsxRuntime.jsxs("div",{className:"bg-muted/30 p-5 space-y-3 text-sm",children:[jsxRuntime.jsxs("div",{className:"flex justify-between gap-4",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Status"}),jsxRuntime.jsx("span",{className:"text-foreground capitalize",children:g.status})]}),jsxRuntime.jsxs("div",{className:"flex justify-between gap-4",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Paper amount"}),jsxRuntime.jsxs("span",{className:"text-foreground tabular-nums",children:[(g.paperAmount/1e6).toLocaleString(void 0,{maximumFractionDigits:6})," Paper"]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between gap-4",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"File hash"}),jsxRuntime.jsx("code",{className:"text-xs text-foreground break-all",children:Ie(g.fileHash,10,10)})]}),g.txSignature&&jsxRuntime.jsxs("div",{className:"flex justify-between gap-4",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Tx"}),jsxRuntime.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:Ie(g.txSignature,8,8)})]}),jsxRuntime.jsxs("div",{className:"flex justify-between gap-4",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Beneficiary"}),jsxRuntime.jsx("code",{className:"text-xs text-foreground",children:Ie(g.beneficiary,6,6)})]})]}),u&&jsxRuntime.jsx("button",{type:"button",onClick:()=>{T(),u();},className:"w-full bg-foreground text-background py-4 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:"Back to dashboard"})]})]}):c?jsxRuntime.jsxs("div",{className:f("flex flex-col lg:flex-row",i),style:a,children:[jsxRuntime.jsx(Re,{}),jsxRuntime.jsxs("div",{className:"flex-1 bg-background p-8 space-y-4",children:[jsxRuntime.jsx("div",{className:"h-7 w-48 bg-muted animate-pulse"}),jsxRuntime.jsx("div",{className:"h-32 w-full bg-muted animate-pulse"}),jsxRuntime.jsx("div",{className:"h-12 w-full bg-muted animate-pulse"})]})]}):l||!w?jsxRuntime.jsxs("div",{className:f("flex flex-col lg:flex-row",i),style:a,children:[jsxRuntime.jsx(Re,{}),jsxRuntime.jsxs("div",{className:"flex-1 bg-background p-8 space-y-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-6 w-6 text-red-500","aria-hidden":true}),jsxRuntime.jsx("h3",{className:"text-xl font-semibold text-foreground",children:l?"Unable to load keys":"Key not found"})]}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:l||`No key with id ${e} on this account.`}),jsxRuntime.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"})]})]}):jsxRuntime.jsxs("div",{className:f("flex flex-col lg:flex-row",i),style:a,children:[jsxRuntime.jsx(Re,{}),jsxRuntime.jsxs("div",{className:"flex-1 bg-background p-8 space-y-6",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h2",{className:"text-2xl font-semibold text-foreground",children:"File paperwork"}),jsxRuntime.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Review the key and beneficiary, then submit your filing."})]}),jsxRuntime.jsx(Ks,{nodeKey:w,stackName:o.stackName}),!L&&jsxRuntime.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."}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Beneficiary (payment address)"}),j?jsxRuntime.jsx("div",{className:"bg-muted/30 p-4",children:jsxRuntime.jsx("code",{className:"text-xs text-foreground break-all",children:t})}):jsxRuntime.jsxs("div",{className:"bg-muted/30 p-4 space-y-3",children:[jsxRuntime.jsx("p",{className:"text-sm text-foreground",children:"You haven't set a payment address yet."}),s&&jsxRuntime.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"})]})]}),jsxRuntime.jsxs("div",{className:"bg-muted/30 p-4 flex gap-3",children:[jsxRuntime.jsx(lucideReact.Info,{className:"h-5 w-5 shrink-0 text-foreground mt-0.5","aria-hidden":true}),jsxRuntime.jsxs("p",{className:"text-sm text-foreground leading-relaxed",children:[jsxRuntime.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."]})]}),N&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:N}),jsxRuntime.jsx("button",{type:"button",onClick:Y,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 Ls(e){return typeof e.paperWork=="string"&&e.paperWork.length>0}function Es({count:e=3}){return jsxRuntime.jsx("div",{className:"space-y-2",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsxs("div",{className:"bg-muted/30 p-4 space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("div",{className:"h-4 w-40 bg-muted animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 w-16 bg-muted animate-pulse"})]}),jsxRuntime.jsx("div",{className:"h-3 w-32 bg-muted animate-pulse"})]},r))})}function _s({nodeKey:e,onSelect:t}){let r=Math.max(0,e.maxTokens-e.tokenBalance);return jsxRuntime.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:[jsxRuntime.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsxs("span",{className:"text-sm font-semibold text-foreground",children:[e.keyIndex!=null?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:e.stackName||""})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[jsxRuntime.jsxs("span",{className:"tabular-nums",children:[K(r)," / ",K(e.maxTokens)," compute used"]}),jsxRuntime.jsx("span",{className:"text-foreground",children:"Eligible"})]})]}),jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-5 w-5 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5","aria-hidden":true})]})}function As({onSelect:e,className:t,style:r}){let{keys:s,loading:u,error:i,refresh:a}=H();if(u)return jsxRuntime.jsx("div",{className:f("space-y-3",t),style:r,children:jsxRuntime.jsx(Es,{count:3})});if(i)return jsxRuntime.jsx("div",{className:f("space-y-3",t),style:r,children:jsxRuntime.jsxs("div",{className:"bg-muted/30 p-5 text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i}),jsxRuntime.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(Ls);return o.length===0?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-3 bg-muted/20 py-16",t),style:r,children:[jsxRuntime.jsx(lucideReact.FileText,{className:"h-10 w-10 text-muted-foreground","aria-hidden":true}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys with pending paperwork"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Run a node to earn Paper, then return here to file."})]})]}):jsxRuntime.jsx("div",{className:f("space-y-2",t),style:r,children:o.map(n=>jsxRuntime.jsx(_s,{nodeKey:n,onSelect:()=>e(n.id)},n.id))})}
2
+ exports.ASCII_KEY_ART=Ce;exports.BottomSheet=ve;exports.BuyKeyWidget=os;exports.BuyPanel=qe;exports.DefaultKeyArt=Xe;exports.FilePaperworkList=As;exports.FilePaperworkView=Ts;exports.KeyBalanceBar=Z;exports.KeyCard=nt;exports.KeyDetailView=et;exports.KeyList=ks;exports.KeyUtilsProvider=Ke;exports.KeysPanel=tt;exports.MAX_ERROR_LEN=Dt;exports.MintSuccess=ze;exports.SellPanel=cs;exports.SolanaPayButton=Ve;exports.TransferPanel=Cs;exports.UsePanel=Ge;exports.calculateBalancePercentage=lt;exports.clampErrorMessage=it;exports.cn=f;exports.createKeyClient=rr;exports.csrfHeaders=G;exports.detectPlatform=dt;exports.formatDate=X;exports.formatTokens=K;exports.getBalanceColor=ct;exports.readErrorMessage=U;exports.safeUrl=F;exports.useFilePaperwork=De;exports.useFilingHistory=br;exports.useKeyLedger=ge;exports.useKeyUtilsContext=h;exports.useKeys=H;exports.useListKey=xe;exports.useMintKey=Ae;exports.usePricing=Ue;exports.useSolanaPayment=ur;exports.useStripeCheckout=Me;exports.useTransferKey=ye;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { DirectTransferResult, EligibleKey, FilingHistoryEntry, FilingResult, FilingStatus, KeyListing, KeyUtilsCallbacks, KeyUtilsConfig, KeyWidgetTab, LedgerEntry, ListingResult, MintResult, NodeKeyInfo, PaymentMethod, Platform, PlatformDownload, PricingInfo } from './types/index.cjs';
2
2
  export { MAX_ERROR_LEN, calculateBalancePercentage, clampErrorMessage, cn, csrfHeaders, detectPlatform, formatDate, formatTokens, getBalanceColor, readErrorMessage, safeUrl } from './utils/index.cjs';
3
3
  export { useFilePaperwork, useFilingHistory, useKeyLedger, useKeys, useListKey, useMintKey, usePricing, useSolanaPayment, useStripeCheckout, useTransferKey } from './hooks/index.cjs';
4
- export { BottomSheet, BottomSheetProps, BuyKeyWidget, BuyKeyWidgetProps, BuyPanel, BuyPanelProps, FilePaperworkList, FilePaperworkListProps, FilePaperworkView, FilePaperworkViewProps, KeyBalanceBar, KeyBalanceBarProps, KeyCard, KeyCardProps, KeyDetailView, KeyDetailViewProps, KeyList, KeyListProps, KeyUtilsProvider, KeyUtilsProviderProps, KeysPanel, KeysPanelProps, MintSuccess, MintSuccessProps, SellPanel, SellPanelProps, SolanaPayButton, SolanaPayButtonProps, TransferPanel, TransferPanelProps, UsePanel, UsePanelProps, useKeyUtilsContext } from './components/index.cjs';
4
+ export { ASCII_KEY_ART, BottomSheet, BottomSheetProps, BuyKeyWidget, BuyKeyWidgetProps, BuyPanel, BuyPanelProps, DefaultKeyArt, DefaultKeyArtProps, FilePaperworkList, FilePaperworkListProps, FilePaperworkView, FilePaperworkViewProps, KeyBalanceBar, KeyBalanceBarProps, KeyCard, KeyCardProps, KeyDetailView, KeyDetailViewProps, KeyList, KeyListProps, KeyUtilsProvider, KeyUtilsProviderProps, KeysPanel, KeysPanelProps, MintSuccess, MintSuccessProps, SellPanel, SellPanelProps, SolanaPayButton, SolanaPayButtonProps, TransferPanel, TransferPanelProps, UsePanel, UsePanelProps, useKeyUtilsContext } from './components/index.cjs';
5
5
  export { HeaderProvider, KeyClient, KeyClientConfig, createKeyClient } from './core/index.cjs';
6
6
  import 'clsx';
7
7
  import 'react/jsx-runtime';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { DirectTransferResult, EligibleKey, FilingHistoryEntry, FilingResult, FilingStatus, KeyListing, KeyUtilsCallbacks, KeyUtilsConfig, KeyWidgetTab, LedgerEntry, ListingResult, MintResult, NodeKeyInfo, PaymentMethod, Platform, PlatformDownload, PricingInfo } from './types/index.js';
2
2
  export { MAX_ERROR_LEN, calculateBalancePercentage, clampErrorMessage, cn, csrfHeaders, detectPlatform, formatDate, formatTokens, getBalanceColor, readErrorMessage, safeUrl } from './utils/index.js';
3
3
  export { useFilePaperwork, useFilingHistory, useKeyLedger, useKeys, useListKey, useMintKey, usePricing, useSolanaPayment, useStripeCheckout, useTransferKey } from './hooks/index.js';
4
- export { BottomSheet, BottomSheetProps, BuyKeyWidget, BuyKeyWidgetProps, BuyPanel, BuyPanelProps, FilePaperworkList, FilePaperworkListProps, FilePaperworkView, FilePaperworkViewProps, KeyBalanceBar, KeyBalanceBarProps, KeyCard, KeyCardProps, KeyDetailView, KeyDetailViewProps, KeyList, KeyListProps, KeyUtilsProvider, KeyUtilsProviderProps, KeysPanel, KeysPanelProps, MintSuccess, MintSuccessProps, SellPanel, SellPanelProps, SolanaPayButton, SolanaPayButtonProps, TransferPanel, TransferPanelProps, UsePanel, UsePanelProps, useKeyUtilsContext } from './components/index.js';
4
+ export { ASCII_KEY_ART, BottomSheet, BottomSheetProps, BuyKeyWidget, BuyKeyWidgetProps, BuyPanel, BuyPanelProps, DefaultKeyArt, DefaultKeyArtProps, FilePaperworkList, FilePaperworkListProps, FilePaperworkView, FilePaperworkViewProps, KeyBalanceBar, KeyBalanceBarProps, KeyCard, KeyCardProps, KeyDetailView, KeyDetailViewProps, KeyList, KeyListProps, KeyUtilsProvider, KeyUtilsProviderProps, KeysPanel, KeysPanelProps, MintSuccess, MintSuccessProps, SellPanel, SellPanelProps, SolanaPayButton, SolanaPayButtonProps, TransferPanel, TransferPanelProps, UsePanel, UsePanelProps, useKeyUtilsContext } from './components/index.js';
5
5
  export { HeaderProvider, KeyClient, KeyClientConfig, createKeyClient } from './core/index.js';
6
6
  import 'clsx';
7
7
  import 'react/jsx-runtime';