@stacknet/keyutils 0.4.8 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/index.cjs +2 -2
- package/dist/components/index.d.cts +94 -15
- package/dist/components/index.d.ts +94 -15
- package/dist/components/index.js +2 -2
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.js +1 -1
- package/dist/hooks/index.cjs +2 -2
- package/dist/hooks/index.d.cts +104 -8
- package/dist/hooks/index.d.ts +104 -8
- package/dist/hooks/index.js +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/types/index.d.cts +100 -1
- package/dist/types/index.d.ts +100 -1
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.cts +58 -3
- package/dist/utils/index.d.ts +58 -3
- package/dist/utils/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var rr=require('react'),jsxRuntime=require('react/jsx-runtime'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),lucideReact=require('lucide-react');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var rr__default=/*#__PURE__*/_interopDefault(rr);var et=rr.createContext(null);function C(){let e=rr.useContext(et);if(!e)throw new Error("useKeyUtilsContext must be used within a KeyUtilsProvider");return e}function Ie({config:e,callbacks:t={},children:r}){typeof e.apiBaseUrl!="string"&&console.error("[KeyUtils] apiBaseUrl must be a string");let s=rr.useMemo(()=>({config:e,callbacks:t}),[e,t]);return jsxRuntime.jsx(et.Provider,{value:s,children:r})}function Y(){if(typeof document>"u")return {};let e=document.cookie.match(/(?:^|;\s*)__csrf=([^;]*)/);return e?{"x-csrf-token":e[1]}:{}}function tt(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 L(e,t){try{let r=await e.json();if(r&&typeof r=="object"&&"error"in r)return tt(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 l(...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 rt(e,t){return t<=0?0:Math.min(100,Math.round(e/t*100))}function st(e){return e>=70?"bg-green-500":e>=30?"bg-yellow-500":"bg-red-500"}function G(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 nt(){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"}function at(){let{config:e}=C(),[t,r]=rr.useState(null),[s,g]=rr.useState(true),[d,c]=rr.useState(null),i=rr.useRef(true),n=rr.useRef(e.apiBaseUrl);n.current=e.apiBaseUrl;let o=async()=>{try{i.current&&(g(!0),c(null));let m=await fetch(`${n.current}/api/keys/pricing`,{credentials:"include"});if(!m.ok)throw new Error(await L(m,`Pricing unavailable (${m.status})`));let u=await m.json();i.current&&r(u);}catch(m){i.current&&c(m instanceof Error?m.message:"Failed to fetch pricing");}finally{i.current&&g(false);}};return rr.useEffect(()=>{i.current=true,o();let m=setInterval(o,6e4);return ()=>{i.current=false,clearInterval(m);}},[]),{pricing:t,loading:s,error:d,refresh:o}}function it(){let{config:e,callbacks:t}=C(),[r,s]=rr.useState(false),[g,d]=rr.useState(null),[c,i]=rr.useState(null);return {mint:rr.useCallback(async(o,m,u=1)=>{try{s(!0),i(null),t.onPaymentComplete?.(o,m);let f=await fetch(`${e.apiBaseUrl}/api/keys/mint`,{method:"POST",headers:{"Content-Type":"application/json",...Y()},credentials:"include",body:JSON.stringify({paymentMethod:o,paymentRef:m,quantity:u,stackId:e.stackId})});if(!f.ok)throw new Error(await L(f,`Key generation failed (${f.status})`));let a=await f.json(),p=a.keys?.[0]||a,v={success:!0,key:{id:p.keyId||p.id||"",key:p.key||"",userId:p.userId||"",status:"active",tokenBalance:p.tokenBalance??p.currentTokenBalance??0,maxTokens:p.initialTokenBalance??p.tokenBalance??0,createdAt:String(p.createdAt||Date.now())},transactionId:m};return d(v),t.onMintSuccess?.(v),v}catch(f){let a=f instanceof Error?f:new Error("Key generation failed");return i(a.message),t.onMintError?.(a),{success:false,error:a.message}}finally{s(false);}},[e.apiBaseUrl,t]),minting:r,result:g,error:c}}function ct(){let{config:e}=C(),[t,r]=rr.useState(false),[s,g]=rr.useState(null),d=rr.useRef(true);return {createSession:rr.useCallback(async(i,n)=>{try{r(!0),g(null);let o=await fetch(`${e.apiBaseUrl}/api/keys/stripe-session`,{method:"POST",headers:{"Content-Type":"application/json",...Y()},credentials:"include",body:JSON.stringify({priceCents:i,quantity:n,stackId:e.stackId,referrerUrl:window.location.href})});if(!o.ok)throw new Error(await L(o,`Checkout failed (${o.status})`));let{url:m}=await o.json();if(!m)throw new Error("No checkout URL returned");let u;try{u=new URL(m);}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(o){if(d.current){let m=o instanceof Error?o.message:"Checkout failed";g(m),r(false);}}},[e.apiBaseUrl,e.stackId]),loading:t,error:s}}var ut=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function Be({amountSol:e,onSuccess:t,onError:r,disabled:s,className:g,style:d}){let{config:c}=C(),[i,n]=rr.useState(false),[o,m]=rr.useState(null),u=!!(c.merchantWallet&&ut.test(c.merchantWallet)),f=rr.useCallback(async()=>{if(u)try{n(!0),m(null);let{Connection:a,PublicKey:p,Transaction:v,SystemProgram:T,LAMPORTS_PER_SOL:w}=await import('@solana/web3.js'),E=typeof window<"u"?window.solana:void 0;if(!E||typeof E!="object"||!E.isPhantom)throw new Error("Phantom wallet not found. Please install Phantom.");let $=E,P;try{P=new p(c.merchantWallet);}catch{throw new Error("Invalid merchant wallet address.")}let re=await $.connect(),M=new p(re.publicKey.toString()),A="https://api.mainnet-beta.solana.com",se=F(c.solanaRpcUrl,A),ce=se==="#"?A:se,Re=new a(ce),{blockhash:W}=await Re.getLatestBlockhash(),ee=BigInt(Math.floor(e*1e9)),de=c.protocolTreasuryWallet,me=c.protocolFeeBps??500,ue=new v({recentBlockhash:W,feePayer:M});if(de&&ut.test(de)&&me>0){let Ze=ee*BigInt(me)/10000n,_t=ee-Ze,At=new p(de);ue.add(T.transfer({fromPubkey:M,toPubkey:P,lamports:Number(_t)}),T.transfer({fromPubkey:M,toPubkey:At,lamports:Number(Ze)}));}else ue.add(T.transfer({fromPubkey:M,toPubkey:P,lamports:Number(ee)}));let{signature:ye}=await $.signAndSendTransaction(ue);t(ye);}catch(a){let p=a instanceof Error?a:new Error("Payment failed");m(p.message),r?.(p);}finally{n(false);}},[e,c.merchantWallet,u,t,r]);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("button",{onClick:f,disabled:s||i||!u,"aria-label":`Pay ${e.toFixed(4)} SOL`,className:l("flex w-full items-center justify-center gap-2 rounded-2xl bg-purple-600 py-6 text-base font-semibold text-white transition-colors hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed",g),style:d,children:i?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"]})}),o&&jsxRuntime.jsx("p",{className:"mt-2 text-center text-xs text-red-500",children:o})]})}function Ee({result:e,className:t,style:r}){let[s,g]=rr.useState(false),d=rr.useRef(null);rr.useEffect(()=>()=>{d.current&&clearTimeout(d.current);},[]);let c=rr.useCallback(()=>{e.key?.key&&(navigator.clipboard.writeText(e.key.key),g(true),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>g(false),2e3));},[e.key?.key]);return !e.success||!e.key?null:jsxRuntime.jsxs("div",{className:l("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:c,"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 X({className:e}){return jsxRuntime.jsx("div",{className:l("animate-pulse rounded-xl bg-muted",e)})}function _e(){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(X,{className:"h-14 w-48"}),jsxRuntime.jsx(X,{className:"h-5 w-64"})]}),jsxRuntime.jsx(X,{className:"h-[72px] w-full rounded-2xl"}),jsxRuntime.jsx(X,{className:"h-[68px] w-full rounded-2xl"}),jsxRuntime.jsx(X,{className:"h-[60px] w-full rounded-2xl"})]})}function ne({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(X,{className:"h-4 w-32"}),jsxRuntime.jsx(X,{className:"h-4 w-16"})]}),jsxRuntime.jsx(X,{className:"h-2 w-full rounded-full"}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(X,{className:"h-3 w-24"}),jsxRuntime.jsx(X,{className:"h-3 w-20"})]})]},r))})}function dr({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 gt({pricing:e,quantity:t}){let[r,s]=rr.useState(false),g=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:["$",g.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:["$",g.toFixed(2)]})]})]})]})}function Ae({className:e,style:t}){let{config:r}=C(),{pricing:s,loading:g,error:d,refresh:c}=at(),{mint:i,minting:n,result:o,error:m}=it(),{createSession:u,loading:f,error:a}=ct(),[p,v]=rr.useState(1),[T,w]=rr.useState(r.paymentMethods?.includes("stripe")?"stripe":"solana"),[E,$]=rr.useState(0),[P,re]=rr.useState(false),M=rr__default.default.useRef(p);M.current=p;let A=Math.max(1,r.maxQuantity||5),se=[...r.paymentMethods||["solana"]].sort((W,ee)=>W==="stripe"?-1:ee==="stripe"?1:0);if(rr.useEffect(()=>{if(typeof window>"u")return;let ee=new URLSearchParams(window.location.search).get("session_id");if(!ee){try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}return}if(/^cs_(test|live)_/.test(ee)&&!P&&!o?.success){let de=false;try{de=sessionStorage.getItem("keyutils_stripe_pending")==="1";}catch{}if(!de)return;try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}re(true);let me=new URL(window.location.href);me.searchParams.delete("session_id"),window.history.replaceState({},"",me.toString());let ue=M.current;try{let ye=sessionStorage.getItem("keyutils_stripe_quantity");ye&&(ue=parseInt(ye,10)||1,sessionStorage.removeItem("keyutils_stripe_quantity"));}catch{}i("stripe",ee,ue);}},[P,o,i]),o?.success)return jsxRuntime.jsx("div",{className:l("flex flex-col items-center justify-center",e),style:t,children:jsxRuntime.jsx(Ee,{result:o})});if(P||n)return jsxRuntime.jsx("div",{className:l("flex flex-col",e),style:t,children:jsxRuntime.jsx(_e,{})});if(g)return jsxRuntime.jsx("div",{className:l("flex flex-col",e),style:t,children:jsxRuntime.jsx(_e,{})});if(d||!s)return jsxRuntime.jsxs("div",{className:l("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:d||"Please check your connection and try again."})]}),jsxRuntime.jsx("button",{onClick:()=>c(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]});let ce=async W=>{$(2),await i(T,W,p);},Re=()=>{u(s.priceCents,p);};return jsxRuntime.jsx("div",{className:l("flex flex-col",e),style:t,children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[E===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(dr,{quantity:p,max:A,onChange:v}),jsxRuntime.jsx(gt,{pricing:s,quantity:p}),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"})]}),E===1&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[se.length>1&&jsxRuntime.jsx("div",{role:"tablist",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:se.map(W=>jsxRuntime.jsxs("button",{role:"tab","aria-selected":T===W,onClick:()=>w(W),className:l("flex flex-1 items-center justify-center gap-2.5 rounded-xl py-4 text-sm font-medium transition-colors",T===W?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[W==="stripe"?jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-5 w-5"}):jsxRuntime.jsx(lucideReact.Wallet,{className:"h-5 w-5"}),W==="stripe"?"Credit Card":"Crypto"]},W))}),jsxRuntime.jsx(gt,{pricing:s,quantity:p}),T==="stripe"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{onClick:Re,disabled:f,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:f?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"]})}),a&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-500",children:a})]}):T==="solana"?jsxRuntime.jsx(Be,{amountSol:s.priceSol??0,onSuccess:ce}):null,m&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-500",children:m}),jsxRuntime.jsx("button",{type:"button",onClick:()=>$(0),className:"w-full rounded-2xl border border-border bg-transparent py-3 text-center text-sm font-medium text-foreground transition-colors hover:bg-muted/30",children:"Cancel"})]})]})})}var pr={ios:"iOS",android:"Android",windows:"Windows",mac:"macOS",linux:"Linux"},gr=["mac","windows","linux","ios","android"],xr="https://www.stacknet.org/download";function Me({downloads:e,className:t,style:r}){let{config:s}=C(),g=rr.useMemo(()=>nt(),[]),d=e||gr.map(n=>({platform:n,label:pr[n],url:xr,compatible:n===g})),c=d.find(n=>n.compatible)||d[0],i=d.filter(n=>n.platform!==c.platform);return jsxRuntime.jsxs("div",{className:l("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(c.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 ",c.label]})]}),jsxRuntime.jsxs("p",{className:"text-center text-sm text-muted-foreground",children:["aiSP is also available on"," ",i.map((n,o)=>jsxRuntime.jsxs(rr__default.default.Fragment,{children:[o>0&&(o===i.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 Nr(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 q(){let{config:e}=C(),[t,r]=rr.useState([]),[s,g]=rr.useState(true),[d,c]=rr.useState(null),i=rr.useRef(true),n=e.apiBaseUrl,o=rr.useCallback(async()=>{try{g(!0),c(null);let u=await fetch(`${n}/api/keys`,{credentials:"include"});if(!u.ok)throw new Error(await L(u,`Failed to fetch keys (${u.status})`));let f=await u.json(),a=Array.isArray(f)?f:f.keys??[];i.current&&r(a.map(Nr));}catch(u){i.current&&c(u instanceof Error?u.message:"Failed to fetch keys");}finally{i.current&&g(false);}},[n]);rr.useEffect(()=>(i.current=true,o(),()=>{i.current=false;}),[o]);let m=t.reduce((u,f)=>u+f.tokenBalance,0);return {keys:t,totalBalance:m,loading:s,error:d,refresh:o}}var vr={"bg-green-500":"bg-green-900/50","bg-yellow-500":"bg-yellow-900/50","bg-red-500":"bg-red-900/50"};function J({current:e,max:t,className:r,style:s,showLabel:g=true,segments:d=40}){let c=rt(e,t),i=st(c),n=vr[i]||"bg-muted",o=Math.round(c/100*d);return jsxRuntime.jsxs("div",{className:l("w-full",r),style:s,children:[g&&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:[c,"%"]})]}),jsxRuntime.jsx("div",{className:"flex h-6 w-full items-stretch gap-1",children:Array.from({length:d}).map((m,u)=>jsxRuntime.jsx("div",{className:l("flex-1 rounded-[1px] transition-colors duration-300",u<o?i:n)},u))})]})}function ke(){let{config:e,callbacks:t}=C(),[r,s]=rr.useState(false),[g,d]=rr.useState(null),[c,i]=rr.useState(null),n=rr.useRef(true),o=rr.useCallback(async(u,f)=>{try{s(!0),i(null);let a=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/list`,{method:"POST",headers:{"Content-Type":"application/json",...Y()},credentials:"include",body:JSON.stringify({askPriceCents:f,stackId:e.stackId,stackName:e.stackName})});if(!a.ok)throw new Error(await L(a,`Listing failed (${a.status})`));let p=await a.json();return n.current&&(d(p),t.onListingCreated?.(p)),p}catch(a){let p=a instanceof Error?a.message:"Listing failed";return n.current&&i(p),null}finally{n.current&&s(false);}},[e.apiBaseUrl,e.stackId,e.stackName,t]),m=rr.useCallback(async u=>{try{s(!0),i(null);let f=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/list`,{method:"DELETE",headers:{...Y()},credentials:"include"});if(!f.ok)throw new Error(await L(f,`Delist failed (${f.status})`));return n.current&&d(null),!0}catch(f){let a=f instanceof Error?f.message:"Delist failed";return n.current&&i(a),false}finally{n.current&&s(false);}},[e.apiBaseUrl]);return {listKey:o,delistKey:m,listing:r,result:g,error:c}}function Ne(){let{config:e,callbacks:t}=C(),[r,s]=rr.useState(false),[g,d]=rr.useState(null),[c,i]=rr.useState(null),n=rr.useRef(true);return {transferKey:rr.useCallback(async(m,u)=>{try{s(!0),i(null);let f=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(m)}/transfer`,{method:"POST",headers:{"Content-Type":"application/json",...Y()},credentials:"include",body:JSON.stringify({recipientId:u})});if(!f.ok)throw new Error(await L(f,`Transfer failed (${f.status})`));let a=await f.json();return n.current&&(d(a),t.onTransferComplete?.(a)),a}catch(f){let a=f instanceof Error?f.message:"Transfer failed";return n.current&&i(a),null}finally{n.current&&s(false);}},[e.apiBaseUrl,t]),transferring:r,result:g,error:c}}function bt(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||Cr(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 Cr(e){switch(e){case "credit":return "Credit";case "debit":return "Usage";case "mint":return "Mint";case "reward":return "Reward";default:return ""}}function ve(e){let{config:t}=C(),[r,s]=rr.useState([]),[g,d]=rr.useState(false),[c,i]=rr.useState(null),n=rr.useRef(true),o=t.apiBaseUrl,m=rr.useCallback(async()=>{if(e)try{d(!0),i(null);let u=await fetch(`${o}/api/keys/${encodeURIComponent(e)}/ledger`,{credentials:"include"});if(!u.ok)throw new Error(await L(u,`Failed to fetch ledger (${u.status})`));let f=await u.json(),a=Array.isArray(f)?f:f.entries??[];n.current&&s(a.map(bt));}catch(u){n.current&&i(u instanceof Error?u.message:"Failed to fetch ledger");}finally{n.current&&d(false);}},[o,e]);return rr.useEffect(()=>(n.current=true,m(),()=>{n.current=false;}),[m]),{entries:r,loading:g,error:c,refresh:m}}function xe({open:e,onClose:t,title:r,children:s}){let g=rr.useRef(null),[d,c]=rr.useState(false),[i,n]=rr.useState(false),o=rr.useCallback(m=>{m.key==="Escape"&&t();},[t]);return rr.useEffect(()=>{if(e)c(true),document.addEventListener("keydown",o),document.body.style.overflow="hidden",requestAnimationFrame(()=>{requestAnimationFrame(()=>n(true));});else {n(false);let m=setTimeout(()=>{c(false),document.body.style.overflow="";},300);return document.removeEventListener("keydown",o),()=>clearTimeout(m)}return ()=>{document.removeEventListener("keydown",o);}},[e,o]),d?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:i?1:0},onClick:t}),jsxRuntime.jsxs("div",{ref:g,className:l("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:i?"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 we=[" .-----."," / (_) \\"," / \\","( )"," \\ /"," \\_______/"," || |"," || |"," || /"," || /"," || \\"," || /"," || /"," \\// "],We=16,Br=We*.6,Nt=We*1;function He({className:e,style:t,color:r="currentColor",ariaLabel:s="Node key",keyImage:g,keyImageClass:d}){if(g)return jsxRuntime.jsx("img",{src:F(g),alt:s,className:l(d||"h-20 w-auto mx-auto",e),style:t});let c=we.reduce((f,a)=>Math.max(f,a.length),0),i=we.length,n=c*Br,m=i*Nt;return jsxRuntime.jsx("svg",{viewBox:`0 0 ${m} ${n}`,xmlns:"http://www.w3.org/2000/svg",className:l("block",e),style:t,role:"img","aria-label":s,preserveAspectRatio:"xMidYMid meet",children:jsxRuntime.jsx("g",{transform:`translate(0 ${n}) rotate(-90)`,children:we.map((f,a)=>jsxRuntime.jsx("text",{x:0,y:(a+.8)*Nt,fill:r,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:We,xmlSpace:"preserve",children:f},a))})})}function Mr({nodeKey:e,onSuccess:t}){let{transferKey:r,transferring:s,result:g,error:d}=Ne(),[c,i]=rr.useState(""),[n,o]=rr.useState(false),m=c.trim()===e.userId,u=c.trim().length>0&&n&&!m&&!s,f=async()=>{if(!u)return;await r(e.id,c.trim())&&t();};return g?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:c,onChange:a=>{i(a.target.value),o(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"}),m&&jsxRuntime.jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),c.trim().length>0&&!m&&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:[c.trim().slice(0,20),c.trim().length>20?"...":""]})]})]}),jsxRuntime.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:n,onChange:a=>o(a.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."})]})]})]})}),d&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:d}),jsxRuntime.jsx("button",{onClick:f,disabled:!u,className:l("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 Fr({nodeKey:e,onSuccess:t}){let{config:r}=C(),{listKey:s,listing:g,result:d,error:c}=ke(),[i,n]=rr.useState(""),[o,m]=rr.useState(false),u=parseInt(i.replace(/[^0-9]/g,""),10)||0,a=u>0&&Number.isFinite(u)&&o&&!g,p=async()=>{if(!a)return;let v=u*100;await s(e.id,v)&&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:"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:d.listingId})]}),jsxRuntime.jsxs("a",{href:`https://market.stacknet.org/keys/${encodeURIComponent(d.keyId)}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 rounded-xl bg-foreground px-6 py-3 text-sm font-semibold text-background transition-colors hover:bg-foreground/90",children:[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:i,onChange:v=>{let T=v.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":o,onClick:()=>m(!o),className:l("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",o?"border-foreground bg-foreground":"border-muted-foreground/40"),children:o&&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"})]})]}),c&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:c}),jsxRuntime.jsxs("button",{onClick:p,disabled:!a,className:l("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",a?"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"}),g?"Listing...":"List on Marketplace"]})]})}function jr({nodeKey:e}){let[t,r]=rr.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 Ye({nodeKey:e,onBack:t,onKeysChanged:r,className:s,style:g}){let {config:d}=C();ve(e.id);let [n,o]=rr.useState(null),[m,u]=rr.useState(false),f=()=>{o(null),r?.();},a=()=>{e.key&&(navigator.clipboard.writeText(e.key),u(true),setTimeout(()=>u(false),2e3));},p=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsxRuntime.jsxs("div",{className:l("space-y-5",s),style:g,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"}),"View All"]}),jsxRuntime.jsx(He,{className:l("mx-auto text-foreground px-0 sm:px-0",d.keyImage?"w-2/3 h-auto":"h-20 w-auto"),keyImage:d.keyImage,keyImageClass:d.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:l("text-sm font-medium capitalize",p),children:e.status})]})}),e.key&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("code",{className:"flex-1 truncate px-3 py-2 text-lg text-muted-foreground",children:e.key}),jsxRuntime.jsx("button",{onClick:a,"aria-label":"Copy key",className:"shrink-0 rounded-lg p-2 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",children:m?jsxRuntime.jsx(lucideReact.Check,{className:"h-4 w-4 text-green-500"}):jsxRuntime.jsx(lucideReact.Copy,{className:"h-4 w-4"})})]}),jsxRuntime.jsx(J,{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:[(d.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||d.stackName})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Created"}),jsxRuntime.jsx("span",{className:"text-foreground",children:G(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:G(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:()=>o("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:()=>o("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:()=>o("file"),className:l("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(xe,{open:n==="transfer",onClose:()=>o(null),title:"Transfer Key",children:jsxRuntime.jsx(Mr,{nodeKey:e,onSuccess:f})}),jsxRuntime.jsx(xe,{open:n==="sell",onClose:()=>o(null),title:"Sell Key",children:jsxRuntime.jsx(Fr,{nodeKey:e,onSuccess:f})}),jsxRuntime.jsx(xe,{open:n==="file",onClose:()=>o(null),title:"File Paperwork",children:jsxRuntime.jsx(jr,{nodeKey:e})})]})}function $r({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:l("text-xs font-medium capitalize",r),children:e.status})]}),jsxRuntime.jsx(J,{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 ze({className:e,style:t}){let{keys:r,loading:g,error:d,refresh:c}=q(),[i,n]=rr.useState(null),[o,m]=rr.useState("active"),u=r.filter(p=>p.status===o),f=u.reduce((p,v)=>p+v.tokenBalance,0),a=r.find(p=>p.id===i);return a?jsxRuntime.jsx(Ye,{nodeKey:a,onBack:()=>n(null),onKeysChanged:()=>{n(null),c();},className:e,style:t}):g?jsxRuntime.jsxs("div",{className:l("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(ne,{count:3})]}):d?jsxRuntime.jsxs("div",{className:l("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:d})]}),jsxRuntime.jsx("button",{onClick:()=>c(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]}):r.length===0?jsxRuntime.jsxs("div",{className:l("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:l("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:"hidden text-xs text-muted-foreground sm:inline",children:[u.length," key",u.length!==1?"s":""," \xB7 ",K(f)," tokens"]}),jsxRuntime.jsx("div",{className:"flex gap-1 rounded-lg bg-muted/50 p-1",children:["active","listed"].map(p=>jsxRuntime.jsx("button",{onClick:()=>m(p),className:l("rounded-md px-3 py-1 text-xs font-medium capitalize transition-all",o===p?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:p},p))})]}),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 ",o," keys."]})]}):jsxRuntime.jsx("div",{className:"space-y-2",children:u.map(p=>jsxRuntime.jsx($r,{nodeKey:p,onClick:()=>n(p.id)},p.id))})]})}var Or=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function Wr({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:Or.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:l("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 Hr({defaultTab:e="buy",className:t,style:r}){let[s,g]=rr.useState(e);return jsxRuntime.jsxs("div",{className:l("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(Wr,{active:s,onChange:g})})}),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(Ae,{className:"flex-1"}),s==="use"&&jsxRuntime.jsx(Me,{className:"flex-1"}),s==="keys"&&jsxRuntime.jsx(ze,{className:"flex-1"})]})})})]})}function Vr({apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:s,merchantWallet:g,stripePublicKey:d,theme:c,maxQuantity:i,keyImage:n,keyImageClass:o,aispImage:m,termsUrl:u,onMintSuccess:f,onMintError:a,onPaymentStart:p,onPaymentComplete:v,onListingCreated:T,onTransferComplete:w,defaultTab:E,className:$,style:P}){return jsxRuntime.jsx(Ie,{config:{apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:s,merchantWallet:g,stripePublicKey:d,theme:c,maxQuantity:i,keyImage:n,keyImageClass:o,aispImage:m,termsUrl:u},callbacks:{onMintSuccess:f,onMintError:a,onPaymentStart:p,onPaymentComplete:v,onListingCreated:T,onTransferComplete:w},children:jsxRuntime.jsx(Hr,{defaultTab:E,className:$,style:P})})}function qr({nodeKey:e,selected:t,onSelect:r}){return jsxRuntime.jsxs("button",{onClick:r,className:l("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:l("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:l("text-xs font-medium capitalize",e.status==="active"?"text-green-500":"text-muted-foreground"),children:e.status})]}),jsxRuntime.jsx(J,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function Gr({className:e,style:t}){let{config:r}=C(),{keys:s,loading:g,error:d,refresh:c}=q(),{listKey:i,listing:n,result:o,error:m}=ke(),[u,f]=rr.useState(null),[a,p]=rr.useState(""),[v,T]=rr.useState(false),w=s.find(A=>A.id===u),E=parseInt(a.replace(/[^0-9]/g,""),10)||0,$=E>0&&Number.isFinite(E),P=!!w&&$&&v&&!n,re=async()=>{if(!P||!w)return;let A=E*100;await i(w.id,A)&&c();};if(o)return jsxRuntime.jsxs("div",{className:l("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:o.listingId})]}),jsxRuntime.jsxs("a",{href:`https://market.stacknet.org/keys/${encodeURIComponent(o.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(g)return jsxRuntime.jsxs("div",{className:l("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(ne,{count:2})]});if(d)return jsxRuntime.jsxs("div",{className:l("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:d})]}),jsxRuntime.jsx("button",{onClick:()=>c(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]});let M=s.filter(A=>A.status==="active");return M.length===0?jsxRuntime.jsxs("div",{className:l("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:l("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:M.map(A=>jsxRuntime.jsx(qr,{nodeKey:A,selected:u===A.id,onSelect:()=>f(A.id)},A.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:G(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:a,onChange:A=>{let se=A.target.value.replace(/[^0-9]/g,""),ce=parseInt(se,10);p(isNaN(ce)?"":ce.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":v,onClick:()=>T(!v),className:l("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",v?"border-foreground bg-foreground":"border-muted-foreground/40"),children:v&&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"})]})]}),m&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:m}),jsxRuntime.jsxs("button",{onClick:re,disabled:!P,className:l("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 Ge=20;function Je({nodeKey:e,className:t,style:r}){let[s,g]=rr.useState(false),[d,c]=rr.useState(false),i=rr.useRef(null),{entries:n,loading:o}=ve(s?e.id:null);rr.useEffect(()=>()=>{i.current&&clearTimeout(i.current);},[]);let m=rr.useCallback(()=>{e.key&&(navigator.clipboard.writeText(e.key),c(true),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>c(false),2e3));},[e.key]),u=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500",f=n.slice(0,Ge);return jsxRuntime.jsxs("div",{className:l("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:()=>g(!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:l("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:m,"aria-label":"Copy key to clipboard",className:"shrink-0 rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:d?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(J,{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 ",G(e.createdAt)]}),e.expiresAt&&jsxRuntime.jsxs("span",{children:["Expires ",G(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"}),o?jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading..."}):f.length===0?jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"No ledger entries."}):jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[f.map(a=>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:l("font-medium",a.type==="credit"||a.type==="reward"?"text-green-500":"text-red-500"),children:[a.type==="credit"||a.type==="reward"?"+":"-",K(Math.abs(a.amount))]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:a.description})]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:G(a.createdAt)})]},a.id)),n.length>Ge&&jsxRuntime.jsxs("p",{className:"pt-1 text-xs text-muted-foreground",children:["Showing ",Ge," of ",n.length," entries"]})]})]})]})}var ns=[{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:ns.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 os({getKeyHref:e="/keys/get",showTabs:t=true,className:r,style:s}){let{keys:g,totalBalance:d,loading:c,error:i,refresh:n}=q();return c?jsxRuntime.jsxs("div",{className:l("space-y-4",r),style:s,children:[t&&e&&jsxRuntime.jsx(Pe,{baseHref:e}),jsxRuntime.jsx(ne,{count:3})]}):i?jsxRuntime.jsxs("div",{className:l("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:i})]}),jsxRuntime.jsx("button",{onClick:()=>n(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]})]}):g.length===0?jsxRuntime.jsxs("div",{className:l("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:l("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:[g.length," key",g.length!==1?"s":""," \xB7 Total balance: ",K(d)]}),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"})]}),g.map(o=>jsxRuntime.jsx(Je,{nodeKey:o},o.id))]})}function ds({nodeKey:e,selected:t,onSelect:r}){return jsxRuntime.jsxs("button",{onClick:r,className:l("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:l("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(J,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function us({className:e,style:t}){let{keys:r,loading:s}=q(),{transferKey:g,transferring:d,result:c,error:i}=Ne(),[n,o]=rr.useState(null),[m,u]=rr.useState(""),[f,a]=rr.useState(false),p=r.filter(P=>P.status==="active"),v=p.find(P=>P.id===n),T=v&&m.trim()===v.userId,w=n&&m.trim().length>0&&f&&!T&&!d,E=async()=>{!n||!m.trim()||await g(n,m.trim());},$=()=>{o(null),u(""),a(false);};return c?jsxRuntime.jsxs("div",{className:l("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:[c.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:[c.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:l("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(ne,{count:2}):p.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:p.map(P=>jsxRuntime.jsx(ds,{nodeKey:P,selected:n===P.id,onSelect:()=>o(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:m,onChange:P=>{u(P.target.value),a(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"})]}),v&&m.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:v.keyIndex?`#${v.keyIndex}`:v.id.slice(0,12)})," ","(",K(v.tokenBalance)," tokens) to"," ",jsxRuntime.jsxs("span",{className:"font-mono font-medium",children:[m.trim().slice(0,20),"..."]})]})]}),jsxRuntime.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:f,onChange:P=>a(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."})]})]})]})}),i&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:i}),jsxRuntime.jsx("button",{onClick:E,disabled:!w,className:l("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:d?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 Et(){let{config:e,callbacks:t}=C(),[r,s]=rr.useState(false),[g,d]=rr.useState(null),[c,i]=rr.useState(null),n=rr.useRef(true),o=rr.useCallback(async u=>{try{s(!0),i(null);let f=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/file`,{method:"POST",headers:{"Content-Type":"application/json",...Y()},credentials:"include",body:JSON.stringify({stackId:e.stackId})});if(!f.ok)throw new Error(await L(f,`Filing failed (${f.status})`));let a=await f.json();return n.current&&(d(a),t.onFilingComplete?.(a)),a}catch(f){let a=f instanceof Error?f:new Error("Filing failed");return n.current&&i(a.message),t.onFilingError?.(a),null}finally{n.current&&s(false);}},[e.apiBaseUrl,e.stackId,t]),m=rr.useCallback(()=>{d(null),i(null);},[]);return {filePaperwork:o,filing:r,result:g,error:c,reset:m}}function Se(e,t=6,r=6){return !e||e.length<=t+r+1?e:`${e.slice(0,t)}\u2026${e.slice(-r)}`}function xs({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:[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:G(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 ys({keyId:e,paymentAddress:t,onComplete:r,onConfigurePayment:s,onBack:g,className:d,style:c}){let{config:i}=C(),{keys:n,loading:o,error:m,refresh:u}=q(),{filePaperwork:f,filing:a,result:p,error:v,reset:T}=Et(),w=n.find(M=>M.id===e),E=!!w?.paperWork&&w.paperWork.length>0,$=!!t&&t.length>0,P=E&&$&&!a&&!p,re=async()=>{if(!P||!w)return;let M=await f(w.id);M&&(u(),r?.(M));};return p?jsxRuntime.jsxs("div",{className:l("flex flex-col lg:flex-row",d),style:c,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:p.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:[(p.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(p.fileHash,10,10)})]}),p.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(p.txSignature)}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-foreground underline underline-offset-4",children:Se(p.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(p.beneficiary,6,6)})]})]}),g&&jsxRuntime.jsx("button",{type:"button",onClick:()=>{T(),g();},className:"w-full bg-foreground text-background py-4 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:"Back to dashboard"})]})]}):o?jsxRuntime.jsxs("div",{className:l("flex flex-col lg:flex-row",d),style:c,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"})]})]}):m||!w?jsxRuntime.jsxs("div",{className:l("flex flex-col lg:flex-row",d),style:c,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:m?"Unable to load keys":"Key not found"})]}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:m||`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:l("flex flex-col lg:flex-row",d),style:c,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(xs,{nodeKey:w,stackName:i.stackName}),!E&&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."]})]}),v&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:v}),jsxRuntime.jsx("button",{type:"button",onClick:re,disabled:!P,className:l("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:a?"Filing\u2026":"File Paperwork"})]})]})}function Ns(e){return typeof e.paperWork=="string"&&e.paperWork.length>0}function vs({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 hs({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 ws({onSelect:e,className:t,style:r}){let{keys:s,loading:g,error:d,refresh:c}=q();if(g)return jsxRuntime.jsx("div",{className:l("space-y-3",t),style:r,children:jsxRuntime.jsx(vs,{count:3})});if(d)return jsxRuntime.jsx("div",{className:l("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:d}),jsxRuntime.jsx("button",{type:"button",onClick:()=>c(),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 i=s.filter(Ns);return i.length===0?jsxRuntime.jsxs("div",{className:l("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:l("space-y-2",t),style:r,children:i.map(n=>jsxRuntime.jsx(hs,{nodeKey:n,onSelect:()=>e(n.id)},n.id))})}
|
|
2
|
-
exports.ASCII_KEY_ART=
|
|
1
|
+
'use strict';var jr=require('react'),jsxRuntime=require('react/jsx-runtime'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),lucideReact=require('lucide-react');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var jr__default=/*#__PURE__*/_interopDefault(jr);var kt=jr.createContext(null);function v(){let e=jr.useContext(kt);if(!e)throw new Error("useKeyUtilsContext must be used within a KeyUtilsProvider");return e}function Oe({config:e,callbacks:r={},children:t}){typeof e.apiBaseUrl!="string"&&console.error("[KeyUtils] apiBaseUrl must be a string");let n=jr.useMemo(()=>({config:e,callbacks:r}),[e,r]);return jsxRuntime.jsx(kt.Provider,{value:n,children:t})}var Nt=false;function $(){if(typeof document>"u")return {};let e=document.cookie.match(/(?:^|;\s*)__csrf=([^;]*)/);if(!e)return Nt||(Nt=true,console.warn("[keyutils] __csrf cookie not found; mutations will be sent without a CSRF token")),{};let r=e[1];try{r=decodeURIComponent(r);}catch{}return {"x-csrf-token":r}}function wt(e,r){if(typeof e!="string"||e.length===0)return r;let t=e.replace(/[\u0000-\u001F\u007F]/g," ");return t.length>500?t.slice(0,500)+"\u2026":t}async function R(e,r){try{let t=await e.json();if(t&&typeof t=="object"&&"error"in t)return wt(t.error,r)}catch{}return r}function j(e,r="#"){if(!e||typeof e!="string")return r;let t=e.trim();if(t===""||t==="#")return r;if(t.startsWith("/")||t.startsWith("./")||t.startsWith("../"))return t;try{let n=new URL(t);if(n.protocol==="http:"||n.protocol==="https:")return n.toString()}catch{}return r}var Ve={sent:"sent",routed:"routed",confirmed:"confirmed",finalized:"finalized",filed:"filed"},Ce={sent:{pending:"sent",progressing:"sending",done:"sent"},routed:{pending:"routed",progressing:"routing",done:"routed"},confirmed:{pending:"confirmed",progressing:"confirming",done:"confirmed"},finalized:{pending:"finalized",progressing:"finalizing",done:"finalized"},filed:{pending:"filed",progressing:"filing",done:"filed"}},Cr=["sent","routed","confirmed","finalized","filed"];function He(e){let r=new Map;(e??[]).forEach(o=>r.set(o.id,o));let t=Cr.map(o=>{let s=r.get(o);return s?{...s,label:s.label||Ve[o]}:{id:o,label:Ve[o],status:"pending",timestampMs:null,detail:null}}),n=t.reduce((o,s,a)=>s.status==="done"||s.status==="failed"?a:o,-1);if(n>0)for(let o=0;o<n;o++)t[o].status!=="failed"&&(t[o]={...t[o],status:"done"});if(!t.some(o=>o.status==="failed")){let o=t.findIndex(s=>s.status!=="done");if(o>=0){let s=t[o];s.status!=="current"&&(t[o]={...s,status:"current"});}}return t}function Pt(e){return e.find(r=>r.status==="current")??null}function Ct(e){return e.length>0&&e.every(r=>r.status==="done")}function St(e){return e.some(r=>r.status==="failed")}function We(e,r){if(!r)return {text:"loading",playing:true,stepId:"sent"};if(St(e))return {text:"failed",playing:false,stepId:"filed"};if(Ct(e))return {text:Ce.filed.done,playing:false,stepId:"filed"};let n=Pt(e)?.id??"sent";return {text:Ce[n].progressing,playing:true,stepId:n}}function m(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function B(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 Rt(e,r){return r<=0?0:Math.min(100,Math.round(e/r*100))}function Tt(e){return e>=70?"bg-green-500":e>=30?"bg-yellow-500":"bg-red-500"}function Ee(e,r={}){let t=r.withSymbol!==false,n=Math.max(0,Math.min(6,r.maxDecimals??2));if(e==null||e==="")return t?"$0.00":"0.00";let l;try{if(typeof e=="bigint")l=e;else if(typeof e=="number")l=BigInt(Math.trunc(e));else {let c=String(e).trim().replace(/^\+/,"");if(/^-?\d+$/.test(c))l=BigInt(c);else {let g=Number(c);if(!Number.isFinite(g))return t?"$0.00":"0.00";l=BigInt(Math.trunc(g));}}}catch{return t?"$0.00":"0.00"}let o=l<0n,s=o?-l:l,a=s/1000000n,d=(s%1000000n).toString().padStart(6,"0").slice(0,n),f=a.toLocaleString("en-US"),u=n>0?`.${d}`:"";return `${o?"-":""}${t?"$":""}${f}${u}`}function X(e){if(e==null||e==="")return "";let r=typeof e=="string"&&/^\d+$/.test(e)?Number(e):e,t=new Date(r);return isNaN(t.getTime())?"":t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function It(){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"}function Et(){let{config:e}=v(),[r,t]=jr.useState(null),[n,l]=jr.useState(true),[o,s]=jr.useState(null),a=jr.useRef(true),i=jr.useRef(e.apiBaseUrl);i.current=e.apiBaseUrl;let d=async()=>{try{a.current&&(l(!0),s(null));let f=await fetch(`${i.current}/api/keys/pricing`,{credentials:"include"});if(!f.ok)throw new Error(await R(f,`Pricing unavailable (${f.status})`));let u=await f.json();a.current&&t(u);}catch(f){a.current&&s(f instanceof Error?f.message:"Failed to fetch pricing");}finally{a.current&&l(false);}};return jr.useEffect(()=>{a.current=true,d();let f=setInterval(d,6e4);return ()=>{a.current=false,clearInterval(f);}},[]),{pricing:r,loading:n,error:o,refresh:d}}function Kt(){let{config:e,callbacks:r}=v(),[t,n]=jr.useState(false),[l,o]=jr.useState(null),[s,a]=jr.useState(null);return {mint:jr.useCallback(async(d,f,u=1)=>{try{n(!0),a(null),r.onPaymentComplete?.(d,f);let p=await fetch(`${e.apiBaseUrl}/api/keys/mint`,{method:"POST",headers:{"Content-Type":"application/json",...$()},credentials:"include",body:JSON.stringify({paymentMethod:d,paymentRef:f,quantity:u,stackId:e.stackId})});if(!p.ok)throw new Error(await R(p,`Key generation failed (${p.status})`));let c=await p.json(),g=c.keys?.[0]||c,y={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:f};return o(y),r.onMintSuccess?.(y),y}catch(p){let c=p instanceof Error?p:new Error("Key generation failed");return a(c.message),r.onMintError?.(c),{success:false,error:c.message}}finally{n(false);}},[e.apiBaseUrl,r]),minting:t,result:l,error:s}}function Bt(){let{config:e}=v(),[r,t]=jr.useState(false),[n,l]=jr.useState(null),o=jr.useRef(true);return {createSession:jr.useCallback(async(a,i)=>{try{t(!0),l(null);let d=await fetch(`${e.apiBaseUrl}/api/keys/stripe-session`,{method:"POST",headers:{"Content-Type":"application/json",...$()},credentials:"include",body:JSON.stringify({priceCents:a,quantity:i,stackId:e.stackId,referrerUrl:window.location.href})});if(!d.ok)throw new Error(await R(d,`Checkout failed (${d.status})`));let{url:f}=await d.json();if(!f)throw new Error("No checkout URL returned");let u;try{u=new URL(f);}catch{throw new Error("Invalid checkout URL")}if(u.protocol!=="https:"||!/(^|\.)stripe\.com$/.test(u.hostname))throw new Error("Refusing to redirect to non-Stripe URL");try{sessionStorage.setItem("keyutils_stripe_pending","1"),sessionStorage.setItem("keyutils_stripe_quantity",String(i));}catch{}window.location.href=u.toString();}catch(d){if(o.current){let f=d instanceof Error?d.message:"Checkout failed";l(f),t(false);}}},[e.apiBaseUrl,e.stackId]),loading:r,error:n}}var At=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function Ge({amountSol:e,onSuccess:r,onError:t,disabled:n,className:l,style:o}){let{config:s}=v(),[a,i]=jr.useState(false),[d,f]=jr.useState(null),u=!!(s.merchantWallet&&At.test(s.merchantWallet)),p=jr.useCallback(async()=>{if(u)try{i(!0),f(null);let{Connection:c,PublicKey:g,Transaction:y,SystemProgram:b,LAMPORTS_PER_SOL:k}=await import('@solana/web3.js'),K=typeof window<"u"?window.solana:void 0;if(!K||typeof K!="object"||!K.isPhantom)throw new Error("Phantom wallet not found. Please install Phantom.");let M=K,S;try{S=new g(s.merchantWallet);}catch{throw new Error("Invalid merchant wallet address.")}let G=await M.connect(),z=new g(G.publicKey.toString()),L="https://api.mainnet-beta.solana.com",_=j(s.solanaRpcUrl,L),O=_==="#"?L:_,ne=new c(O),{blockhash:V}=await ne.getLatestBlockhash(),se=BigInt(Math.floor(e*1e9)),xe=s.protocolTreasuryWallet,me=s.protocolFeeBps??500,ie=new y({recentBlockhash:V,feePayer:z});if(xe&&At.test(xe)&&me>0){let le=se*BigInt(me)/10000n,hr=se-le,vr=new g(xe);ie.add(b.transfer({fromPubkey:z,toPubkey:S,lamports:Number(hr)}),b.transfer({fromPubkey:z,toPubkey:vr,lamports:Number(le)}));}else ie.add(b.transfer({fromPubkey:z,toPubkey:S,lamports:Number(se)}));let{signature:ye}=await M.signAndSendTransaction(ie);r(ye);}catch(c){let g=c instanceof Error?c:new Error("Payment failed");f(g.message),t?.(g);}finally{i(false);}},[e,s.merchantWallet,u,r,t]);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("button",{onClick:p,disabled:n||a||!u,"aria-label":`Pay ${e.toFixed(4)} SOL`,className:m("flex w-full items-center justify-center gap-2 rounded-2xl bg-purple-600 py-6 text-base font-semibold text-white transition-colors hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed",l),style:o,children:a?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"]})}),d&&jsxRuntime.jsx("p",{className:"mt-2 text-center text-xs text-red-500",children:d})]})}function Qe({result:e,className:r,style:t}){let[n,l]=jr.useState(false),o=jr.useRef(null);jr.useEffect(()=>()=>{o.current&&clearTimeout(o.current);},[]);let s=jr.useCallback(()=>{e.key?.key&&(navigator.clipboard.writeText(e.key.key),l(true),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>l(false),2e3));},[e.key?.key]);return !e.success||!e.key?null:jsxRuntime.jsxs("div",{className:m("rounded-lg border border-green-500/20 bg-green-500/10 p-6 text-center",r),style:t,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:s,"aria-label":"Copy key to clipboard",className:"shrink-0 rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:n?jsxRuntime.jsx(lucideReact.Check,{className:"h-4 w-4 text-green-500"}):jsxRuntime.jsx(lucideReact.Copy,{className:"h-4 w-4"})})]})]})}function ce({className:e}){return jsxRuntime.jsx("div",{className:m("animate-pulse rounded-xl bg-muted",e)})}function Xe(){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(ce,{className:"h-14 w-48"}),jsxRuntime.jsx(ce,{className:"h-5 w-64"})]}),jsxRuntime.jsx(ce,{className:"h-[72px] w-full rounded-2xl"}),jsxRuntime.jsx(ce,{className:"h-[68px] w-full rounded-2xl"}),jsxRuntime.jsx(ce,{className:"h-[60px] w-full rounded-2xl"})]})}function be({count:e=3}){return jsxRuntime.jsx("div",{className:"space-y-3",children:Array.from({length:e}).map((r,t)=>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(ce,{className:"h-4 w-32"}),jsxRuntime.jsx(ce,{className:"h-4 w-16"})]}),jsxRuntime.jsx(ce,{className:"h-2 w-full rounded-full"}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(ce,{className:"h-3 w-24"}),jsxRuntime.jsx(ce,{className:"h-3 w-20"})]})]},t))})}function Jr({quantity:e,max:r,onChange:t}){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:()=>t(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:()=>t(Math.min(r,e+1)),disabled:e>=r,"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 $t({pricing:e,quantity:r}){let[t,n]=jr.useState(false),l=e.priceUsd*r;return jsxRuntime.jsxs("div",{className:"rounded-2xl border bg-background",children:[jsxRuntime.jsxs("button",{onClick:()=>n(!t),"aria-expanded":t,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:["$",l.toFixed(2)]})," ",jsxRuntime.jsx("span",{className:"text-sm text-muted-foreground",children:"total fees included"})]}),t?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"h-5 w-5 text-muted-foreground"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-5 w-5 text-muted-foreground"})]}),t&&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 ",r]}),jsxRuntime.jsxs("span",{className:"text-foreground",children:["$",(e.priceUsd*r).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:["$",l.toFixed(2)]})]})]})]})}function Ze({className:e,style:r}){let{config:t}=v(),{pricing:n,loading:l,error:o,refresh:s}=Et(),{mint:a,minting:i,result:d,error:f}=Kt(),{createSession:u,loading:p,error:c}=Bt(),[g,y]=jr.useState(1),[b,k]=jr.useState(t.paymentMethods?.includes("stripe")?"stripe":"solana"),[K,M]=jr.useState(0),[S,G]=jr.useState(false),z=jr__default.default.useRef(g);z.current=g;let L=Math.max(1,t.maxQuantity||5),_=[...t.paymentMethods||["solana"]].sort((V,se)=>V==="stripe"?-1:se==="stripe"?1:0);if(jr.useEffect(()=>{if(typeof window>"u")return;let se=new URLSearchParams(window.location.search).get("session_id");if(!se){try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}return}if(/^cs_(test|live)_/.test(se)&&!S&&!d?.success){let xe=false;try{xe=sessionStorage.getItem("keyutils_stripe_pending")==="1";}catch{}if(!xe)return;try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}G(true);let me=new URL(window.location.href);me.searchParams.delete("session_id"),window.history.replaceState({},"",me.toString());let ie=z.current;try{let ye=sessionStorage.getItem("keyutils_stripe_quantity");ye&&(ie=parseInt(ye,10)||1,sessionStorage.removeItem("keyutils_stripe_quantity"));}catch{}a("stripe",se,ie);}},[S,d,a]),d?.success)return jsxRuntime.jsx("div",{className:m("flex flex-col items-center justify-center",e),style:r,children:jsxRuntime.jsx(Qe,{result:d})});if(S||i)return jsxRuntime.jsx("div",{className:m("flex flex-col",e),style:r,children:jsxRuntime.jsx(Xe,{})});if(l)return jsxRuntime.jsx("div",{className:m("flex flex-col",e),style:r,children:jsxRuntime.jsx(Xe,{})});if(o||!n)return jsxRuntime.jsxs("div",{className:m("flex flex-col items-center justify-center gap-4 py-24",e),style:r,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:o||"Please check your connection and try again."})]}),jsxRuntime.jsx("button",{onClick:()=>s(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]});let O=async V=>{M(2),await a(b,V,g);},ne=()=>{u(n.priceCents,g);};return jsxRuntime.jsx("div",{className:m("flex flex-col",e),style:r,children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[K===0&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t.keyImage&&jsxRuntime.jsx("img",{src:j(t.keyImage),alt:"Node Key",className:t.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:["$",n.priceUsd.toFixed(2)]}),jsxRuntime.jsxs("p",{className:"mt-2 text-base text-muted-foreground",children:["per key \xB7 ",n.tokenAllocationFormatted||B(n.tokenAllocation)," tokens included"]})]}),jsxRuntime.jsx(Jr,{quantity:g,max:L,onChange:y}),jsxRuntime.jsx($t,{pricing:n,quantity:g}),jsxRuntime.jsx("button",{onClick:()=>M(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"})]}),K===1&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[_.length>1&&jsxRuntime.jsx("div",{role:"tablist",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:_.map(V=>jsxRuntime.jsxs("button",{role:"tab","aria-selected":b===V,onClick:()=>k(V),className:m("flex flex-1 items-center justify-center gap-2.5 rounded-xl py-4 text-sm font-medium transition-colors",b===V?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[V==="stripe"?jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-5 w-5"}):jsxRuntime.jsx(lucideReact.Wallet,{className:"h-5 w-5"}),V==="stripe"?"Credit Card":"Crypto"]},V))}),jsxRuntime.jsx($t,{pricing:n,quantity:g}),b==="stripe"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{onClick:ne,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"]})}),c&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-500",children:c})]}):b==="solana"?jsxRuntime.jsx(Ge,{amountSol:n.priceSol??0,onSuccess:O}):null,f&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-500",children:f}),jsxRuntime.jsx("button",{type:"button",onClick:()=>M(0),className:"w-full rounded-2xl border border-border bg-transparent py-3 text-center text-sm font-medium text-foreground transition-colors hover:bg-muted/30",children:"Cancel"})]})]})})}var Zr={ios:"iOS",android:"Android",windows:"Windows",mac:"macOS",linux:"Linux"},en=["mac","windows","linux","ios","android"],tn="https://www.stacknet.org/download";function et({downloads:e,className:r,style:t}){let{config:n}=v(),l=jr.useMemo(()=>It(),[]),o=e||en.map(i=>({platform:i,label:Zr[i],url:tn,compatible:i===l})),s=o.find(i=>i.compatible)||o[0],a=o.filter(i=>i.platform!==s.platform);return jsxRuntime.jsxs("div",{className:m("space-y-8",r),style:t,children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-6 pt-4 mt-4",children:[n.aispImage&&jsxRuntime.jsx("img",{src:j(n.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:j(s.url),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-3 rounded-full px-10 py-4 text-lg font-semibold text-white transition-colors hover:opacity-90",style:{backgroundColor:"#0900f4"},children:[jsxRuntime.jsx(lucideReact.Download,{className:"h-5 w-5"}),"Get aiSP for ",s.label]})]}),jsxRuntime.jsxs("p",{className:"text-center text-sm text-muted-foreground",children:["aiSP is also available on"," ",a.map((i,d)=>jsxRuntime.jsxs(jr__default.default.Fragment,{children:[d>0&&(d===a.length-1?" and ":", "),jsxRuntime.jsx("a",{href:j(i.url),target:"_blank",rel:"noopener noreferrer",className:"font-medium underline transition-colors hover:text-foreground",style:{color:"#066bff"},children:i.label})]},i.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:j(n.termsUrl,"/terms"),target:"_blank",rel:"noopener noreferrer",className:"text-foreground underline hover:text-foreground/80",children:"Open Source Applications Terms"})]})]})]})}function on(e){return {id:e.id||"",keyIndex:e.keyIndex??e.key_index??null,key:e.id||e.key||e.keyPrefix||"",userId:e.userId||e.user_id||"",status:e.status||"active",tokenBalance:e.tokenBalance??e.currentTokenBalance??e.current_token_balance??0,maxTokens:e.maxTokens??e.initialTokenBalance??e.initial_token_balance??0,createdAt:String(e.createdAt??e.created_at??""),expiresAt:e.expiresAt,label:e.label||void 0,paperWork:e.paperWork||e.paper_work||void 0,stackId:e.stackId,stackName:e.stackName}}function re(){let{config:e}=v(),[r,t]=jr.useState([]),[n,l]=jr.useState(true),[o,s]=jr.useState(null),a=jr.useRef(true),i=e.apiBaseUrl,d=jr.useCallback(async()=>{try{l(!0),s(null);let u=await fetch(`${i}/api/keys`,{credentials:"include"});if(!u.ok)throw new Error(await R(u,`Failed to fetch keys (${u.status})`));let p=await u.json(),c=Array.isArray(p)?p:p.keys??[];a.current&&t(c.map(on));}catch(u){a.current&&s(u instanceof Error?u.message:"Failed to fetch keys");}finally{a.current&&l(false);}},[i]);jr.useEffect(()=>(a.current=true,d(),()=>{a.current=false;}),[d]);let f=r.reduce((u,p)=>u+p.tokenBalance,0);return {keys:r,totalBalance:f,loading:n,error:o,refresh:d}}var an={"bg-green-500":"bg-green-900/50","bg-yellow-500":"bg-yellow-900/50","bg-red-500":"bg-red-900/50"};function oe({current:e,max:r,className:t,style:n,showLabel:l=true,segments:o=40}){let s=Rt(e,r),a=Tt(s),i=an[a]||"bg-muted",d=Math.round(s/100*o);return jsxRuntime.jsxs("div",{className:m("w-full",t),style:n,children:[l&&jsxRuntime.jsxs("div",{className:"mb-1 flex items-center justify-between text-xs text-muted-foreground",children:[jsxRuntime.jsxs("span",{children:[B(e)," / ",B(r)]}),jsxRuntime.jsxs("span",{children:[s,"%"]})]}),jsxRuntime.jsx("div",{className:"flex h-6 w-full items-stretch gap-1",children:Array.from({length:o}).map((f,u)=>jsxRuntime.jsx("div",{className:m("flex-1 rounded-[1px] transition-colors duration-300",u<d?a:i)},u))})]})}function Le(){let{config:e,callbacks:r}=v(),[t,n]=jr.useState(false),[l,o]=jr.useState(null),[s,a]=jr.useState(null),i=jr.useRef(true),d=jr.useCallback(async(u,p)=>{try{n(!0),a(null);let c=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/list`,{method:"POST",headers:{"Content-Type":"application/json",...$()},credentials:"include",body:JSON.stringify({askPriceCents:p,stackId:e.stackId,stackName:e.stackName})});if(!c.ok)throw new Error(await R(c,`Listing failed (${c.status})`));let g=await c.json();return i.current&&(o(g),r.onListingCreated?.(g)),g}catch(c){let g=c instanceof Error?c.message:"Listing failed";return i.current&&a(g),null}finally{i.current&&n(false);}},[e.apiBaseUrl,e.stackId,e.stackName,r]),f=jr.useCallback(async u=>{try{n(!0),a(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/list`,{method:"DELETE",headers:{...$()},credentials:"include"});if(!p.ok)throw new Error(await R(p,`Delist failed (${p.status})`));return i.current&&o(null),!0}catch(p){let c=p instanceof Error?p.message:"Delist failed";return i.current&&a(c),false}finally{i.current&&n(false);}},[e.apiBaseUrl]);return {listKey:d,delistKey:f,listing:t,result:l,error:s}}function Be(){let{config:e,callbacks:r}=v(),[t,n]=jr.useState(false),[l,o]=jr.useState(null),[s,a]=jr.useState(null),i=jr.useRef(true);return {transferKey:jr.useCallback(async(f,u)=>{try{n(!0),a(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(f)}/transfer`,{method:"POST",headers:{"Content-Type":"application/json",...$()},credentials:"include",body:JSON.stringify({recipientId:u})});if(!p.ok)throw new Error(await R(p,`Transfer failed (${p.status})`));let c=await p.json();return i.current&&(o(c),r.onTransferComplete?.(c)),c}catch(p){let c=p instanceof Error?p.message:"Transfer failed";return i.current&&a(c),null}finally{i.current&&n(false);}},[e.apiBaseUrl,r]),transferring:t,result:l,error:s}}function Vt(e){let r=e.type||e.entry_type||"debit",t=e.amount??e.tokens??e.token_amount??0,n=e.description||e.memo||e.reason||un(r);return {id:e.id||"",keyId:e.keyId||e.key_id||"",type:r,amount:t,description:n,createdAt:String(e.createdAt??e.created_at??e.timestamp??""),metadata:e.metadata||void 0}}function un(e){switch(e){case "credit":return "Credit";case "debit":return "Usage";case "mint":return "Mint";case "reward":return "Reward";default:return ""}}function Fe(e){let{config:r}=v(),[t,n]=jr.useState([]),[l,o]=jr.useState(false),[s,a]=jr.useState(null),i=jr.useRef(true),d=r.apiBaseUrl,f=jr.useCallback(async()=>{if(e)try{o(!0),a(null);let u=await fetch(`${d}/api/keys/${encodeURIComponent(e)}/ledger`,{credentials:"include"});if(!u.ok)throw new Error(await R(u,`Failed to fetch ledger (${u.status})`));let p=await u.json(),c=Array.isArray(p)?p:p.entries??[];i.current&&n(c.map(Vt));}catch(u){i.current&&a(u instanceof Error?u.message:"Failed to fetch ledger");}finally{i.current&&o(false);}},[d,e]);return jr.useEffect(()=>(i.current=true,f(),()=>{i.current=false;}),[f]),{entries:t,loading:l,error:s,refresh:f}}function Ie({open:e,onClose:r,title:t,children:n}){let l=jr.useRef(null),[o,s]=jr.useState(false),[a,i]=jr.useState(false),d=jr.useCallback(f=>{f.key==="Escape"&&r();},[r]);return jr.useEffect(()=>{if(e)s(true),document.addEventListener("keydown",d),document.body.style.overflow="hidden",requestAnimationFrame(()=>{requestAnimationFrame(()=>i(true));});else {i(false);let f=setTimeout(()=>{s(false),document.body.style.overflow="";},300);return document.removeEventListener("keydown",d),()=>clearTimeout(f)}return ()=>{document.removeEventListener("keydown",d);}},[e,d]),o?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:a?1:0},onClick:r}),jsxRuntime.jsxs("div",{ref:l,className:m("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:a?"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"})}),t&&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:t}),jsxRuntime.jsx("button",{onClick:r,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:n})]})]}):null}var Me=[" .-----."," / (_) \\"," / \\","( )"," \\ /"," \\_______/"," || |"," || |"," || /"," || /"," || \\"," || /"," || /"," \\// "],at=16,hn=at*.6,Wt=at*1;function it({className:e,style:r,color:t="currentColor",ariaLabel:n="Node key",keyImage:l,keyImageClass:o}){if(l)return jsxRuntime.jsx("img",{src:j(l),alt:n,className:m(o||"h-20 w-auto mx-auto",e),style:r});let s=Me.reduce((p,c)=>Math.max(p,c.length),0),a=Me.length,i=s*hn,f=a*Wt;return jsxRuntime.jsx("svg",{viewBox:`0 0 ${f} ${i}`,xmlns:"http://www.w3.org/2000/svg",className:m("block",e),style:r,role:"img","aria-label":n,preserveAspectRatio:"xMidYMid meet",children:jsxRuntime.jsx("g",{transform:`translate(0 ${i}) rotate(-90)`,children:Me.map((p,c)=>jsxRuntime.jsx("text",{x:0,y:(c+.8)*Wt,fill:t,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:at,xmlSpace:"preserve",children:p},c))})})}function Yt(){let{config:e,callbacks:r}=v(),[t,n]=jr.useState(false),[l,o]=jr.useState(null),[s,a]=jr.useState(null),i=jr.useRef(true);jr.useEffect(()=>(i.current=true,()=>{i.current=false;}),[]);let d=jr.useCallback(async(u,p)=>{try{n(!0),a(null);let c={stackId:e.stackId};p&&(c.payoutMethod=p);let g=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/file`,{method:"POST",headers:{"Content-Type":"application/json",...$()},credentials:"include",body:JSON.stringify(c)});if(!g.ok)throw new Error(await R(g,`Filing failed (${g.status})`));let y=await g.json();return i.current&&(o(y),r.onFilingComplete?.(y)),y}catch(c){let g=c instanceof Error?c:new Error("Filing failed");return i.current&&a(g.message),r.onFilingError?.(g),null}finally{i.current&&n(false);}},[e.apiBaseUrl,e.stackId,r]),f=jr.useCallback(()=>{o(null),a(null);},[]);return {filePaperwork:d,filing:t,result:l,error:s,reset:f}}function De(){let{config:e}=v(),[r,t]=jr.useState(null),[n,l]=jr.useState(true),[o,s]=jr.useState(null),[a,i]=jr.useState(false),d=jr.useRef(true),f=e.apiBaseUrl,u=jr.useCallback(async()=>{try{l(!0),s(null);let c=await fetch(`${f}/api/payout`,{credentials:"include"});if(!c.ok)throw new Error(await R(c,`Failed to load payout account (${c.status})`));let g=await c.json();d.current&&t(g);}catch(c){d.current&&s(c instanceof Error?c.message:"Failed to load payout account");}finally{d.current&&l(false);}},[f]);jr.useEffect(()=>(d.current=true,u(),()=>{d.current=false;}),[u]);let p=jr.useCallback(async()=>{try{i(!0),s(null);let c=await fetch(`${f}/api/payout`,{method:"DELETE",headers:{...$()},credentials:"include"});if(!c.ok&&c.status!==204)throw new Error(await R(c,`Disconnect failed (${c.status})`));return d.current&&t({method:null}),!0}catch(c){return d.current&&s(c instanceof Error?c.message:"Disconnect failed"),false}finally{d.current&&i(false);}},[f]);return {account:r,loading:n,error:o,refresh:u,disconnect:p,disconnecting:a}}var Rn=5e3;function Tn(e){return e==="paid"||e==="failed"}function Jt(e){let{config:r}=v(),t=r.apiBaseUrl,[n,l]=jr.useState(null),[o,s]=jr.useState(!!e),[a,i]=jr.useState(null),d=jr.useRef(true),f=jr.useCallback(async()=>{if(!e){l(null),s(false);return}try{i(null);let u=await fetch(`${t}/api/keys/filings/${encodeURIComponent(e)}`,{credentials:"include"});if(!u.ok)throw new Error(await R(u,`Failed to load filing (${u.status})`));let p=await u.json();d.current&&l(p);}catch(u){d.current&&i(u instanceof Error?u.message:"Failed to load filing");}finally{d.current&&s(false);}},[t,e]);return jr.useEffect(()=>{if(d.current=true,!e)return l(null),s(false),()=>{d.current=false;};s(true),f();let u=setInterval(()=>{d.current&&(n&&Tn(n.status)||f());},Rn);return ()=>{d.current=false,clearInterval(u);}},[e,f,n]),{detail:n,loading:o,error:a,refresh:f}}function Bn(e){if(!e)return "";try{return new Date(e).toLocaleTimeString()}catch{return ""}}function Fn({state:e,isLast:r}){let t=e.status==="done",n=e.status==="current",l=e.status==="failed",o=t?lucideReact.Check:l?lucideReact.AlertCircle:n?lucideReact.ArrowRight:lucideReact.Circle,s=m("flex h-8 w-8 shrink-0 items-center justify-center rounded-full",n&&"bg-foreground text-background",t&&"bg-green-500/15 text-green-500",l&&"bg-red-500/15 text-red-500",!t&&!n&&!l&&"bg-muted text-muted-foreground"),a=Ce[e.id],i=t?a.done:n?a.progressing:a.pending;return jsxRuntime.jsxs("li",{className:"flex gap-3",children:[jsxRuntime.jsxs("div",{className:"relative flex flex-col items-center",children:[jsxRuntime.jsx("div",{className:s,children:jsxRuntime.jsx(o,{className:"h-4 w-4"})}),!r&&jsxRuntime.jsx("div",{className:m("w-px flex-1 mt-1",t?"bg-green-500/30":"bg-border"),style:{minHeight:32}})]}),jsxRuntime.jsxs("div",{className:m("flex-1 pb-6",r&&"pb-0"),children:[jsxRuntime.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[jsxRuntime.jsxs("span",{className:m("text-sm font-medium lowercase",t&&"text-foreground font-bold",n&&"text-foreground",l&&"text-red-500",!t&&!n&&!l&&"text-muted-foreground"),children:[i,e.id==="confirmed"&&e.approvalsCount!=null&&e.approvalsThreshold!=null&&jsxRuntime.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",e.approvalsCount," of ",e.approvalsThreshold,")"]})]}),e.timestampMs&&jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:Bn(e.timestampMs)})]}),e.detail&&jsxRuntime.jsx("p",{className:m("mt-0.5 text-xs",l?"text-red-500":"text-muted-foreground"),children:e.detail}),e.externalUrl&&jsxRuntime.jsxs("a",{href:j(e.externalUrl),target:"_blank",rel:"noopener noreferrer",className:"mt-1 inline-flex items-center gap-1 text-xs text-foreground/80 hover:text-foreground underline-offset-4 hover:underline",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-3 w-3"}),"view"]})]})]})}function dt({states:e,className:r}){return jsxRuntime.jsx("ol",{className:m("flex flex-col",r),children:e.map((t,n)=>jsxRuntime.jsx(Fn,{state:t,isLast:n===e.length-1},t.id))})}function ut({text:e,speedMs:r=40,playing:t,className:n}){let[l,o]=jr.useState(()=>t?"":e);return jr.useEffect(()=>{if(!t){o(e);return}o("");let s=0,a=false,i,d=()=>{a||(s+=1,o(e.slice(0,s)),s<e.length&&(i=setTimeout(d,r)));};return i=setTimeout(d,r),()=>{a=true,clearTimeout(i);}},[e,r,t]),jsxRuntime.jsxs("span",{className:n,children:[l,t?jsxRuntime.jsx("span",{"aria-hidden":"true",className:"font-mono font-normal opacity-70",children:"\u258A"}):null]})}function pe(e,r=6,t=6){return e?e.length<=r+t+1?e:`${e.slice(0,r)}\u2026${e.slice(-t)}`:""}function zn({value:e}){let[r,t]=jr.useState(false);return jsxRuntime.jsx("button",{type:"button",onClick:()=>{typeof navigator>"u"||!navigator.clipboard||(navigator.clipboard.writeText(e),t(true),setTimeout(()=>t(false),1200));},className:"text-muted-foreground hover:text-foreground transition-colors","aria-label":"Copy",children:r?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"})})}function q({label:e,value:r,href:t,copyValue:n}){return jsxRuntime.jsxs("div",{className:"flex items-start justify-between gap-3 py-2 border-b border-border last:border-b-0",children:[jsxRuntime.jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground shrink-0",children:e}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t?jsxRuntime.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-xs font-mono text-foreground underline underline-offset-4 break-all",children:r}):jsxRuntime.jsx("span",{className:"text-xs font-mono text-foreground break-all",children:r}),n&&jsxRuntime.jsx(zn,{value:n})]})]})}function Yn({detail:e}){let[r,t]=jr.useState(false);return jsxRuntime.jsxs("div",{className:"border border-border rounded-xl",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>t(!r),className:"flex w-full items-center justify-between p-4 text-sm font-semibold text-foreground hover:bg-muted/40 transition-colors rounded-xl",children:["Technical details",r?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"h-4 w-4"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-4 w-4"})]}),r&&jsxRuntime.jsxs("div",{className:"px-4 pb-3",children:[jsxRuntime.jsx(q,{label:"Filing ID",value:pe(e.filingId,8,8),copyValue:e.filingId}),jsxRuntime.jsx(q,{label:"Key ID",value:pe(e.keyId,8,8),copyValue:e.keyId}),jsxRuntime.jsx(q,{label:"File hash",value:pe(e.fileHash,8,8),copyValue:e.fileHash}),e.intentHashHex&&jsxRuntime.jsx(q,{label:"Intent hash",value:pe(e.intentHashHex,8,8),copyValue:e.intentHashHex}),e.proofPda&&jsxRuntime.jsx(q,{label:"Proof PDA",value:pe(e.proofPda,8,8),copyValue:e.proofPda}),e.txSignature&&jsxRuntime.jsx(q,{label:"Tx",value:pe(e.txSignature,8,8),href:`https://solscan.io/tx/${encodeURIComponent(e.txSignature)}`,copyValue:e.txSignature}),jsxRuntime.jsx(q,{label:"Beneficiary",value:pe(e.beneficiary,8,8),copyValue:e.beneficiary}),e.onchainBeneficiary&&e.onchainBeneficiary!==e.beneficiary&&jsxRuntime.jsx(q,{label:"On-chain wallet",value:pe(e.onchainBeneficiary,8,8),copyValue:e.onchainBeneficiary}),jsxRuntime.jsx(q,{label:"Payout method",value:e.payoutMethod}),jsxRuntime.jsx(q,{label:"Memo",value:e.memo}),jsxRuntime.jsx(q,{label:"Amount",value:Ee(e.amountUsdc)}),jsxRuntime.jsx(q,{label:"Tokens used",value:e.tokensUsed}),jsxRuntime.jsx(q,{label:"Filed at",value:X(e.filedAt)}),e.stripePaymentIntentId&&jsxRuntime.jsx(q,{label:"Stripe PI",value:pe(e.stripePaymentIntentId,6,6),copyValue:e.stripePaymentIntentId}),e.failureReason&&jsxRuntime.jsx(q,{label:"Failure",value:e.failureReason})]})]})}function mt({filingId:e,className:r,style:t}){let{detail:n,loading:l,error:o}=Jt(e),s=jr__default.default.useMemo(()=>He(n?.tracker),[n?.tracker]),a=We(s,!!n),i=s.find(d=>d.status==="failed");return o&&!n?jsxRuntime.jsxs("div",{className:m("space-y-4",r),style:t,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:"Unable to load filing"})]}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:o})]}):jsxRuntime.jsxs("div",{className:m("space-y-5",r),style:t,children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-1",children:[jsxRuntime.jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"delivery status"}),jsxRuntime.jsx("h1",{className:m("text-4xl font-mono tracking-tight",i?"text-red-500":"text-foreground"),children:i?a.text:jsxRuntime.jsx(ut,{text:a.text,playing:a.playing,speedMs:40})})]}),l&&!n&&jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("div",{className:"h-5 w-40 bg-muted animate-pulse rounded"}),jsxRuntime.jsx("div",{className:"h-5 w-32 bg-muted animate-pulse rounded"}),jsxRuntime.jsx("div",{className:"h-5 w-48 bg-muted animate-pulse rounded"})]}),jsxRuntime.jsx(dt,{states:s}),n&&jsxRuntime.jsx(Yn,{detail:n})]})}function ts(e,r=6,t=6){return !e||e.length<=r+t+1?e:`${e.slice(0,r)}\u2026${e.slice(-t)}`}function rs({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 2000 2000","aria-label":"USDC",role:"img",className:e,children:[jsxRuntime.jsx("path",{d:"M1000 2000c554.17 0 1000-445.83 1000-1000S1554.17 0 1000 0 0 445.83 0 1000s445.83 1000 1000 1000z",fill:"#2775ca"}),jsxRuntime.jsx("path",{d:"M1275 1158.33c0-145.83-87.5-195.83-262.5-216.66-125-16.67-150-50-150-108.34s41.67-95.83 125-95.83c75 0 116.67 25 137.5 87.5 4.17 12.5 16.67 20.83 29.17 20.83h66.66c16.67 0 29.17-12.5 29.17-29.16v-4.17c-16.67-91.67-91.67-162.5-187.5-170.83v-100c0-16.67-12.5-29.17-33.33-33.34h-62.5c-16.67 0-29.17 12.5-33.34 33.34v95.83c-125 16.67-204.16 100-204.16 204.17 0 137.5 83.33 191.66 258.33 212.5 116.67 20.83 154.17 45.83 154.17 112.5s-58.34 112.5-137.5 112.5c-108.34 0-145.84-45.84-158.34-108.34-4.16-16.66-16.66-25-29.16-25h-70.84c-16.66 0-29.16 12.5-29.16 29.17v4.17c16.66 104.16 83.33 179.16 220.83 200v100c0 16.66 12.5 29.16 33.33 33.33h62.5c16.67 0 29.17-12.5 33.34-33.33v-100c125-20.84 208.33-108.34 208.33-220.84z",fill:"#fff"}),jsxRuntime.jsx("path",{d:"M787.5 1595.83c-325-116.66-491.67-479.16-370.83-800 62.5-175 200-308.33 370.83-370.83 16.67-8.33 25-20.83 25-41.67V325c0-16.67-8.33-29.17-25-33.33-4.17 0-12.5 0-16.67 4.16-395.83 125-612.5 545.84-487.5 941.67 75 233.33 254.17 412.5 487.5 487.5 16.67 8.33 33.34 0 37.5-16.67 4.17-4.16 4.17-8.33 4.17-16.66v-58.34c0-12.5-12.5-29.16-25-37.5zM1229.17 295.83c-16.67-8.33-33.34 0-37.5 16.67-4.17 4.17-4.17 8.33-4.17 16.67v58.33c0 16.67 12.5 33.33 25 41.67 325 116.66 491.67 479.16 370.83 800-62.5 175-200 308.33-370.83 370.83-16.67 8.33-25 20.83-25 41.67V1700c0 16.67 8.33 29.17 25 33.33 4.17 0 12.5 0 16.67-4.16 395.83-125 612.5-545.84 487.5-941.67-75-237.5-258.34-416.67-487.5-491.67z",fill:"#fff"})]})}function ns({nodeKey:e,stackName:r}){let t=Math.max(0,e.maxTokens-e.tokenBalance);return jsxRuntime.jsxs("div",{className:"rounded-xl 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:ts(e.id,8,8)})]}),r&&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})]}),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:[B(t)," / ",B(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 ft({keyId:e,onComplete:r,onBack:t,onViewFiling:n,onConfigureEarnings:l,className:o,style:s}){let{config:a}=v(),{keys:i,loading:d,error:f,refresh:u}=re(),{account:p,loading:c,error:g}=De(),{filePaperwork:y,filing:b,result:k,error:K}=Yt(),[M,S]=jr.useState(false),[G,z]=jr.useState(false),L=le=>G?"* * * *":le;jr.useEffect(()=>{k&&!M&&(S(true),r?.(k),u());},[k,M,r,u]);let _=i.find(le=>le.id===e),O=!!_?.paperWork&&_.paperWork!=="0",ne=!!p?.method,V=O&&ne&&!b&&!k,se=async()=>{if(!V||!_)return;let le=p?.method==="solana"?"usdc":p?.method==="stripe"?"stripe":null;await y(_.id,le);};if(k)return jsxRuntime.jsxs("div",{className:m("space-y-6",o),style:s,children:[jsxRuntime.jsx(mt,{filingId:k.filingId}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[n&&jsxRuntime.jsx("button",{type:"button",onClick:()=>n(k.filingId),className:"flex-1 rounded-xl bg-foreground text-background py-3 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:"Open filing"}),t&&jsxRuntime.jsx("button",{type:"button",onClick:t,className:"flex-1 rounded-xl border border-border bg-background text-foreground py-3 text-sm font-semibold hover:bg-muted/50 transition-colors",children:"Back to dashboard"})]})]});if(d||c)return jsxRuntime.jsxs("div",{className:m("space-y-4",o),style:s,children:[jsxRuntime.jsx("div",{className:"h-7 w-48 bg-muted animate-pulse rounded-xl"}),jsxRuntime.jsx("div",{className:"h-32 w-full bg-muted animate-pulse rounded-xl"}),jsxRuntime.jsx("div",{className:"h-12 w-full bg-muted animate-pulse rounded-xl"})]});if(f||!_)return jsxRuntime.jsxs("div",{className:m("space-y-4",o),style:s,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:f?"Unable to load keys":"Key not found"})]}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:f||`No key with id ${e} on this account.`}),jsxRuntime.jsx("button",{type:"button",onClick:()=>u(),className:"rounded-xl bg-foreground text-background px-4 py-3 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:"Try again"})]});let xe=_.stackName||a.stackName,me=null,ie=null,ye="";return p?.method==="solana"&&p.solana?(ie=jsxRuntime.jsx(rs,{className:"h-7 w-7 shrink-0"}),ye="USDC",me=jsxRuntime.jsx("code",{className:"text-xs text-foreground break-all",children:L(p.solana.address)})):p?.method==="stripe"&&p.stripe&&(ie=jsxRuntime.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-foreground text-background",children:jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-4 w-4"})}),ye="USD via Stripe",me=jsxRuntime.jsxs("span",{className:"text-xs text-foreground",children:["Stripe account ",jsxRuntime.jsx("code",{className:"text-xs",children:L(p.stripe.accountIdMasked)}),!p.stripe.payoutsEnabled&&jsxRuntime.jsx("span",{className:"ml-2 text-amber-600",children:"(payouts pending)"})]})),jsxRuntime.jsxs("div",{className:m("space-y-6",o),style:s,children:[jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Your earnings will be deposited into your earnings account."}),jsxRuntime.jsx(ns,{nodeKey:_,stackName:xe}),!O&&jsxRuntime.jsx("div",{className:"rounded-xl bg-muted/30 p-4 text-sm text-muted-foreground",children:"This key has no pending paperwork. Run your node to earn Paper, then return to file."}),g&&!ne&&jsxRuntime.jsxs("div",{className:"rounded-xl bg-muted/30 p-4 text-sm text-muted-foreground",children:["Couldn't load your earnings account (",g,"). Try again in a moment."]}),!ne&&!g?jsxRuntime.jsxs("div",{className:"rounded-xl border border-border p-4 space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.jsx(lucideReact.Info,{className:"h-5 w-5 mt-0.5 text-foreground shrink-0","aria-hidden":true}),jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Earnings account required"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Connect a payout destination before filing. You only do this once."})]})]}),l&&jsxRuntime.jsxs("button",{type:"button",onClick:l,className:"inline-flex items-center gap-2 rounded-xl bg-foreground text-background px-4 py-2 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),"Set up earnings account"]})]}):ne&&O?jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Payout"}),jsxRuntime.jsxs("div",{className:"rounded-xl bg-muted/30 p-4 flex items-start gap-3",children:[ie,jsxRuntime.jsxs("div",{className:"flex flex-col gap-1 min-w-0",children:[jsxRuntime.jsx("span",{className:"text-sm font-semibold text-foreground",children:ye}),me]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>z(le=>!le),"aria-label":G?"Show address":"Hide address","aria-pressed":G,className:"ml-auto mt-0.5 p-0.5 text-muted-foreground hover:text-foreground transition-colors shrink-0",children:G?jsxRuntime.jsx(lucideReact.Eye,{className:"h-4 w-4"}):jsxRuntime.jsx(lucideReact.EyeOff,{className:"h-4 w-4"})})]})]}):null,K&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:K}),jsxRuntime.jsx("button",{type:"button",onClick:se,disabled:!V,className:m("w-full rounded-xl py-4 text-sm font-semibold transition-colors",V?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:b?"Filing\u2026":"File Paperwork"})]})}function ls({nodeKey:e,onSuccess:r}){let{transferKey:t,transferring:n,result:l,error:o}=Be(),[s,a]=jr.useState(""),[i,d]=jr.useState(false),f=s.trim()===e.userId,u=s.trim().length>0&&i&&!f&&!n,p=async()=>{if(!u)return;await t(e.id,s.trim())&&r();};return l?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:s,onChange:c=>{a(c.target.value),d(false);},placeholder:"Enter recipient's user ID or global ID",className:"w-full rounded-xl border border-border bg-background px-4 py-3 text-sm text-foreground placeholder:text-muted-foreground focus:border-foreground/30 focus:outline-none focus:ring-1 focus:ring-foreground/10"}),f&&jsxRuntime.jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),s.trim().length>0&&!f&&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)})," ","(",B(e.tokenBalance)," tokens) to"," ",jsxRuntime.jsxs("span",{className:"font-mono font-medium",children:[s.trim().slice(0,20),s.trim().length>20?"...":""]})]})]}),jsxRuntime.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:i,onChange:c=>d(c.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:p,disabled:!u,className:m("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",u?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:n?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 cs({nodeKey:e,onSuccess:r}){let{config:t}=v(),{listKey:n,listing:l,result:o,error:s}=Le(),[a,i]=jr.useState(""),[d,f]=jr.useState(false),u=parseInt(a.replace(/[^0-9]/g,""),10)||0,c=u>0&&Number.isFinite(u)&&d&&!l,g=async()=>{if(!c)return;let y=u*100;await n(e.id,y)&&r();};return o?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:o.listingId})]}),jsxRuntime.jsxs("a",{href:`https://market.stacknet.org/keys/${encodeURIComponent(o.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:a,onChange:y=>{let b=y.target.value.replace(/[^0-9]/g,""),k=parseInt(b,10);i(isNaN(k)?"":k.toLocaleString("en-US"));},placeholder:"0",className:"w-full rounded-xl border bg-background py-6 pl-10 pr-4 text-3xl font-bold text-foreground placeholder:text-muted-foreground/30 focus:outline-none focus:ring-2 focus:ring-foreground/20"})]})]}),jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.jsx("button",{type:"button",role:"checkbox","aria-checked":d,onClick:()=>f(!d),className:m("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",d?"border-foreground bg-foreground":"border-muted-foreground/40"),children:d&&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:j(t.termsUrl,"/terms"),className:"text-foreground underline",target:"_blank",rel:"noopener noreferrer",children:"Terms"})]})]}),s&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:s}),jsxRuntime.jsxs("button",{onClick:g,disabled:!c,className:m("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",c?"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"}),l?"Listing...":"List on Marketplace"]})]})}function ds({nodeKey:e,onSuccess:r,onClose:t,onViewFiling:n,onConfigureEarnings:l}){return jsxRuntime.jsx(ft,{keyId:e.id,onComplete:r,onBack:t,onViewFiling:n,onConfigureEarnings:l})}function pt({nodeKey:e,onBack:r,onKeysChanged:t,onViewFiling:n,onConfigureEarnings:l,className:o,style:s}){let {config:a}=v();Fe(e.id);let [f,u]=jr.useState(null),[p,c]=jr.useState(false),g=()=>{u(null),t?.();},y=K=>{},b=()=>{e.key&&(navigator.clipboard.writeText(e.key),c(true),setTimeout(()=>c(false),2e3));},k=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsxRuntime.jsxs("div",{className:m("space-y-5",o),style:s,children:[jsxRuntime.jsxs("button",{onClick:r,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"}),"View All"]}),jsxRuntime.jsx(it,{className:m("mx-auto text-foreground px-0 sm:px-0",a.keyImage?"w-2/3 h-auto":"h-20 w-auto"),keyImage:a.keyImage,keyImageClass:a.keyImageClass}),jsxRuntime.jsx("div",{className:"space-y-1",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("h2",{className:"text-3xl font-bold text-foreground",children:e.keyIndex?`Key #${e.keyIndex}`:e.label||e.id.slice(0,16)}),jsxRuntime.jsx("span",{className:m("text-sm font-medium capitalize",k),children:e.status})]})}),e.key&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("code",{className:"flex-1 truncate px-0 py-2 text-lg text-muted-foreground",children:e.key}),jsxRuntime.jsx("button",{onClick:b,"aria-label":"Copy key",className:"shrink-0 rounded-lg p-2 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",children:p?jsxRuntime.jsx(lucideReact.Check,{className:"h-4 w-4 text-green-500"}):jsxRuntime.jsx(lucideReact.Copy,{className:"h-4 w-4"})})]}),jsxRuntime.jsx(oe,{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:[(a.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||a.stackName})]}),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&&e.paperWork!=="0"&&jsxRuntime.jsxs("div",{className:"rounded-xl p-5",children:[jsxRuntime.jsx("h3",{className:"text-sm font-semibold text-foreground mb-2",children:"Paperwork"}),jsxRuntime.jsx("p",{className:"text-2xl font-semibold tabular-nums text-foreground",children:Ee(e.paperWork)})]}),e.status==="active"&&jsxRuntime.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[jsxRuntime.jsx("button",{onClick:()=>u("transfer"),className:"flex items-center justify-center rounded-xl border border-border p-4 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors",children:"Transfer"}),jsxRuntime.jsx("button",{onClick:()=>u("sell"),className:"flex items-center justify-center rounded-xl border border-border p-4 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors",children:"Sell"}),jsxRuntime.jsx("button",{onClick:()=>u("file"),className:"flex items-center justify-center rounded-xl border border-border p-4 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors",children:"File"})]}),jsxRuntime.jsx(Ie,{open:f==="transfer",onClose:()=>u(null),title:"Transfer Key",children:jsxRuntime.jsx(ls,{nodeKey:e,onSuccess:g})}),jsxRuntime.jsx(Ie,{open:f==="sell",onClose:()=>u(null),title:"Sell Key",children:jsxRuntime.jsx(cs,{nodeKey:e,onSuccess:g})}),jsxRuntime.jsx(Ie,{open:f==="file",onClose:()=>u(null),title:"File Paperwork",children:jsxRuntime.jsx(ds,{nodeKey:e,onSuccess:y,onClose:()=>u(null),onViewFiling:n,onConfigureEarnings:l})})]})}function us({nodeKey:e,onClick:r}){let t=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsxRuntime.jsx("button",{onClick:r,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:m("text-xs font-medium capitalize",t),children:e.status})]}),jsxRuntime.jsx(oe,{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 gt({onViewFiling:e,onConfigureEarnings:r,className:t,style:n}){let{keys:l,loading:s,error:a,refresh:i}=re(),[d,f]=jr.useState(null),[u,p]=jr.useState("active"),c=l.filter(b=>b.status===u),g=c.reduce((b,k)=>b+k.tokenBalance,0),y=l.find(b=>b.id===d);return y?jsxRuntime.jsx(pt,{nodeKey:y,onBack:()=>f(null),onKeysChanged:()=>{f(null),i();},onViewFiling:e,onConfigureEarnings:r,className:t,style:n}):s?jsxRuntime.jsxs("div",{className:m("space-y-4",t),style:n,children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx(be,{count:3})]}):a?jsxRuntime.jsxs("div",{className:m("flex flex-col items-center justify-center gap-4 py-16",t),style:n,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:a})]}),jsxRuntime.jsx("button",{onClick:()=>i(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]}):l.length===0?jsxRuntime.jsxs("div",{className:m("flex flex-col items-center justify-center gap-4 rounded-xl border border-dashed py-16",t),style:n,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:m("space-y-4",t),style:n,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:"hidden text-xs text-muted-foreground sm:inline",children:[c.length," key",c.length!==1?"s":""," \xB7 ",B(g)," tokens"]}),jsxRuntime.jsx("div",{className:"flex gap-1 rounded-lg bg-muted/50 p-1",children:["active","listed"].map(b=>jsxRuntime.jsx("button",{onClick:()=>p(b),className:m("rounded-md px-3 py-1 text-xs font-medium capitalize transition-all",u===b?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:b},b))})]}),c.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 ",u," keys."]})]}):jsxRuntime.jsx("div",{className:"space-y-2",children:c.map(b=>jsxRuntime.jsx(us,{nodeKey:b,onClick:()=>f(b.id)},b.id))})]})}var fs=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function ps({active:e,onChange:r}){return jsxRuntime.jsx("div",{role:"tablist","aria-label":"Key actions",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:fs.map(({id:t,label:n})=>jsxRuntime.jsx("button",{role:"tab","aria-selected":e===t,"aria-controls":`panel-${t}`,id:`tab-${t}`,onClick:()=>r(t),className:m("flex flex-1 items-center justify-center gap-2.5 rounded-xl py-3.5 text-sm font-medium transition-all",e===t?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:jsxRuntime.jsx("span",{className:"inline",children:n})},t))})}function gs({defaultTab:e="buy",onViewFiling:r,onConfigureEarnings:t,className:n,style:l}){let[o,s]=jr.useState(e);return jsxRuntime.jsxs("div",{className:m("flex flex-col",n),style:l,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(ps,{active:o,onChange:s})})}),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-${o}`,"aria-labelledby":`tab-${o}`,children:[o==="buy"&&jsxRuntime.jsx(Ze,{className:"flex-1"}),o==="use"&&jsxRuntime.jsx(et,{className:"flex-1"}),o==="keys"&&jsxRuntime.jsx(gt,{className:"flex-1",onViewFiling:r,onConfigureEarnings:t})]})})})]})}function xs({apiBaseUrl:e,stackId:r,stackName:t,paymentMethods:n,merchantWallet:l,stripePublicKey:o,theme:s,maxQuantity:a,keyImage:i,keyImageClass:d,aispImage:f,termsUrl:u,onMintSuccess:p,onMintError:c,onPaymentStart:g,onPaymentComplete:y,onListingCreated:b,onTransferComplete:k,onFilingComplete:K,onFilingError:M,defaultTab:S,onViewFiling:G,onConfigureEarnings:z,className:L,style:_}){return jsxRuntime.jsx(Oe,{config:{apiBaseUrl:e,stackId:r,stackName:t,paymentMethods:n,merchantWallet:l,stripePublicKey:o,theme:s,maxQuantity:a,keyImage:i,keyImageClass:d,aispImage:f,termsUrl:u},callbacks:{onMintSuccess:p,onMintError:c,onPaymentStart:g,onPaymentComplete:y,onListingCreated:b,onTransferComplete:k,onFilingComplete:K,onFilingError:M},children:jsxRuntime.jsx(gs,{defaultTab:S,onViewFiling:G,onConfigureEarnings:z,className:L,style:_})})}function hs({nodeKey:e,selected:r,onSelect:t}){return jsxRuntime.jsxs("button",{onClick:t,className:m("flex w-full items-start gap-3 rounded-xl border p-4 text-left transition-all",r?"border-foreground/30 bg-foreground/5 ring-1 ring-foreground/10":"border-border hover:border-foreground/20"),children:[jsxRuntime.jsx("div",{className:m("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors",r?"border-foreground bg-foreground":"border-muted-foreground/40"),children:r&&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:m("text-xs font-medium capitalize",e.status==="active"?"text-green-500":"text-muted-foreground"),children:e.status})]}),jsxRuntime.jsx(oe,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function vs({className:e,style:r}){let{config:t}=v(),{keys:n,loading:l,error:o,refresh:s}=re(),{listKey:a,listing:i,result:d,error:f}=Le(),[u,p]=jr.useState(null),[c,g]=jr.useState(""),[y,b]=jr.useState(false),k=n.find(L=>L.id===u),K=parseInt(c.replace(/[^0-9]/g,""),10)||0,M=K>0&&Number.isFinite(K),S=!!k&&M&&y&&!i,G=async()=>{if(!S||!k)return;let L=K*100;await a(k.id,L)&&s();};if(d)return jsxRuntime.jsxs("div",{className:m("flex flex-col items-center gap-4 rounded-xl bg-green-500/10 py-12",e),style:r,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:d.listingId})]}),jsxRuntime.jsxs("a",{href:`https://market.stacknet.org/keys/${encodeURIComponent(d.keyId)}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 rounded-xl bg-foreground px-6 py-3 text-sm font-semibold text-background transition-colors hover:bg-foreground/90",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),"View Listing"]})]});if(l)return jsxRuntime.jsxs("div",{className:m("space-y-5 px-1",e),style:r,children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx(be,{count:2})]});if(o)return jsxRuntime.jsxs("div",{className:m("flex flex-col items-center justify-center gap-4 py-16",e),style:r,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:()=>s(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]});let z=n.filter(L=>L.status==="active");return z.length===0?jsxRuntime.jsxs("div",{className:m("flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16",e),style:r,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:m("space-y-5",e),style:r,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:z.map(L=>jsxRuntime.jsx(hs,{nodeKey:L,selected:u===L.id,onSelect:()=>p(L.id)},L.id))})]}),k&&jsxRuntime.jsxs("div",{className:"rounded-xl border bg-muted/30 p-5 space-y-2 text-sm",children:[k.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:["#",k.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:k.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:t.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:[B(k.tokenBalance)," / ",B(k.maxTokens)]})]}),k.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:k.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(k.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:c,onChange:L=>{let _=L.target.value.replace(/[^0-9]/g,""),O=parseInt(_,10);g(isNaN(O)?"":O.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":y,onClick:()=>b(!y),className:m("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",y?"border-foreground bg-foreground":"border-muted-foreground/40"),children:y&&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:j(t.termsUrl,"/terms"),className:"text-foreground underline",target:"_blank",rel:"noopener noreferrer",children:"Terms"})]})]}),f&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:f}),jsxRuntime.jsxs("button",{onClick:G,disabled:!S,className:m("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",S?"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"}),i?"Listing...":"List on Marketplace"]})]})}var yt=20;function bt({nodeKey:e,className:r,style:t}){let[n,l]=jr.useState(false),[o,s]=jr.useState(false),a=jr.useRef(null),{entries:i,loading:d}=Fe(n?e.id:null);jr.useEffect(()=>()=>{a.current&&clearTimeout(a.current);},[]);let f=jr.useCallback(()=>{e.key&&(navigator.clipboard.writeText(e.key),s(true),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>s(false),2e3));},[e.key]),u=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500",p=i.slice(0,yt);return jsxRuntime.jsxs("div",{className:m("rounded-lg border bg-background",r),style:t,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:()=>l(!n),"aria-expanded":n,"aria-label":n?"Collapse ledger":"Expand ledger",className:"text-muted-foreground hover:text-foreground",children:n?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:m("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:f,"aria-label":"Copy key to clipboard",className:"shrink-0 rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:o?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(oe,{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)]})]})]}),n&&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"}),d?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(c=>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:m("font-medium",c.type==="credit"||c.type==="reward"?"text-green-500":"text-red-500"),children:[c.type==="credit"||c.type==="reward"?"+":"-",B(Math.abs(c.amount))]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:c.description})]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:X(c.createdAt)})]},c.id)),i.length>yt&&jsxRuntime.jsxs("p",{className:"pt-1 text-xs text-muted-foreground",children:["Showing ",yt," of ",i.length," entries"]})]})]})]})}var Is=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function $e({baseHref:e}){return jsxRuntime.jsx("div",{className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5 mb-6",children:Is.map(({id:r,label:t})=>jsxRuntime.jsx("a",{href:`${e}?tab=${r}`,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:t},r))})}function Us({getKeyHref:e="/keys/get",showTabs:r=true,className:t,style:n}){let{keys:l,totalBalance:o,loading:s,error:a,refresh:i}=re();return s?jsxRuntime.jsxs("div",{className:m("space-y-4",t),style:n,children:[r&&e&&jsxRuntime.jsx($e,{baseHref:e}),jsxRuntime.jsx(be,{count:3})]}):a?jsxRuntime.jsxs("div",{className:m("space-y-4",t),style:n,children:[r&&e&&jsxRuntime.jsx($e,{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:a})]}),jsxRuntime.jsx("button",{onClick:()=>i(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]})]}):l.length===0?jsxRuntime.jsxs("div",{className:m("space-y-4",t),style:n,children:[r&&e&&jsxRuntime.jsx($e,{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:m("space-y-4",t),style:n,children:[r&&e&&jsxRuntime.jsx($e,{baseHref:e}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("p",{className:"text-sm text-muted-foreground",children:[l.length," key",l.length!==1?"s":""," \xB7 Total balance: ",B(o)]}),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"})]}),l.map(d=>jsxRuntime.jsx(bt,{nodeKey:d},d.id))]})}function Fs({nodeKey:e,selected:r,onSelect:t}){return jsxRuntime.jsxs("button",{onClick:t,className:m("flex w-full items-start gap-3 rounded-xl border p-4 text-left transition-all",r?"border-foreground/30 bg-foreground/5 ring-1 ring-foreground/10":"border-border hover:border-foreground/20"),children:[jsxRuntime.jsx("div",{className:m("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors",r?"border-foreground bg-foreground":"border-muted-foreground/40"),children:r&&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(oe,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function As({className:e,style:r}){let{keys:t,loading:n}=re(),{transferKey:l,transferring:o,result:s,error:a}=Be(),[i,d]=jr.useState(null),[f,u]=jr.useState(""),[p,c]=jr.useState(false),g=t.filter(S=>S.status==="active"),y=g.find(S=>S.id===i),b=y&&f.trim()===y.userId,k=i&&f.trim().length>0&&p&&!b&&!o,K=async()=>{!i||!f.trim()||await l(i,f.trim());},M=()=>{d(null),u(""),c(false);};return s?jsxRuntime.jsxs("div",{className:m("flex flex-col items-center gap-4 py-8",e),style:r,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:[s.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:[s.toUserId.slice(0,20),"..."]})]})]}),jsxRuntime.jsx("button",{onClick:M,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:m("space-y-5",e),style:r,children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"mb-3 text-sm font-medium text-foreground",children:"Select Key to Transfer"}),n?jsxRuntime.jsx(be,{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(S=>jsxRuntime.jsx(Fs,{nodeKey:S,selected:i===S.id,onSelect:()=>d(S.id)},S.id))})]}),i&&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:f,onChange:S=>{u(S.target.value),c(false);},placeholder:"Enter recipient's user ID or global ID",className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:border-foreground/30 focus:outline-none focus:ring-1 focus:ring-foreground/10"}),b&&jsxRuntime.jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),y&&f.trim().length>0&&!b&&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:y.keyIndex?`#${y.keyIndex}`:y.id.slice(0,12)})," ","(",B(y.tokenBalance)," tokens) to"," ",jsxRuntime.jsxs("span",{className:"font-mono font-medium",children:[f.trim().slice(0,20),"..."]})]})]}),jsxRuntime.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:p,onChange:S=>c(S.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."})]})]})]})}),a&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:a}),jsxRuntime.jsx("button",{onClick:K,disabled:!k,className:m("flex w-full items-center justify-center gap-2 rounded-lg px-4 py-3 text-sm font-medium transition-all",k?"bg-foreground text-background hover:opacity-90":"bg-muted text-muted-foreground cursor-not-allowed"),children:o?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 Ds(e){return e.status==="active"}function $s({count:e=3}){return jsxRuntime.jsx("div",{className:"space-y-2",children:Array.from({length:e}).map((r,t)=>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"})]},t))})}function js({nodeKey:e,onSelect:r}){let t=Math.max(0,e.maxTokens-e.tokenBalance);return jsxRuntime.jsxs("button",{type:"button",onClick:r,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:[B(t)," / ",B(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 Os({onSelect:e,className:r,style:t}){let{keys:n,loading:l,error:o,refresh:s}=re();if(l)return jsxRuntime.jsx("div",{className:m("space-y-3",r),style:t,children:jsxRuntime.jsx($s,{count:3})});if(o)return jsxRuntime.jsx("div",{className:m("space-y-3",r),style:t,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:o}),jsxRuntime.jsx("button",{type:"button",onClick:()=>s(),className:"mt-3 bg-foreground text-background px-4 py-2 text-xs font-semibold hover:bg-foreground/90 transition-colors",children:"Try again"})]})});let a=n.filter(Ds);return a.length===0?jsxRuntime.jsxs("div",{className:m("flex flex-col items-center justify-center gap-3 bg-muted/20 py-16",r),style:t,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:m("space-y-2",r),style:t,children:a.map(i=>jsxRuntime.jsx(js,{nodeKey:i,onSelect:()=>e(i.id)},i.id))})}function cr({label:e,sub:r,icon:t,selected:n,enabled:l,disabledLabel:o,onClick:s}){let a=l;return jsxRuntime.jsxs("button",{type:"button",onClick:a?s:void 0,disabled:!a,"aria-disabled":!a,className:m("flex flex-col items-start gap-1 rounded-xl border p-4 text-left transition-colors",a?n?"border-foreground bg-foreground/5 cursor-pointer":"border-border hover:bg-muted/50 cursor-pointer":"border-border bg-muted/20 cursor-not-allowed opacity-70"),children:[jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:m("flex h-7 w-7 items-center justify-center rounded-md",n&&l?"bg-foreground text-background":"bg-muted text-foreground"),children:t}),jsxRuntime.jsx("span",{className:"text-sm font-semibold text-foreground",children:e})]}),!l&&jsxRuntime.jsx(lucideReact.Lock,{className:"h-3.5 w-3.5 text-muted-foreground","aria-hidden":true})]}),jsxRuntime.jsx("p",{className:m("text-xs",l?"text-muted-foreground":"text-muted-foreground/80"),children:l?r:o??r})]})}function zs({caps:e,value:r,onChange:t,className:n,disabled:l=false}){let o=e.stripe.enabled&&!l,s=e.usdc.enabled&&!l,a=`disabled by ${e.stackName} stack`,i=`disabled by ${e.stackName} stack`;return jsxRuntime.jsxs("div",{className:m("space-y-2",n),children:[jsxRuntime.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Payout method"}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[jsxRuntime.jsx(cr,{label:"USDC",sub:"On-chain payout to your stack address",icon:jsxRuntime.jsx(lucideReact.Wallet,{className:"h-4 w-4"}),selected:r==="usdc",enabled:s,disabledLabel:i,onClick:()=>t("usdc")}),jsxRuntime.jsx(cr,{label:"Stripe",sub:"USD payout to your bank via Stripe",icon:jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-4 w-4"}),selected:r==="stripe",enabled:o,disabledLabel:a,onClick:()=>t("stripe")})]})]})}function ur(){let{config:e}=v(),[r,t]=jr.useState(false),[n,l]=jr.useState(null);return {startStripeConnect:jr.useCallback(async()=>{try{t(!0),l(null);let s=await fetch(`${e.apiBaseUrl}/api/payout/stripe/start`,{method:"POST",headers:{"Content-Type":"application/json",...$()},credentials:"include",body:JSON.stringify({stackId:e.stackId})});if(!s.ok)throw new Error(await R(s,`Stripe Connect start failed (${s.status})`));let a=await s.json();if(typeof window<"u"&&a.onboardingUrl){let i;try{i=new URL(a.onboardingUrl);}catch{throw new Error("Invalid onboarding URL")}if(i.protocol!=="https:"||!/(^|\.)stripe\.com$/.test(i.hostname))throw new Error("Refusing to redirect to non-Stripe URL");window.location.href=i.toString();return}}catch(s){l(s instanceof Error?s.message:"Stripe Connect start failed");}finally{t(false);}},[e.apiBaseUrl,e.stackId]),starting:r,error:n}}function Js(){if(typeof window>"u")return null;let e=window,r=e.solana,t=e.phantom?.solana;return ((r&&r.isPhantom?r:null)||(t&&t.isPhantom?t:null))??null}function Gs(e){let r="";for(let t=0;t<e.length;t+=1)r+=String.fromCharCode(e[t]);return typeof btoa=="function"?btoa(r):Buffer.from(e).toString("base64")}function fr(){let{config:e}=v(),[r,t]=jr.useState(false),[n,l]=jr.useState(null);return {connectAndVerify:jr.useCallback(async()=>{try{t(!0),l(null);let s=Js();if(!s)throw new Error("Phantom wallet not found. Install Phantom to continue.");let i=(await s.connect()).publicKey.toString(),d=await fetch(`${e.apiBaseUrl}/api/payout/crypto/nonce`,{method:"POST",headers:{"Content-Type":"application/json",...$()},credentials:"include",body:JSON.stringify({address:i})});if(!d.ok)throw new Error(await R(d,`Nonce request failed (${d.status})`));let{nonce:f,message:u}=await d.json(),p=new TextEncoder().encode(u),c=await s.signMessage(p,"utf8"),g=Gs(c.signature),y=await fetch(`${e.apiBaseUrl}/api/payout/crypto/verify`,{method:"POST",headers:{"Content-Type":"application/json",...$()},credentials:"include",body:JSON.stringify({address:i,nonce:f,signature:g})});if(!y.ok)throw new Error(await R(y,`Verification failed (${y.status})`));return {address:i}}catch(s){let a=s instanceof Error?s:new Error("Wallet verification failed");return l(a.message),null}finally{t(false);}},[e.apiBaseUrl]),connecting:r,error:n}}function pr(e){let{config:r}=v(),t=r.stackId,n=r.apiBaseUrl,[l,o]=jr.useState(null),[s,a]=jr.useState(!!t),[i,d]=jr.useState(null),f=jr.useRef(true),u=jr.useCallback(async()=>{if(!t){o(null),a(false);return}try{a(!0),d(null);let p=await fetch(`${n}/api/stacks/${encodeURIComponent(t)}/payout-capabilities`,{credentials:"include"});if(!p.ok)throw new Error(await R(p,`Failed to load payout capabilities (${p.status})`));let c=await p.json();f.current&&o(c);}catch(p){f.current&&d(p instanceof Error?p.message:"Failed to load payout capabilities");}finally{f.current&&a(false);}},[n,t]);return jr.useEffect(()=>(f.current=true,u(),()=>{f.current=false;}),[u]),{caps:l,loading:s,error:i,refresh:u}}function je({ok:e,label:r}){return jsxRuntime.jsxs("span",{className:m("inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-[11px] font-medium",e?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"),children:[e?jsxRuntime.jsx(lucideReact.CheckCircle2,{className:"h-3 w-3"}):jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-3 w-3"}),r]})}function yr({active:e,onClick:r,icon:t,label:n,sub:l}){return jsxRuntime.jsxs("button",{type:"button",onClick:r,className:m("flex flex-1 items-start gap-3 rounded-xl border p-4 text-left transition-colors",e?"border-foreground bg-foreground/5":"border-border hover:bg-muted/40"),children:[jsxRuntime.jsx("span",{className:m("flex h-8 w-8 shrink-0 items-center justify-center rounded-md",e?"bg-foreground text-background":"bg-muted text-foreground"),children:t}),jsxRuntime.jsxs("span",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"text-sm font-semibold text-foreground",children:n}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:l})]})]})}function io({onChange:e,className:r,style:t}){let{account:n,loading:l,error:o,refresh:s,disconnect:a,disconnecting:i}=De(),{caps:d,loading:f}=pr(),{startStripeConnect:u,starting:p,error:c}=ur(),{connectAndVerify:g,connecting:y,error:b}=fr(),k=!!d?.stripe.enabled,K=n?.method??null,[M,S]=jr.useState(K??"solana");jr.useEffect(()=>{K?S(K):!k&&M==="stripe"&&S("solana");},[K,k,M]);let G=async()=>{await u(),e?.();},z=async()=>{await g()&&(await s(),e?.());},L=async()=>{await a()&&e?.();};if(l||f)return jsxRuntime.jsxs("div",{className:m("space-y-3",r),style:t,children:[jsxRuntime.jsx("div",{className:"h-5 w-40 bg-muted animate-pulse rounded"}),jsxRuntime.jsx("div",{className:"h-24 w-full bg-muted animate-pulse rounded-xl"})]});if(o)return jsxRuntime.jsxs("div",{className:m("space-y-3",r),style:t,children:[jsxRuntime.jsx("h3",{className:"text-base font-semibold text-foreground",children:"Earnings Account"}),jsxRuntime.jsxs("div",{className:"rounded-xl border border-border bg-muted/20 p-4 text-sm text-muted-foreground space-y-3",children:[jsxRuntime.jsx("p",{children:"Earnings onboarding is temporarily unavailable. Try again in a moment."}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>s(),className:"inline-flex items-center gap-1 text-xs text-foreground underline-offset-4 hover:underline",children:[jsxRuntime.jsx(lucideReact.RefreshCw,{className:"h-3 w-3"}),"retry"]})]})]});let _=n?.solana,O=n?.stripe,ne=k||K==="stripe";return jsxRuntime.jsxs("div",{className:m("space-y-4",r),style:t,children:[jsxRuntime.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-base font-semibold text-foreground",children:"Earnings Account"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Connect a destination so you can be paid for filings."})]}),K&&jsxRuntime.jsxs("button",{type:"button",onClick:L,disabled:i,className:"inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-red-500 transition-colors disabled:opacity-50",children:[jsxRuntime.jsx(lucideReact.X,{className:"h-3 w-3"}),i?"disconnecting\u2026":"disconnect"]})]}),ne&&jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx(yr,{active:M==="solana",onClick:()=>S("solana"),icon:jsxRuntime.jsx(lucideReact.Wallet,{className:"h-4 w-4"}),label:"Crypto (Solana)",sub:"Connect a wallet, sign once"}),jsxRuntime.jsx(yr,{active:M==="stripe",onClick:()=>S("stripe"),icon:jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-4 w-4"}),label:"Bank (Stripe)",sub:"Stripe-hosted onboarding"})]}),M==="solana"&&jsxRuntime.jsx("div",{className:"space-y-3 rounded-xl border border-border p-4",children:_?jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Connected wallet"}),jsxRuntime.jsx(je,{ok:true,label:"verified"})]}),jsxRuntime.jsx("code",{className:"block text-xs text-foreground break-all",children:_.address}),jsxRuntime.jsxs("p",{className:"text-xs text-muted-foreground",children:["You signed a server-issued nonce on ",new Date(_.verifiedAt).toLocaleString(),"."]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("p",{className:"text-sm text-foreground",children:"Connect your Phantom wallet and sign a one-time message to prove you control the address. Filings paid in USDC will land here."}),b&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:b}),jsxRuntime.jsxs("button",{type:"button",onClick:z,disabled:y,className:m("inline-flex items-center gap-2 rounded-md bg-foreground text-background px-4 py-2 text-sm font-semibold transition-colors","hover:bg-foreground/90 disabled:opacity-50 disabled:cursor-not-allowed"),children:[jsxRuntime.jsx(lucideReact.Wallet,{className:"h-4 w-4"}),y?"Waiting for signature\u2026":"Connect Phantom & sign"]})]})}),M==="stripe"&&jsxRuntime.jsx("div",{className:"space-y-3 rounded-xl border border-border p-4",children:O?jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Stripe account"}),jsxRuntime.jsx("code",{className:"text-xs text-foreground",children:O.accountIdMasked})]}),jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2",children:[jsxRuntime.jsx(je,{ok:O.detailsSubmitted,label:"details"}),jsxRuntime.jsx(je,{ok:O.chargesEnabled,label:"charges"}),jsxRuntime.jsx(je,{ok:O.payoutsEnabled,label:"payouts"})]}),O.pendingOnboardingUrl&&jsxRuntime.jsxs("a",{href:j(O.pendingOnboardingUrl),className:"inline-flex items-center gap-1 text-sm text-foreground underline-offset-4 hover:underline",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-3.5 w-3.5"}),"Finish Stripe onboarding"]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("p",{className:"text-sm text-foreground",children:"We'll create a Stripe Express account under this stack's platform credentials and hand you off to Stripe to enter your bank details. Filings paid in USD will land in your bank."}),c&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:c}),jsxRuntime.jsxs("button",{type:"button",onClick:G,disabled:p,className:m("inline-flex items-center gap-2 rounded-md bg-foreground text-background px-4 py-2 text-sm font-semibold transition-colors","hover:bg-foreground/90 disabled:opacity-50 disabled:cursor-not-allowed"),children:[jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-4 w-4"}),p?"Opening Stripe\u2026":"Connect with Stripe"]})]})})]})}
|
|
2
|
+
exports.ASCII_KEY_ART=Me;exports.BottomSheet=Ie;exports.BuyKeyWidget=xs;exports.BuyPanel=Ze;exports.DefaultKeyArt=it;exports.FilePaperworkList=Os;exports.FilePaperworkView=ft;exports.FilingDetailView=mt;exports.FilingTracker=dt;exports.KeyBalanceBar=oe;exports.KeyCard=bt;exports.KeyDetailView=pt;exports.KeyList=Us;exports.KeyUtilsProvider=Oe;exports.KeysPanel=gt;exports.MintSuccess=Qe;exports.PayoutAccountPanel=io;exports.PayoutMethodPicker=zs;exports.SellPanel=vs;exports.SolanaPayButton=Ge;exports.TransferPanel=As;exports.TypingText=ut;exports.UsePanel=et;exports.useKeyUtilsContext=v;
|