@stacknet/keyutils 0.5.0 → 0.7.1
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 +10 -1
- package/dist/components/index.d.ts +10 -1
- package/dist/components/index.js +2 -2
- package/dist/hooks/index.cjs +2 -2
- package/dist/hooks/index.d.cts +45 -13
- package/dist/hooks/index.d.ts +45 -13
- package/dist/hooks/index.js +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.d.cts +40 -6
- package/dist/types/index.d.ts +40 -6
- package/dist/types/index.js +1 -0
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.cts +30 -2
- package/dist/utils/index.d.ts +30 -2
- package/dist/utils/index.js +1 -1
- package/package.json +13 -12
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),En=require('react'),jsxRuntime=require('react/jsx-runtime'),lucideReact=require('lucide-react');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var En__default=/*#__PURE__*/_interopDefault(En);var Kt=false;function H(){if(typeof document>"u")return {};let e=document.cookie.match(/(?:^|;\s*)__csrf=([^;]*)/);if(!e)return Kt||(Kt=true,console.warn("[keyutils] __csrf cookie not found; mutations will be sent without a CSRF token")),{};let t=e[1];try{t=decodeURIComponent(t);}catch{}return {"x-csrf-token":t}}var Cr=500;function Lt(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 S(e,t){try{let r=await e.json();if(r&&typeof r=="object"&&"error"in r)return Lt(r.error,t)}catch{}return t}function D(e,t="#"){if(!e||typeof e!="string")return t;let r=e.trim();if(r===""||r==="#")return t;if(r.startsWith("/")||r.startsWith("./")||r.startsWith("../"))return r;try{let n=new URL(r);if(n.protocol==="http:"||n.protocol==="https:")return n.toString()}catch{}return t}var He={sent:"sent",routed:"routed",confirmed:"confirmed",finalized:"finalized",filed:"filed"},Se={sent:{pending:"sent",progressing:"sending",done:"sent"},routed:{pending:"routed",progressing:"routing",done:"routed"},confirmed:{pending:"confirmed",progressing:"confirming",done:"confirmed"},finalized:{pending:"finalized",progressing:"finalizing",done:"finalized"},filed:{pending:"filed",progressing:"filing",done:"filed"}},Sr=["sent","routed","confirmed","finalized","filed"];function Ve(e){let t=new Map;(e??[]).forEach(a=>t.set(a.id,a));let r=Sr.map(a=>{let s=t.get(a);return s?{...s,label:s.label||He[a]}:{id:a,label:He[a],status:"pending",timestampMs:null,detail:null}}),n=r.reduce((a,s,o)=>s.status==="done"||s.status==="failed"?o:a,-1);if(n>0)for(let a=0;a<n;a++)r[a].status!=="failed"&&(r[a]={...r[a],status:"done"});if(!r.some(a=>a.status==="failed")){let a=r.findIndex(s=>s.status!=="done");if(a>=0){let s=r[a];s.status!=="current"&&(r[a]={...s,status:"current"});}}return r}function Bt(e){return e.find(t=>t.status==="current")??null}function Ft(e){return e.length>0&&e.every(t=>t.status==="done")}function At(e){return e.some(t=>t.status==="failed")}function We(e,t){if(!t)return {text:"loading",playing:true,stepId:"sent"};if(At(e))return {text:"failed",playing:false,stepId:"filed"};if(Ft(e))return {text:Se.filed.done,playing:false,stepId:"filed"};let n=Bt(e)?.id??"sent";return {text:Se[n].progressing,playing:true,stepId:n}}function f(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function A(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 Mt(e,t){return t<=0?0:Math.min(100,Math.round(e/t*100))}function _t(e){return e>=70?"bg-green-500":e>=30?"bg-yellow-500":"bg-red-500"}function Ae(e,t={}){let r=t.withSymbol!==false,n=Math.max(0,Math.min(6,t.maxDecimals??2));if(e==null||e==="")return r?"$0.00":"0.00";let l;try{if(typeof e=="bigint")l=e;else if(typeof e=="number")l=BigInt(Math.trunc(e));else {let u=String(e).trim().replace(/^\+/,"");if(/^-?\d+$/.test(u))l=BigInt(u);else {let g=Number(u);if(!Number.isFinite(g))return r?"$0.00":"0.00";l=BigInt(Math.trunc(g));}}}catch{return r?"$0.00":"0.00"}let a=l<0n,s=a?-l:l,o=s/1000000n,d=(s%1000000n).toString().padStart(6,"0").slice(0,n),c=o.toLocaleString("en-US"),m=n>0?`.${d}`:"";return `${a?"-":""}${r?"$":""}${c}${m}`}function ee(e){if(e==null||e==="")return "";let t=typeof e=="string"&&/^\d+$/.test(e)?Number(e):e,r=new Date(t);return isNaN(r.getTime())?"":r.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function Dt(){if(typeof navigator>"u")return "mac";let e=navigator.userAgent.toLowerCase();return /iphone|ipad|ipod/.test(e)?"ios":/android/.test(e)?"android":/win/.test(e)?"windows":/linux/.test(e)?"linux":"mac"}var $t=En.createContext(null);function h(){let e=En.useContext($t);if(!e)throw new Error("useKeyUtilsContext must be used within a KeyUtilsProvider");return e}function ze({config:e,callbacks:t={},children:r}){typeof e.apiBaseUrl!="string"&&console.error("[KeyUtils] apiBaseUrl must be a string");let n=En.useMemo(()=>({config:e,callbacks:t}),[e,t]);return jsxRuntime.jsx($t.Provider,{value:n,children:r})}function qe(){let{config:e}=h(),[t,r]=En.useState(null),[n,l]=En.useState(true),[a,s]=En.useState(null),o=En.useRef(true),i=En.useRef(e.apiBaseUrl);i.current=e.apiBaseUrl;let d=async()=>{try{o.current&&(l(!0),s(null));let c=await fetch(`${i.current}/api/keys/pricing`,{credentials:"include"});if(!c.ok)throw new Error(await S(c,`Pricing unavailable (${c.status})`));let m=await c.json();o.current&&r(m);}catch(c){o.current&&s(c instanceof Error?c.message:"Failed to fetch pricing");}finally{o.current&&l(false);}};return En.useEffect(()=>{o.current=true,d();let c=setInterval(d,6e4);return ()=>{o.current=false,clearInterval(c);}},[]),{pricing:t,loading:n,error:a,refresh:d}}function Mr(e){return {id:e.id||"",keyIndex:e.keyIndex??e.key_index??null,key:e.id||e.key||e.keyPrefix||"",userId:e.userId||e.user_id||"",status:e.status||"active",tokenBalance:e.tokenBalance??e.currentTokenBalance??e.current_token_balance??0,maxTokens:e.maxTokens??e.initialTokenBalance??e.initial_token_balance??0,createdAt:String(e.createdAt??e.created_at??""),expiresAt:e.expiresAt,label:e.label||void 0,paperWork:e.paperWork||e.paper_work||void 0,stackId:e.stackId,stackName:e.stackName}}function te(){let{config:e}=h(),[t,r]=En.useState([]),[n,l]=En.useState(true),[a,s]=En.useState(null),o=En.useRef(true),i=e.apiBaseUrl,d=En.useCallback(async()=>{try{l(!0),s(null);let m=await fetch(`${i}/api/keys`,{credentials:"include"});if(!m.ok)throw new Error(await S(m,`Failed to fetch keys (${m.status})`));let p=await m.json(),u=Array.isArray(p)?p:p.keys??[];o.current&&r(u.map(Mr));}catch(m){o.current&&s(m instanceof Error?m.message:"Failed to fetch keys");}finally{o.current&&l(false);}},[i]);En.useEffect(()=>(o.current=true,d(),()=>{o.current=false;}),[d]);let c=t.reduce((m,p)=>m+p.tokenBalance,0);return {keys:t,totalBalance:c,loading:n,error:a,refresh:d}}function Ge(e){let t=e.type||e.entry_type||"debit",r=e.amount??e.tokens??e.token_amount??0,n=e.description||e.memo||e.reason||_r(t);return {id:e.id||"",keyId:e.keyId||e.key_id||"",type:t,amount:r,description:n,createdAt:String(e.createdAt??e.created_at??e.timestamp??""),metadata:e.metadata||void 0}}function _r(e){switch(e){case "credit":return "Credit";case "debit":return "Usage";case "mint":return "Mint";case "reward":return "Reward";default:return ""}}function Dr(e){return {id:e.id||"",keyIndex:e.keyIndex??e.key_index??null,key:e.id||e.key||e.keyPrefix||"",userId:e.userId||e.user_id||"",status:e.status||"active",tokenBalance:e.tokenBalance??e.currentTokenBalance??e.current_token_balance??0,maxTokens:e.maxTokens??e.initialTokenBalance??e.initial_token_balance??0,createdAt:String(e.createdAt??e.created_at??""),expiresAt:e.expiresAt,label:e.label||void 0,paperWork:e.paperWork||e.paper_work||void 0,stackId:e.stackId,stackName:e.stackName}}async function $r(e){if(!e)return {};let t=e();return t instanceof Promise?await t:t}function jr(e){if(!e)return false;let t=e.toUpperCase();return t==="POST"||t==="PUT"||t==="PATCH"||t==="DELETE"}async function be(e,t={}){let{getHeaders:r,...n}=t,l=await $r(r),a=jr(n.method)?H():{},s=await fetch(e,{...n,headers:{"Content-Type":"application/json",...a,...l,...n.headers},credentials:"include"});if(!s.ok)throw new Error(await S(s,`Request failed (${s.status})`));return s.json()}function Or(e){let{apiBaseUrl:t,stackId:r,stackName:n,getHeaders:l}=e,a=`${t}/api/keys`;return {async getKeys(){let s=await be(a,{getHeaders:l});return (Array.isArray(s)?s:s.keys??[]).map(Dr)},async getLedger(s){let o=await be(`${a}/${encodeURIComponent(s)}/ledger`,{getHeaders:l});return (Array.isArray(o)?o:o.entries??[]).map(Ge)},async getPricing(){return be(`${a}/pricing`,{getHeaders:l})},async mint(s,o,i=1){try{let d=await be(a+"/mint",{method:"POST",body:JSON.stringify({paymentMethod:s,paymentRef:o,quantity:i,stackId:r}),getHeaders:l}),c=d.keys?.[0]||d;return {success:!0,key:{id:c.keyId||c.id||"",key:c.key||"",userId:c.userId||"",status:"active",tokenBalance:c.tokenBalance??c.currentTokenBalance??0,maxTokens:c.initialTokenBalance??c.tokenBalance??0,createdAt:String(c.createdAt||Date.now())},transactionId:o}}catch(d){return {success:false,error:d instanceof Error?d.message:"Key generation failed"}}},async listKey(s,o){return be(`${a}/${encodeURIComponent(s)}/list`,{method:"POST",body:JSON.stringify({askPriceCents:o,stackId:r,stackName:n}),getHeaders:l})},async delistKey(s){await be(`${a}/${encodeURIComponent(s)}/list`,{method:"DELETE",getHeaders:l});},async transferKey(s,o){return be(`${a}/${encodeURIComponent(s)}/transfer`,{method:"POST",body:JSON.stringify({recipientId:o}),getHeaders:l})},async createStripeSession(s,o,i){return be(`${a}/stripe-session`,{method:"POST",body:JSON.stringify({priceCents:s,quantity:o,stackId:r,referrerUrl:i}),getHeaders:l})}}}function Re(e){let{config:t}=h(),[r,n]=En.useState([]),[l,a]=En.useState(false),[s,o]=En.useState(null),i=En.useRef(true),d=t.apiBaseUrl,c=En.useCallback(async()=>{if(e)try{a(!0),o(null);let m=await fetch(`${d}/api/keys/${encodeURIComponent(e)}/ledger`,{credentials:"include"});if(!m.ok)throw new Error(await S(m,`Failed to fetch ledger (${m.status})`));let p=await m.json(),u=Array.isArray(p)?p:p.entries??[];i.current&&n(u.map(Ge));}catch(m){i.current&&o(m instanceof Error?m.message:"Failed to fetch ledger");}finally{i.current&&a(false);}},[d,e]);return En.useEffect(()=>(i.current=true,c(),()=>{i.current=false;}),[c]),{entries:r,loading:l,error:s,refresh:c}}function Ze(){let{config:e,callbacks:t}=h(),[r,n]=En.useState(false),[l,a]=En.useState(null),[s,o]=En.useState(null);return {mint:En.useCallback(async(d,c,m=1)=>{try{n(!0),o(null),t.onPaymentComplete?.(d,c);let p=await fetch(`${e.apiBaseUrl}/api/keys/mint`,{method:"POST",headers:{"Content-Type":"application/json",...H()},credentials:"include",body:JSON.stringify({paymentMethod:d,paymentRef:c,quantity:m,stackId:e.stackId})});if(!p.ok)throw new Error(await S(p,`Key generation failed (${p.status})`));let u=await p.json(),g=u.keys?.[0]||u,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:c};return a(y),t.onMintSuccess?.(y),y}catch(p){let u=p instanceof Error?p:new Error("Key generation failed");return o(u.message),t.onMintError?.(u),{success:false,error:u.message}}finally{n(false);}},[e.apiBaseUrl,t]),minting:r,result:l,error:s}}function Te(){let{config:e,callbacks:t}=h(),[r,n]=En.useState(false),[l,a]=En.useState(null),[s,o]=En.useState(null),i=En.useRef(true),d=En.useCallback(async(m,p)=>{try{n(!0),o(null);let u=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(m)}/list`,{method:"POST",headers:{"Content-Type":"application/json",...H()},credentials:"include",body:JSON.stringify({askPriceCents:p,stackId:e.stackId,stackName:e.stackName})});if(!u.ok)throw new Error(await S(u,`Listing failed (${u.status})`));let g=await u.json();return i.current&&(a(g),t.onListingCreated?.(g)),g}catch(u){let g=u instanceof Error?u.message:"Listing failed";return i.current&&o(g),null}finally{i.current&&n(false);}},[e.apiBaseUrl,e.stackId,e.stackName,t]),c=En.useCallback(async m=>{try{n(!0),o(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(m)}/list`,{method:"DELETE",headers:{...H()},credentials:"include"});if(!p.ok)throw new Error(await S(p,`Delist failed (${p.status})`));return i.current&&a(null),!0}catch(p){let u=p instanceof Error?p.message:"Delist failed";return i.current&&o(u),false}finally{i.current&&n(false);}},[e.apiBaseUrl]);return {listKey:d,delistKey:c,listing:r,result:l,error:s}}function tt(){let{config:e}=h(),[t,r]=En.useState(false),[n,l]=En.useState(null),a=En.useRef(true);return {createSession:En.useCallback(async(o,i)=>{try{r(!0),l(null);let d=await fetch(`${e.apiBaseUrl}/api/keys/stripe-session`,{method:"POST",headers:{"Content-Type":"application/json",...H()},credentials:"include",body:JSON.stringify({priceCents:o,quantity:i,stackId:e.stackId,referrerUrl:window.location.href})});if(!d.ok)throw new Error(await S(d,`Checkout failed (${d.status})`));let{url:c}=await d.json();if(!c)throw new Error("No checkout URL returned");let m;try{m=new URL(c);}catch{throw new Error("Invalid checkout URL")}if(m.protocol!=="https:"||!/(^|\.)stripe\.com$/.test(m.hostname))throw new Error("Refusing to redirect to non-Stripe URL");try{sessionStorage.setItem("keyutils_stripe_pending","1"),sessionStorage.setItem("keyutils_stripe_quantity",String(i));}catch{}window.location.href=m.toString();}catch(d){if(a.current){let c=d instanceof Error?d.message:"Checkout failed";l(c),r(false);}}},[e.apiBaseUrl,e.stackId]),loading:t,error:n}}var Wt=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function Qr(){let{config:e}=h(),[t,r]=En.useState(false),[n,l]=En.useState(null);return {pay:En.useCallback(async s=>{if(!e.merchantWallet||!Wt.test(e.merchantWallet))throw new Error("Merchant wallet not configured");try{r(!0),l(null);let{Connection:o,PublicKey:i,Transaction:d,SystemProgram:c}=await import('@solana/web3.js'),m=typeof window<"u"?window.solana:void 0;if(!m||typeof m!="object"||!m.isPhantom)throw new Error("Phantom wallet not found. Please install Phantom.");let p=m,u=new i(e.merchantWallet),g=await p.connect(),y=new i(g.publicKey.toString()),b="https://api.mainnet-beta.solana.com",k=D(e.solanaRpcUrl,b),I=k==="#"?b:k,F=new o(I),{blockhash:P}=await F.getLatestBlockhash(),z=BigInt(Math.floor(s*1e9)),V=e.protocolTreasuryWallet,U=e.protocolFeeBps??500,B=new d({recentBlockhash:P,feePayer:y});if(V&&Wt.test(V)&&U>0){let Q=z*BigInt(U)/10000n,O=z-Q,Z=new i(V);B.add(c.transfer({fromPubkey:y,toPubkey:u,lamports:Number(O)}),c.transfer({fromPubkey:y,toPubkey:Z,lamports:Number(Q)}));}else B.add(c.transfer({fromPubkey:y,toPubkey:u,lamports:Number(z)}));let{signature:j}=await p.signAndSendTransaction(B);return j}catch(o){let i=o instanceof Error?o:new Error("SOL payment failed");throw l(i.message),i}finally{r(false);}},[e.merchantWallet,e.protocolTreasuryWallet,e.protocolFeeBps,e.solanaRpcUrl]),processing:t,error:n}}function Ie(){let{config:e,callbacks:t}=h(),[r,n]=En.useState(false),[l,a]=En.useState(null),[s,o]=En.useState(null),i=En.useRef(true);return {transferKey:En.useCallback(async(c,m)=>{try{n(!0),o(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(c)}/transfer`,{method:"POST",headers:{"Content-Type":"application/json",...H()},credentials:"include",body:JSON.stringify({recipientId:m})});if(!p.ok)throw new Error(await S(p,`Transfer failed (${p.status})`));let u=await p.json();return i.current&&(a(u),t.onTransferComplete?.(u)),u}catch(p){let u=p instanceof Error?p.message:"Transfer failed";return i.current&&o(u),null}finally{i.current&&n(false);}},[e.apiBaseUrl,t]),transferring:r,result:l,error:s}}function st(){let{config:e,callbacks:t}=h(),[r,n]=En.useState(false),[l,a]=En.useState(null),[s,o]=En.useState(null),i=En.useRef(true);En.useEffect(()=>(i.current=true,()=>{i.current=false;}),[]);let d=En.useCallback(async(m,p)=>{try{n(!0),o(null);let u={stackId:e.stackId};p&&(u.payoutMethod=p);let g=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(m)}/file`,{method:"POST",headers:{"Content-Type":"application/json",...H()},credentials:"include",body:JSON.stringify(u)});if(!g.ok)throw new Error(await S(g,`Filing failed (${g.status})`));let y=await g.json();return i.current&&(a(y),t.onFilingComplete?.(y)),y}catch(u){let g=u instanceof Error?u:new Error("Filing failed");return i.current&&o(g.message),t.onFilingError?.(g),null}finally{i.current&&n(false);}},[e.apiBaseUrl,e.stackId,t]),c=En.useCallback(()=>{a(null),o(null);},[]);return {filePaperwork:d,filing:r,result:l,error:s,reset:c}}function on(){let{config:e}=h(),[t,r]=En.useState([]),[n,l]=En.useState(true),[a,s]=En.useState(null),o=En.useRef(true),i=e.apiBaseUrl,d=En.useCallback(async()=>{try{l(!0),s(null);let c=await fetch(`${i}/api/keys/filings`,{credentials:"include"});if(!c.ok)throw new Error(await S(c,`Failed to fetch filings (${c.status})`));let m=await c.json(),p=Array.isArray(m)?m:m.filings??[];o.current&&r(p);}catch(c){o.current&&s(c instanceof Error?c.message:"Failed to fetch filings");}finally{o.current&&l(false);}},[i]);return En.useEffect(()=>(o.current=true,d(),()=>{o.current=false;}),[d]),{entries:t,loading:n,error:a,refresh:d}}function it(e){let{config:t}=h(),r=e??t.stackId,n=t.apiBaseUrl,[l,a]=En.useState(null),[s,o]=En.useState(!!r),[i,d]=En.useState(null),c=En.useRef(true),m=En.useCallback(async()=>{if(!r){a(null),o(false);return}try{o(!0),d(null);let p=await fetch(`${n}/api/stacks/${encodeURIComponent(r)}/payout-capabilities`,{credentials:"include"});if(!p.ok)throw new Error(await S(p,`Failed to load payout capabilities (${p.status})`));let u=await p.json();c.current&&a(u);}catch(p){c.current&&d(p instanceof Error?p.message:"Failed to load payout capabilities");}finally{c.current&&o(false);}},[n,r]);return En.useEffect(()=>(c.current=true,m(),()=>{c.current=false;}),[m]),{caps:l,loading:s,error:i,refresh:m}}var fn=5e3;function pn(e){return e==="paid"||e==="failed"}function ct(e){let{config:t}=h(),r=t.apiBaseUrl,[n,l]=En.useState(null),[a,s]=En.useState(!!e),[o,i]=En.useState(null),d=En.useRef(true),c=En.useCallback(async()=>{if(!e){l(null),s(false);return}try{i(null);let m=await fetch(`${r}/api/keys/filings/${encodeURIComponent(e)}`,{credentials:"include"});if(!m.ok)throw new Error(await S(m,`Failed to load filing (${m.status})`));let p=await m.json();d.current&&l(p);}catch(m){d.current&&i(m instanceof Error?m.message:"Failed to load filing");}finally{d.current&&s(false);}},[r,e]);return En.useEffect(()=>{if(d.current=true,!e)return l(null),s(false),()=>{d.current=false;};s(true),c();let m=setInterval(()=>{d.current&&(n&&pn(n.status)||c());},fn);return ()=>{d.current=false,clearInterval(m);}},[e,c,n]),{detail:n,loading:a,error:o,refresh:c}}function Ee(){let{config:e}=h(),[t,r]=En.useState(null),[n,l]=En.useState(true),[a,s]=En.useState(null),[o,i]=En.useState(false),d=En.useRef(true),c=e.apiBaseUrl,m=En.useCallback(async()=>{try{l(!0),s(null);let u=await fetch(`${c}/api/payout`,{credentials:"include"});if(!u.ok)throw new Error(await S(u,`Failed to load payout account (${u.status})`));let g=await u.json();d.current&&r(g);}catch(u){d.current&&s(u instanceof Error?u.message:"Failed to load payout account");}finally{d.current&&l(false);}},[c]);En.useEffect(()=>(d.current=true,m(),()=>{d.current=false;}),[m]);let p=En.useCallback(async()=>{try{i(!0),s(null);let u=await fetch(`${c}/api/payout`,{method:"DELETE",headers:{...H()},credentials:"include"});if(!u.ok&&u.status!==204)throw new Error(await S(u,`Disconnect failed (${u.status})`));return d.current&&r({method:null}),!0}catch(u){return d.current&&s(u instanceof Error?u.message:"Disconnect failed"),false}finally{d.current&&i(false);}},[c]);return {account:t,loading:n,error:a,refresh:m,disconnect:p,disconnecting:o}}function dt(){let{config:e}=h(),[t,r]=En.useState(false),[n,l]=En.useState(null);return {startStripeConnect:En.useCallback(async()=>{try{r(!0),l(null);let s=await fetch(`${e.apiBaseUrl}/api/payout/stripe/start`,{method:"POST",headers:{"Content-Type":"application/json",...H()},credentials:"include",body:JSON.stringify({stackId:e.stackId})});if(!s.ok)throw new Error(await S(s,`Stripe Connect start failed (${s.status})`));let o=await s.json();if(typeof window<"u"&&o.onboardingUrl){let i;try{i=new URL(o.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{r(false);}},[e.apiBaseUrl,e.stackId]),starting:t,error:n}}function hn(){if(typeof window>"u")return null;let e=window,t=e.solana,r=e.phantom?.solana;return ((t&&t.isPhantom?t:null)||(r&&r.isPhantom?r:null))??null}function kn(e){let t="";for(let r=0;r<e.length;r+=1)t+=String.fromCharCode(e[r]);return typeof btoa=="function"?btoa(t):Buffer.from(e).toString("base64")}function ut(){let{config:e}=h(),[t,r]=En.useState(false),[n,l]=En.useState(null);return {connectAndVerify:En.useCallback(async()=>{try{r(!0),l(null);let s=hn();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",...H()},credentials:"include",body:JSON.stringify({address:i})});if(!d.ok)throw new Error(await S(d,`Nonce request failed (${d.status})`));let{nonce:c,message:m}=await d.json(),p=new TextEncoder().encode(m),u=await s.signMessage(p,"utf8"),g=kn(u.signature),y=await fetch(`${e.apiBaseUrl}/api/payout/crypto/verify`,{method:"POST",headers:{"Content-Type":"application/json",...H()},credentials:"include",body:JSON.stringify({address:i,nonce:c,signature:g})});if(!y.ok)throw new Error(await S(y,`Verification failed (${y.status})`));return {address:i}}catch(s){let o=s instanceof Error?s:new Error("Wallet verification failed");return l(o.message),null}finally{r(false);}},[e.apiBaseUrl]),connecting:t,error:n}}var Qt=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function pt({amountSol:e,onSuccess:t,onError:r,disabled:n,className:l,style:a}){let{config:s}=h(),[o,i]=En.useState(false),[d,c]=En.useState(null),m=!!(s.merchantWallet&&Qt.test(s.merchantWallet)),p=En.useCallback(async()=>{if(m)try{i(!0),c(null);let{Connection:u,PublicKey:g,Transaction:y,SystemProgram:b,LAMPORTS_PER_SOL:k}=await import('@solana/web3.js'),I=typeof window<"u"?window.solana:void 0;if(!I||typeof I!="object"||!I.isPhantom)throw new Error("Phantom wallet not found. Please install Phantom.");let F=I,P;try{P=new g(s.merchantWallet);}catch{throw new Error("Invalid merchant wallet address.")}let z=await F.connect(),V=new g(z.publicKey.toString()),U="https://api.mainnet-beta.solana.com",B=D(s.solanaRpcUrl,U),j=B==="#"?U:B,Q=new u(j),{blockhash:O}=await Q.getLatestBlockhash(),Z=BigInt(Math.floor(e*1e9)),xe=s.protocolTreasuryWallet,me=s.protocolFeeBps??500,ie=new y({recentBlockhash:O,feePayer:V});if(xe&&Qt.test(xe)&&me>0){let le=Z*BigInt(me)/10000n,wr=Z-le,Pr=new g(xe);ie.add(b.transfer({fromPubkey:V,toPubkey:P,lamports:Number(wr)}),b.transfer({fromPubkey:V,toPubkey:Pr,lamports:Number(le)}));}else ie.add(b.transfer({fromPubkey:V,toPubkey:P,lamports:Number(Z)}));let{signature:ye}=await F.signAndSendTransaction(ie);t(ye);}catch(u){let g=u instanceof Error?u:new Error("Payment failed");c(g.message),r?.(g);}finally{i(false);}},[e,s.merchantWallet,m,t,r]);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("button",{onClick:p,disabled:n||o||!m,"aria-label":`Pay ${e.toFixed(4)} SOL`,className:f("flex w-full items-center justify-center gap-2 rounded-2xl bg-purple-600 py-6 text-base font-semibold text-white transition-colors hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed",l),style:a,children:o?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader2,{className:"h-4 w-4 animate-spin"}),"Processing..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Pay ",e.toFixed(4)," SOL"]})}),d&&jsxRuntime.jsx("p",{className:"mt-2 text-center text-xs text-red-500",children:d})]})}function gt({result:e,className:t,style:r}){let[n,l]=En.useState(false),a=En.useRef(null);En.useEffect(()=>()=>{a.current&&clearTimeout(a.current);},[]);let s=En.useCallback(()=>{e.key?.key&&(navigator.clipboard.writeText(e.key.key),l(true),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>l(false),2e3));},[e.key?.key]);return !e.success||!e.key?null:jsxRuntime.jsxs("div",{className:f("rounded-lg border border-green-500/20 bg-green-500/10 p-6 text-center",t),style:r,children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"mx-auto mb-3 h-12 w-12 text-green-500"}),jsxRuntime.jsx("h3",{className:"mb-2 text-lg font-semibold text-foreground",children:"Key Generated!"}),jsxRuntime.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Your node key has been successfully generated."}),jsxRuntime.jsxs("div",{className:"mx-auto flex max-w-md items-center gap-2 rounded-md border bg-background p-3",children:[jsxRuntime.jsx("code",{className:"flex-1 truncate text-xs text-foreground",children:e.key.key}),jsxRuntime.jsx("button",{onClick: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:f("animate-pulse rounded-xl bg-muted",e)})}function xt(){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 he({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(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"})]})]},r))})}function _n({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 tr({pricing:e,quantity:t}){let[r,n]=En.useState(false),l=e.priceUsd*t;return jsxRuntime.jsxs("div",{className:"rounded-2xl border bg-background",children:[jsxRuntime.jsxs("button",{onClick:()=>n(!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:["$",l.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:["$",l.toFixed(2)]})]})]})]})}function yt({className:e,style:t}){let{config:r}=h(),{pricing:n,loading:l,error:a,refresh:s}=qe(),{mint:o,minting:i,result:d,error:c}=Ze(),{createSession:m,loading:p,error:u}=tt(),[g,y]=En.useState(1),[b,k]=En.useState(r.paymentMethods?.includes("stripe")?"stripe":"solana"),[I,F]=En.useState(0),[P,z]=En.useState(false),V=En__default.default.useRef(g);V.current=g;let U=Math.max(1,r.maxQuantity||5),B=[...r.paymentMethods||["solana"]].sort((O,Z)=>O==="stripe"?-1:Z==="stripe"?1:0);if(En.useEffect(()=>{if(typeof window>"u")return;let Z=new URLSearchParams(window.location.search).get("session_id");if(!Z){try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}return}if(/^cs_(test|live)_/.test(Z)&&!P&&!d?.success){let xe=false;try{xe=sessionStorage.getItem("keyutils_stripe_pending")==="1";}catch{}if(!xe)return;try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}z(true);let me=new URL(window.location.href);me.searchParams.delete("session_id"),window.history.replaceState({},"",me.toString());let ie=V.current;try{let ye=sessionStorage.getItem("keyutils_stripe_quantity");ye&&(ie=parseInt(ye,10)||1,sessionStorage.removeItem("keyutils_stripe_quantity"));}catch{}o("stripe",Z,ie);}},[P,d,o]),d?.success)return jsxRuntime.jsx("div",{className:f("flex flex-col items-center justify-center",e),style:t,children:jsxRuntime.jsx(gt,{result:d})});if(P||i)return jsxRuntime.jsx("div",{className:f("flex flex-col",e),style:t,children:jsxRuntime.jsx(xt,{})});if(l)return jsxRuntime.jsx("div",{className:f("flex flex-col",e),style:t,children:jsxRuntime.jsx(xt,{})});if(a||!n)return jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-24",e),style:t,children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load pricing"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a||"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 j=async O=>{F(2),await o(b,O,g);},Q=()=>{m(n.priceCents,g);};return jsxRuntime.jsx("div",{className:f("flex flex-col",e),style:t,children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[I===0&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[r.keyImage&&jsxRuntime.jsx("img",{src:D(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:["$",n.priceUsd.toFixed(2)]}),jsxRuntime.jsxs("p",{className:"mt-2 text-base text-muted-foreground",children:["per key \xB7 ",n.tokenAllocationFormatted||A(n.tokenAllocation)," tokens included"]})]}),jsxRuntime.jsx(_n,{quantity:g,max:U,onChange:y}),jsxRuntime.jsx(tr,{pricing:n,quantity:g}),jsxRuntime.jsx("button",{onClick:()=>F(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"})]}),I===1&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[B.length>1&&jsxRuntime.jsx("div",{role:"tablist",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:B.map(O=>jsxRuntime.jsxs("button",{role:"tab","aria-selected":b===O,onClick:()=>k(O),className:f("flex flex-1 items-center justify-center gap-2.5 rounded-xl py-4 text-sm font-medium transition-colors",b===O?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[O==="stripe"?jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-5 w-5"}):jsxRuntime.jsx(lucideReact.Wallet,{className:"h-5 w-5"}),O==="stripe"?"Credit Card":"Crypto"]},O))}),jsxRuntime.jsx(tr,{pricing:n,quantity:g}),b==="stripe"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{onClick:Q,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"]})}),u&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-500",children:u})]}):b==="solana"?jsxRuntime.jsx(pt,{amountSol:n.priceSol??0,onSuccess:j}):null,c&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-500",children:c}),jsxRuntime.jsx("button",{type:"button",onClick:()=>F(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 On={ios:"iOS",android:"Android",windows:"Windows",mac:"macOS",linux:"Linux"},Hn=["mac","windows","linux","ios","android"],Vn="https://www.stacknet.org/download";function bt({downloads:e,className:t,style:r}){let{config:n}=h(),l=En.useMemo(()=>Dt(),[]),a=e||Hn.map(i=>({platform:i,label:On[i],url:Vn,compatible:i===l})),s=a.find(i=>i.compatible)||a[0],o=a.filter(i=>i.platform!==s.platform);return jsxRuntime.jsxs("div",{className:f("space-y-8",t),style:r,children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-6 pt-4 mt-4",children:[n.aispImage&&jsxRuntime.jsx("img",{src:D(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:D(s.url),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-3 rounded-full px-10 py-4 text-lg font-semibold text-white transition-colors hover:opacity-90",style:{backgroundColor:"#0900f4"},children:[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"," ",o.map((i,d)=>jsxRuntime.jsxs(En__default.default.Fragment,{children:[d>0&&(d===o.length-1?" and ":", "),jsxRuntime.jsx("a",{href:D(i.url),target:"_blank",rel:"noopener noreferrer",className:"font-medium underline transition-colors hover:text-foreground",style:{color:"#066bff"},children:i.label})]},i.platform)),"."]}),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:D(n.termsUrl,"/terms"),target:"_blank",rel:"noopener noreferrer",className:"text-foreground underline hover:text-foreground/80",children:"Open Source Applications Terms"})]})]})]})}var Wn={"bg-green-500":"bg-green-900/50","bg-yellow-500":"bg-yellow-900/50","bg-red-500":"bg-red-900/50"};function oe({current:e,max:t,className:r,style:n,showLabel:l=true,segments:a=40}){let s=Mt(e,t),o=_t(s),i=Wn[o]||"bg-muted",d=Math.round(s/100*a);return jsxRuntime.jsxs("div",{className:f("w-full",r),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:[A(e)," / ",A(t)]}),jsxRuntime.jsxs("span",{children:[s,"%"]})]}),jsxRuntime.jsx("div",{className:"flex h-6 w-full items-stretch gap-1",children:Array.from({length:a}).map((c,m)=>jsxRuntime.jsx("div",{className:f("flex-1 rounded-[1px] transition-colors duration-300",m<d?o:i)},m))})]})}function Be({open:e,onClose:t,title:r,children:n}){let l=En.useRef(null),[a,s]=En.useState(false),[o,i]=En.useState(false),d=En.useCallback(c=>{c.key==="Escape"&&t();},[t]);return En.useEffect(()=>{if(e)s(true),document.addEventListener("keydown",d),document.body.style.overflow="hidden",requestAnimationFrame(()=>{requestAnimationFrame(()=>i(true));});else {i(false);let c=setTimeout(()=>{s(false),document.body.style.overflow="";},300);return document.removeEventListener("keydown",d),()=>clearTimeout(c)}return ()=>{document.removeEventListener("keydown",d);}},[e,d]),a?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",children:[jsxRuntime.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm transition-opacity duration-300",style:{opacity:o?1:0},onClick:t}),jsxRuntime.jsxs("div",{ref:l,className:f("relative z-10 w-full max-w-xl rounded-t-2xl bg-background shadow-2xl","max-h-[85vh] flex flex-col","transition-transform duration-300 ease-out"),style:{transform:o?"translateY(0)":"translateY(100%)"},children:[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:n})]})]}):null}var $e=[" .-----."," / (_) \\"," / \\","( )"," \\ /"," \\_______/"," || |"," || |"," || /"," || /"," || \\"," || /"," || /"," \\// "],kt=16,Gn=kt*.6,sr=kt*1;function vt({className:e,style:t,color:r="currentColor",ariaLabel:n="Node key",keyImage:l,keyImageClass:a}){if(l)return jsxRuntime.jsx("img",{src:D(l),alt:n,className:f(a||"h-20 w-auto mx-auto",e),style:t});let s=$e.reduce((p,u)=>Math.max(p,u.length),0),o=$e.length,i=s*Gn,c=o*sr;return jsxRuntime.jsx("svg",{viewBox:`0 0 ${c} ${i}`,xmlns:"http://www.w3.org/2000/svg",className:f("block",e),style:t,role:"img","aria-label":n,preserveAspectRatio:"xMidYMid meet",children:jsxRuntime.jsx("g",{transform:`translate(0 ${i}) rotate(-90)`,children:$e.map((p,u)=>jsxRuntime.jsx("text",{x:0,y:(u+.8)*sr,fill:r,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:kt,xmlSpace:"preserve",children:p},u))})})}function rs(e){if(!e)return "";try{return new Date(e).toLocaleTimeString()}catch{return ""}}function ns({state:e,isLast:t}){let r=e.status==="done",n=e.status==="current",l=e.status==="failed",a=r?lucideReact.Check:l?lucideReact.AlertCircle:n?lucideReact.ArrowRight:lucideReact.Circle,s=f("flex h-8 w-8 shrink-0 items-center justify-center rounded-full",n&&"bg-foreground text-background",r&&"bg-green-500/15 text-green-500",l&&"bg-red-500/15 text-red-500",!r&&!n&&!l&&"bg-muted text-muted-foreground"),o=Se[e.id],i=r?o.done:n?o.progressing:o.pending;return 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(a,{className:"h-4 w-4"})}),!t&&jsxRuntime.jsx("div",{className:f("w-px flex-1 mt-1",r?"bg-green-500/30":"bg-border"),style:{minHeight:32}})]}),jsxRuntime.jsxs("div",{className:f("flex-1 pb-6",t&&"pb-0"),children:[jsxRuntime.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[jsxRuntime.jsxs("span",{className:f("text-sm font-medium lowercase",r&&"text-foreground font-bold",n&&"text-foreground",l&&"text-red-500",!r&&!n&&!l&&"text-muted-foreground"),children:[i,e.id==="confirmed"&&e.approvalsCount!=null&&e.approvalsThreshold!=null&&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:rs(e.timestampMs)})]}),e.detail&&jsxRuntime.jsx("p",{className:f("mt-0.5 text-xs",l?"text-red-500":"text-muted-foreground"),children:e.detail}),e.externalUrl&&jsxRuntime.jsxs("a",{href:D(e.externalUrl),target:"_blank",rel:"noopener noreferrer",className:"mt-1 inline-flex items-center gap-1 text-xs text-foreground/80 hover:text-foreground underline-offset-4 hover:underline",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-3 w-3"}),"view"]})]})]})}function Nt({states:e,className:t}){return jsxRuntime.jsx("ol",{className:f("flex flex-col",t),children:e.map((r,n)=>jsxRuntime.jsx(ns,{state:r,isLast:n===e.length-1},r.id))})}function wt({text:e,speedMs:t=40,playing:r,className:n}){let[l,a]=En.useState(()=>r?"":e);return En.useEffect(()=>{if(!r){a(e);return}a("");let s=0,o=false,i,d=()=>{o||(s+=1,a(e.slice(0,s)),s<e.length&&(i=setTimeout(d,t)));};return i=setTimeout(d,t),()=>{o=true,clearTimeout(i);}},[e,t,r]),jsxRuntime.jsxs("span",{className:n,children:[l,r?jsxRuntime.jsx("span",{"aria-hidden":"true",className:"font-mono font-normal opacity-70",children:"\u258A"}):null]})}function pe(e,t=6,r=6){return e?e.length<=t+r+1?e:`${e.slice(0,t)}\u2026${e.slice(-r)}`:""}function ps({value:e}){let[t,r]=En.useState(false);return jsxRuntime.jsx("button",{type:"button",onClick:()=>{typeof navigator>"u"||!navigator.clipboard||(navigator.clipboard.writeText(e),r(true),setTimeout(()=>r(false),1200));},className:"text-muted-foreground hover:text-foreground transition-colors","aria-label":"Copy",children:t?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 J({label:e,value:t,href:r,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:[r?jsxRuntime.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"text-xs font-mono text-foreground underline underline-offset-4 break-all",children:t}):jsxRuntime.jsx("span",{className:"text-xs font-mono text-foreground break-all",children:t}),n&&jsxRuntime.jsx(ps,{value:n})]})]})}function gs({detail:e}){let[t,r]=En.useState(false);return jsxRuntime.jsxs("div",{className:"border border-border rounded-xl",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>r(!t),className:"flex w-full items-center justify-between p-4 text-sm font-semibold text-foreground hover:bg-muted/40 transition-colors rounded-xl",children:["Technical details",t?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"h-4 w-4"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-4 w-4"})]}),t&&jsxRuntime.jsxs("div",{className:"px-4 pb-3",children:[jsxRuntime.jsx(J,{label:"Filing ID",value:pe(e.filingId,8,8),copyValue:e.filingId}),jsxRuntime.jsx(J,{label:"Key ID",value:pe(e.keyId,8,8),copyValue:e.keyId}),jsxRuntime.jsx(J,{label:"File hash",value:pe(e.fileHash,8,8),copyValue:e.fileHash}),e.intentHashHex&&jsxRuntime.jsx(J,{label:"Intent hash",value:pe(e.intentHashHex,8,8),copyValue:e.intentHashHex}),e.proofPda&&jsxRuntime.jsx(J,{label:"Proof PDA",value:pe(e.proofPda,8,8),copyValue:e.proofPda}),e.txSignature&&jsxRuntime.jsx(J,{label:"Tx",value:pe(e.txSignature,8,8),href:`https://solscan.io/tx/${encodeURIComponent(e.txSignature)}`,copyValue:e.txSignature}),jsxRuntime.jsx(J,{label:"Beneficiary",value:pe(e.beneficiary,8,8),copyValue:e.beneficiary}),e.onchainBeneficiary&&e.onchainBeneficiary!==e.beneficiary&&jsxRuntime.jsx(J,{label:"On-chain wallet",value:pe(e.onchainBeneficiary,8,8),copyValue:e.onchainBeneficiary}),jsxRuntime.jsx(J,{label:"Payout method",value:e.payoutMethod}),jsxRuntime.jsx(J,{label:"Memo",value:e.memo}),jsxRuntime.jsx(J,{label:"Amount",value:Ae(e.amountUsdc)}),jsxRuntime.jsx(J,{label:"Tokens used",value:e.tokensUsed}),jsxRuntime.jsx(J,{label:"Filed at",value:ee(e.filedAt)}),e.stripePaymentIntentId&&jsxRuntime.jsx(J,{label:"Stripe PI",value:pe(e.stripePaymentIntentId,6,6),copyValue:e.stripePaymentIntentId}),e.failureReason&&jsxRuntime.jsx(J,{label:"Failure",value:e.failureReason})]})]})}function Pt({filingId:e,className:t,style:r}){let{detail:n,loading:l,error:a}=ct(e),s=En__default.default.useMemo(()=>Ve(n?.tracker),[n?.tracker]),o=We(s,!!n),i=s.find(d=>d.status==="failed");return a&&!n?jsxRuntime.jsxs("div",{className:f("space-y-4",t),style:r,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:a})]}):jsxRuntime.jsxs("div",{className:f("space-y-5",t),style:r,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:f("text-4xl font-mono tracking-tight",i?"text-red-500":"text-foreground"),children:i?o.text:jsxRuntime.jsx(wt,{text:o.text,playing:o.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(Nt,{states:s}),n&&jsxRuntime.jsx(gs,{detail:n})]})}function ws(e,t=6,r=6){return !e||e.length<=t+r+1?e:`${e.slice(0,t)}\u2026${e.slice(-r)}`}function Ps({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 Cs({nodeKey:e,stackName:t}){let r=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:ws(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:[A(r)," / ",A(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:ee(e.createdAt)})]})]})}function Ct({keyId:e,onComplete:t,onBack:r,onViewFiling:n,onConfigureEarnings:l,className:a,style:s}){let{config:o}=h(),{keys:i,loading:d,error:c,refresh:m}=te(),{account:p,loading:u,error:g}=Ee(),{filePaperwork:y,filing:b,result:k,error:I}=st(),[F,P]=En.useState(false),[z,V]=En.useState(false),U=le=>z?"* * * *":le;En.useEffect(()=>{k&&!F&&(P(true),t?.(k),m());},[k,F,t,m]);let B=i.find(le=>le.id===e),j=!!B?.paperWork&&B.paperWork!=="0",Q=!!p?.method,O=j&&Q&&!b&&!k,Z=async()=>{if(!O||!B)return;let le=p?.method==="solana"?"usdc":p?.method==="stripe"?"stripe":null;await y(B.id,le);};if(k)return jsxRuntime.jsxs("div",{className:f("space-y-6",a),style:s,children:[jsxRuntime.jsx(Pt,{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"}),r&&jsxRuntime.jsx("button",{type:"button",onClick:r,className:"flex-1 rounded-xl border border-border bg-background text-foreground py-3 text-sm font-semibold hover:bg-muted/50 transition-colors",children:"Back to dashboard"})]})]});if(d||u)return jsxRuntime.jsxs("div",{className:f("space-y-4",a),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(c||!B)return jsxRuntime.jsxs("div",{className:f("space-y-4",a),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:c?"Unable to load keys":"Key not found"})]}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:c||`No key with id ${e} on this account.`}),jsxRuntime.jsx("button",{type:"button",onClick:()=>m(),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=B.stackName||o.stackName,me=null,ie=null,ye="";return p?.method==="solana"&&p.solana?(ie=jsxRuntime.jsx(Ps,{className:"h-7 w-7 shrink-0"}),ye="USDC",me=jsxRuntime.jsx("code",{className:"text-xs text-foreground break-all",children:U(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:U(p.stripe.accountIdMasked)}),!p.stripe.payoutsEnabled&&jsxRuntime.jsx("span",{className:"ml-2 text-amber-600",children:"(payouts pending)"})]})),jsxRuntime.jsxs("div",{className:f("space-y-6",a),style:s,children:[jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Your earnings will be deposited into your earnings account."}),jsxRuntime.jsx(Cs,{nodeKey:B,stackName:xe}),!j&&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&&!Q&&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."]}),!Q&&!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"]})]}):Q&&j?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:()=>V(le=>!le),"aria-label":z?"Show address":"Hide address","aria-pressed":z,className:"ml-auto mt-0.5 p-0.5 text-muted-foreground hover:text-foreground transition-colors shrink-0",children:z?jsxRuntime.jsx(lucideReact.Eye,{className:"h-4 w-4"}):jsxRuntime.jsx(lucideReact.EyeOff,{className:"h-4 w-4"})})]})]}):null,I&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:I}),jsxRuntime.jsx("button",{type:"button",onClick:Z,disabled:!O,className:f("w-full rounded-xl py-4 text-sm font-semibold transition-colors",O?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:b?"Filing\u2026":"File Paperwork"})]})}function Es({nodeKey:e,onSuccess:t}){let{transferKey:r,transferring:n,result:l,error:a}=Ie(),[s,o]=En.useState(""),[i,d]=En.useState(false),c=s.trim()===e.userId,m=s.trim().length>0&&i&&!c&&!n,p=async()=>{if(!m)return;await r(e.id,s.trim())&&t();};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:u=>{o(u.target.value),d(false);},placeholder:"Enter recipient's user ID or global ID",className:"w-full rounded-xl border border-border bg-background px-4 py-3 text-sm text-foreground placeholder:text-muted-foreground focus:border-foreground/30 focus:outline-none focus:ring-1 focus:ring-foreground/10"}),c&&jsxRuntime.jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),s.trim().length>0&&!c&&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)})," ","(",A(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:u=>d(u.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:p,disabled:!m,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",m?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children: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 Us({nodeKey:e,onSuccess:t}){let{config:r}=h(),{listKey:n,listing:l,result:a,error:s}=Te(),[o,i]=En.useState(""),[d,c]=En.useState(false),m=parseInt(o.replace(/[^0-9]/g,""),10)||0,u=m>0&&Number.isFinite(m)&&d&&!l,g=async()=>{if(!u)return;let y=m*100;await n(e.id,y)&&t();};return a?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:a.listingId})]}),jsxRuntime.jsxs("a",{href:`https://market.stacknet.org/keys/${encodeURIComponent(a.keyId)}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 rounded-xl bg-foreground px-6 py-3 text-sm font-semibold text-background transition-colors hover:bg-foreground/90",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),"View Listing"]})]}):jsxRuntime.jsxs("div",{className:"space-y-5",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{htmlFor:"listing-price",className:"mb-2 block text-sm font-semibold text-foreground",children:"Listing Price (USD)"}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-2xl font-bold text-muted-foreground",children:"$"}),jsxRuntime.jsx("input",{id:"listing-price",type:"text",inputMode:"numeric",value:o,onChange: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:()=>c(!d),className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",d?"border-foreground bg-foreground":"border-muted-foreground/40"),children:d&&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:D(r.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:!u,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",u?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),l?"Listing...":"List on Marketplace"]})]})}function Ks({nodeKey:e,onSuccess:t,onClose:r,onViewFiling:n,onConfigureEarnings:l}){return jsxRuntime.jsx(Ct,{keyId:e.id,onComplete:t,onBack:r,onViewFiling:n,onConfigureEarnings:l})}function St({nodeKey:e,onBack:t,onKeysChanged:r,onViewFiling:n,onConfigureEarnings:l,className:a,style:s}){let{config:o}=h(),{entries:i,loading:d}=Re(e.id),[c,m]=En.useState(null),[p,u]=En.useState(false),g=()=>{m(null),r?.();},y=I=>{},b=()=>{e.key&&(navigator.clipboard.writeText(e.key),u(true),setTimeout(()=>u(false),2e3));},k=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsxRuntime.jsxs("div",{className:f("space-y-5",a),style:s,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(vt,{className:f("mx-auto text-foreground px-0 sm:px-0",o.keyImage?"w-2/3 h-auto":"h-20 w-auto"),keyImage:o.keyImage,keyImageClass:o.keyImageClass}),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:f("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:[(o.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||o.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:ee(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:ee(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:Ae(e.paperWork)})]}),e.status==="active"&&jsxRuntime.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[jsxRuntime.jsx("button",{onClick:()=>m("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:()=>m("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:()=>m("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(Be,{open:c==="transfer",onClose:()=>m(null),title:"Transfer Key",children:jsxRuntime.jsx(Es,{nodeKey:e,onSuccess:g})}),jsxRuntime.jsx(Be,{open:c==="sell",onClose:()=>m(null),title:"Sell Key",children:jsxRuntime.jsx(Us,{nodeKey:e,onSuccess:g})}),jsxRuntime.jsx(Be,{open:c==="file",onClose:()=>m(null),title:"File Paperwork",children:jsxRuntime.jsx(Ks,{nodeKey:e,onSuccess:y,onClose:()=>m(null),onViewFiling:n,onConfigureEarnings:l})})]})}function Ls({nodeKey:e,onClick:t}){let r=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsxRuntime.jsx("button",{onClick:t,className:"flex w-full items-start gap-3 rounded-xl border border-border p-4 text-left transition-all hover:border-foreground/20 hover:bg-muted/30",children:jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:f("text-xs font-medium capitalize",r),children:e.status})]}),jsxRuntime.jsx(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 Rt({onViewFiling:e,onConfigureEarnings:t,className:r,style:n}){let{keys:l,totalBalance:a,loading:s,error:o,refresh:i}=te(),[d,c]=En.useState(null),[m,p]=En.useState("active"),u=l.filter(b=>b.status===m),g=u.reduce((b,k)=>b+k.tokenBalance,0),y=l.find(b=>b.id===d);return y?jsxRuntime.jsx(St,{nodeKey:y,onBack:()=>c(null),onKeysChanged:()=>{c(null),i();},onViewFiling:e,onConfigureEarnings:t,className:r,style:n}):s?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:n,children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx(he,{count:3})]}):o?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-16",r),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:o})]}),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:f("flex flex-col items-center justify-center gap-4 rounded-xl border border-dashed py-16",r),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:f("space-y-4",r),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:[u.length," key",u.length!==1?"s":""," \xB7 ",A(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:f("rounded-md px-3 py-1 text-xs font-medium capitalize transition-all",m===b?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:b},b))})]}),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 ",m," keys."]})]}):jsxRuntime.jsx("div",{className:"space-y-2",children:u.map(b=>jsxRuntime.jsx(Ls,{nodeKey:b,onClick:()=>c(b.id)},b.id))})]})}var Fs=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function As({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:Fs.map(({id:r,label:n})=>jsxRuntime.jsx("button",{role:"tab","aria-selected":e===r,"aria-controls":`panel-${r}`,id:`tab-${r}`,onClick:()=>t(r),className:f("flex flex-1 items-center justify-center gap-2.5 rounded-xl py-3.5 text-sm font-medium transition-all",e===r?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:jsxRuntime.jsx("span",{className:"inline",children:n})},r))})}function Ms({defaultTab:e="buy",onViewFiling:t,onConfigureEarnings:r,className:n,style:l}){let[a,s]=En.useState(e);return jsxRuntime.jsxs("div",{className:f("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(As,{active:a,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-${a}`,"aria-labelledby":`tab-${a}`,children:[a==="buy"&&jsxRuntime.jsx(yt,{className:"flex-1"}),a==="use"&&jsxRuntime.jsx(bt,{className:"flex-1"}),a==="keys"&&jsxRuntime.jsx(Rt,{className:"flex-1",onViewFiling:t,onConfigureEarnings:r})]})})})]})}function _s({apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:n,merchantWallet:l,stripePublicKey:a,theme:s,maxQuantity:o,keyImage:i,keyImageClass:d,aispImage:c,termsUrl:m,onMintSuccess:p,onMintError:u,onPaymentStart:g,onPaymentComplete:y,onListingCreated:b,onTransferComplete:k,onFilingComplete:I,onFilingError:F,defaultTab:P,onViewFiling:z,onConfigureEarnings:V,className:U,style:B}){return jsxRuntime.jsx(ze,{config:{apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:n,merchantWallet:l,stripePublicKey:a,theme:s,maxQuantity:o,keyImage:i,keyImageClass:d,aispImage:c,termsUrl:m},callbacks:{onMintSuccess:p,onMintError:u,onPaymentStart:g,onPaymentComplete:y,onListingCreated:b,onTransferComplete:k,onFilingComplete:I,onFilingError:F},children:jsxRuntime.jsx(Ms,{defaultTab:P,onViewFiling:z,onConfigureEarnings:V,className:U,style:B})})}function js({nodeKey:e,selected:t,onSelect:r}){return jsxRuntime.jsxs("button",{onClick:r,className:f("flex w-full items-start gap-3 rounded-xl border p-4 text-left transition-all",t?"border-foreground/30 bg-foreground/5 ring-1 ring-foreground/10":"border-border hover:border-foreground/20"),children:[jsxRuntime.jsx("div",{className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors",t?"border-foreground bg-foreground":"border-muted-foreground/40"),children:t&&jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 text-background"})}),jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:f("text-xs font-medium capitalize",e.status==="active"?"text-green-500":"text-muted-foreground"),children:e.status})]}),jsxRuntime.jsx(oe,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function Os({className:e,style:t}){let{config:r}=h(),{keys:n,loading:l,error:a,refresh:s}=te(),{listKey:o,listing:i,result:d,error:c}=Te(),[m,p]=En.useState(null),[u,g]=En.useState(""),[y,b]=En.useState(false),k=n.find(U=>U.id===m),I=parseInt(u.replace(/[^0-9]/g,""),10)||0,F=I>0&&Number.isFinite(I),P=!!k&&F&&y&&!i,z=async()=>{if(!P||!k)return;let U=I*100;await o(k.id,U)&&s();};if(d)return jsxRuntime.jsxs("div",{className:f("flex flex-col items-center gap-4 rounded-xl bg-green-500/10 py-12",e),style:t,children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Key Listed!"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Your key is now on the Global Open AI Network marketplace."}),jsxRuntime.jsxs("p",{className:"text-xs text-muted-foreground",children:["Listing ID: ",jsxRuntime.jsx("code",{children: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:f("space-y-5 px-1",e),style:t,children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx(he,{count:2})]});if(a)return jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-16",e),style:t,children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a})]}),jsxRuntime.jsx("button",{onClick:()=>s(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]});let V=n.filter(U=>U.status==="active");return V.length===0?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16",e),style:t,children:[jsxRuntime.jsx(lucideReact.AlertTriangle,{className:"h-8 w-8 text-muted-foreground"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"No active keys to sell."})]}):jsxRuntime.jsxs("div",{className:f("space-y-5",e),style:t,children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx("div",{className:"space-y-2",children:V.map(U=>jsxRuntime.jsx(js,{nodeKey:U,selected:m===U.id,onSelect:()=>p(U.id)},U.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: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:[A(k.tokenBalance)," / ",A(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:ee(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:u,onChange:U=>{let B=U.target.value.replace(/[^0-9]/g,""),j=parseInt(B,10);g(isNaN(j)?"":j.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:f("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:D(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:z,disabled:!P,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",P?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),i?"Listing...":"List on Marketplace"]})]})}var It=20;function Et({nodeKey:e,className:t,style:r}){let[n,l]=En.useState(false),[a,s]=En.useState(false),o=En.useRef(null),{entries:i,loading:d}=Re(n?e.id:null);En.useEffect(()=>()=>{o.current&&clearTimeout(o.current);},[]);let c=En.useCallback(()=>{e.key&&(navigator.clipboard.writeText(e.key),s(true),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>s(false),2e3));},[e.key]),m=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500",p=i.slice(0,It);return jsxRuntime.jsxs("div",{className:f("rounded-lg border bg-background",t),style:r,children:[jsxRuntime.jsxs("div",{className:"p-4",children:[jsxRuntime.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("button",{onClick:()=>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:f("text-xs font-medium capitalize",m),children:e.status})]}),e.key&&jsxRuntime.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[jsxRuntime.jsx("code",{className:"flex-1 truncate rounded bg-muted px-2 py-1 text-xs text-muted-foreground",children:e.key}),jsxRuntime.jsx("button",{onClick:c,"aria-label":"Copy key to clipboard",className:"shrink-0 rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:a?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 ",ee(e.createdAt)]}),e.expiresAt&&jsxRuntime.jsxs("span",{children:["Expires ",ee(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(u=>jsxRuntime.jsxs("div",{className:"flex items-center justify-between text-xs",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("span",{className:f("font-medium",u.type==="credit"||u.type==="reward"?"text-green-500":"text-red-500"),children:[u.type==="credit"||u.type==="reward"?"+":"-",A(Math.abs(u.amount))]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:u.description})]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:ee(u.createdAt)})]},u.id)),i.length>It&&jsxRuntime.jsxs("p",{className:"pt-1 text-xs text-muted-foreground",children:["Showing ",It," of ",i.length," entries"]})]})]})]})}var Qs=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function je({baseHref:e}){return jsxRuntime.jsx("div",{className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5 mb-6",children:Qs.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 Xs({getKeyHref:e="/keys/get",showTabs:t=true,className:r,style:n}){let{keys:l,totalBalance:a,loading:s,error:o,refresh:i}=te();return s?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:n,children:[t&&e&&jsxRuntime.jsx(je,{baseHref:e}),jsxRuntime.jsx(he,{count:3})]}):o?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:n,children:[t&&e&&jsxRuntime.jsx(je,{baseHref:e}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 py-12",children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o})]}),jsxRuntime.jsx("button",{onClick:()=>i(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]})]}):l.length===0?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:n,children:[t&&e&&jsxRuntime.jsx(je,{baseHref:e}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 rounded-lg border border-dashed py-12",children:[jsxRuntime.jsx(lucideReact.KeyRound,{className:"h-10 w-10 text-muted-foreground"}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys yet"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Get your first node key to start earning."})]}),e&&jsxRuntime.jsx("a",{href:e,className:"rounded-lg bg-foreground px-4 py-2 text-sm font-medium text-background transition-colors hover:bg-foreground/90",children:"Get a Key"})]})]}):jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:n,children:[t&&e&&jsxRuntime.jsx(je,{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: ",A(a)]}),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(Et,{nodeKey:d},d.id))]})}function no({nodeKey:e,selected:t,onSelect:r}){return jsxRuntime.jsxs("button",{onClick:r,className:f("flex w-full items-start gap-3 rounded-xl border p-4 text-left transition-all",t?"border-foreground/30 bg-foreground/5 ring-1 ring-foreground/10":"border-border hover:border-foreground/20"),children:[jsxRuntime.jsx("div",{className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors",t?"border-foreground bg-foreground":"border-muted-foreground/40"),children:t&&jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 text-background"})}),jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:"text-xs font-medium capitalize text-green-500",children:e.status})]}),jsxRuntime.jsx(oe,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function so({className:e,style:t}){let{keys:r,loading:n}=te(),{transferKey:l,transferring:a,result:s,error:o}=Ie(),[i,d]=En.useState(null),[c,m]=En.useState(""),[p,u]=En.useState(false),g=r.filter(P=>P.status==="active"),y=g.find(P=>P.id===i),b=y&&c.trim()===y.userId,k=i&&c.trim().length>0&&p&&!b&&!a,I=async()=>{!i||!c.trim()||await l(i,c.trim());},F=()=>{d(null),m(""),u(false);};return s?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center gap-4 py-8",e),style:t,children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Transfer Complete"}),jsxRuntime.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Key transferred successfully"})]}),jsxRuntime.jsxs("div",{className:"w-full max-w-sm space-y-2 rounded-xl border border-border bg-muted/30 p-4 text-sm",children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key"}),jsxRuntime.jsxs("span",{className:"font-mono text-foreground",children:[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:F,className:"mt-2 rounded-lg border border-border px-4 py-2 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors",children:"Transfer Another"})]}):jsxRuntime.jsxs("div",{className:f("space-y-5",e),style:t,children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"mb-3 text-sm font-medium text-foreground",children:"Select Key to Transfer"}),n?jsxRuntime.jsx(he,{count:2}):g.length===0?jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"No active keys available for transfer."}):jsxRuntime.jsx("div",{className:"space-y-2",children:g.map(P=>jsxRuntime.jsx(no,{nodeKey:P,selected:i===P.id,onSelect:()=>d(P.id)},P.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:c,onChange:P=>{m(P.target.value),u(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&&c.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)})," ","(",A(y.tokenBalance)," tokens) to"," ",jsxRuntime.jsxs("span",{className:"font-mono font-medium",children:[c.trim().slice(0,20),"..."]})]})]}),jsxRuntime.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:p,onChange:P=>u(P.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border"}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"I confirm this transfer is permanent and cannot be undone."})]})]})]})}),o&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:o}),jsxRuntime.jsx("button",{onClick:I,disabled:!k,className:f("flex w-full items-center justify-center gap-2 rounded-lg px-4 py-3 text-sm font-medium transition-all",k?"bg-foreground text-background hover:opacity-90":"bg-muted text-muted-foreground cursor-not-allowed"),children:a?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 io(e){return e.status==="active"}function lo({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 co({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:[A(r)," / ",A(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 uo({onSelect:e,className:t,style:r}){let{keys:n,loading:l,error:a,refresh:s}=te();if(l)return jsxRuntime.jsx("div",{className:f("space-y-3",t),style:r,children:jsxRuntime.jsx(lo,{count:3})});if(a)return jsxRuntime.jsx("div",{className:f("space-y-3",t),style:r,children:jsxRuntime.jsxs("div",{className:"bg-muted/30 p-5 text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a}),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 o=n.filter(io);return o.length===0?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-3 bg-muted/20 py-16",t),style:r,children:[jsxRuntime.jsx(lucideReact.FileText,{className:"h-10 w-10 text-muted-foreground","aria-hidden":true}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys with pending paperwork"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Run a node to earn Paper, then return here to file."})]})]}):jsxRuntime.jsx("div",{className:f("space-y-2",t),style:r,children:o.map(i=>jsxRuntime.jsx(co,{nodeKey:i,onSelect:()=>e(i.id)},i.id))})}function br({label:e,sub:t,icon:r,selected:n,enabled:l,disabledLabel:a,onClick:s}){let o=l;return jsxRuntime.jsxs("button",{type:"button",onClick:o?s:void 0,disabled:!o,"aria-disabled":!o,className:f("flex flex-col items-start gap-1 rounded-xl border p-4 text-left transition-colors",o?n?"border-foreground bg-foreground/5 cursor-pointer":"border-border hover:bg-muted/50 cursor-pointer":"border-border bg-muted/20 cursor-not-allowed opacity-70"),children:[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:f("flex h-7 w-7 items-center justify-center rounded-md",n&&l?"bg-foreground text-background":"bg-muted text-foreground"),children:r}),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:f("text-xs",l?"text-muted-foreground":"text-muted-foreground/80"),children:l?t:a??t})]})}function go({caps:e,value:t,onChange:r,className:n,disabled:l=false}){let a=e.stripe.enabled&&!l,s=e.usdc.enabled&&!l,o=`disabled by ${e.stackName} stack`,i=`disabled by ${e.stackName} stack`;return jsxRuntime.jsxs("div",{className:f("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(br,{label:"USDC",sub:"On-chain payout to your stack address",icon:jsxRuntime.jsx(lucideReact.Wallet,{className:"h-4 w-4"}),selected:t==="usdc",enabled:s,disabledLabel:i,onClick:()=>r("usdc")}),jsxRuntime.jsx(br,{label:"Stripe",sub:"USD payout to your bank via Stripe",icon:jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-4 w-4"}),selected:t==="stripe",enabled:a,disabledLabel:o,onClick:()=>r("stripe")})]})]})}function Oe({ok:e,label:t}){return jsxRuntime.jsxs("span",{className:f("inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-[11px] font-medium",e?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"),children:[e?jsxRuntime.jsx(lucideReact.CheckCircle2,{className:"h-3 w-3"}):jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-3 w-3"}),t]})}function vr({active:e,onClick:t,icon:r,label:n,sub:l}){return jsxRuntime.jsxs("button",{type:"button",onClick:t,className:f("flex flex-1 items-start gap-3 rounded-xl border p-4 text-left transition-colors",e?"border-foreground bg-foreground/5":"border-border hover:bg-muted/40"),children:[jsxRuntime.jsx("span",{className:f("flex h-8 w-8 shrink-0 items-center justify-center rounded-md",e?"bg-foreground text-background":"bg-muted text-foreground"),children:r}),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 wo({onChange:e,className:t,style:r}){let{account:n,loading:l,error:a,refresh:s,disconnect:o,disconnecting:i}=Ee(),{caps:d,loading:c}=it(),{startStripeConnect:m,starting:p,error:u}=dt(),{connectAndVerify:g,connecting:y,error:b}=ut(),k=!!d?.stripe.enabled,I=n?.method??null,[F,P]=En.useState(I??"solana");En.useEffect(()=>{I?P(I):!k&&F==="stripe"&&P("solana");},[I,k,F]);let z=async()=>{await m(),e?.();},V=async()=>{await g()&&(await s(),e?.());},U=async()=>{await o()&&e?.();};if(l||c)return jsxRuntime.jsxs("div",{className:f("space-y-3",t),style:r,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(a)return jsxRuntime.jsxs("div",{className:f("space-y-3",t),style:r,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 B=n?.solana,j=n?.stripe,Q=k||I==="stripe";return jsxRuntime.jsxs("div",{className:f("space-y-4",t),style:r,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."})]}),I&&jsxRuntime.jsxs("button",{type:"button",onClick:U,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"]})]}),Q&&jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx(vr,{active:F==="solana",onClick:()=>P("solana"),icon:jsxRuntime.jsx(lucideReact.Wallet,{className:"h-4 w-4"}),label:"Crypto (Solana)",sub:"Connect a wallet, sign once"}),jsxRuntime.jsx(vr,{active:F==="stripe",onClick:()=>P("stripe"),icon:jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-4 w-4"}),label:"Bank (Stripe)",sub:"Stripe-hosted onboarding"})]}),F==="solana"&&jsxRuntime.jsx("div",{className:"space-y-3 rounded-xl border border-border p-4",children:B?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(Oe,{ok:true,label:"verified"})]}),jsxRuntime.jsx("code",{className:"block text-xs text-foreground break-all",children:B.address}),jsxRuntime.jsxs("p",{className:"text-xs text-muted-foreground",children:["You signed a server-issued nonce on ",new Date(B.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:V,disabled:y,className:f("inline-flex items-center gap-2 rounded-md bg-foreground text-background px-4 py-2 text-sm font-semibold transition-colors","hover:bg-foreground/90 disabled:opacity-50 disabled:cursor-not-allowed"),children:[jsxRuntime.jsx(lucideReact.Wallet,{className:"h-4 w-4"}),y?"Waiting for signature\u2026":"Connect Phantom & sign"]})]})}),F==="stripe"&&jsxRuntime.jsx("div",{className:"space-y-3 rounded-xl border border-border p-4",children:j?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:j.accountIdMasked})]}),jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2",children:[jsxRuntime.jsx(Oe,{ok:j.detailsSubmitted,label:"details"}),jsxRuntime.jsx(Oe,{ok:j.chargesEnabled,label:"charges"}),jsxRuntime.jsx(Oe,{ok:j.payoutsEnabled,label:"payouts"})]}),j.pendingOnboardingUrl&&jsxRuntime.jsxs("a",{href:D(j.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."}),u&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:u}),jsxRuntime.jsxs("button",{type:"button",onClick:z,disabled:p,className:f("inline-flex items-center gap-2 rounded-md bg-foreground text-background px-4 py-2 text-sm font-semibold transition-colors","hover:bg-foreground/90 disabled:opacity-50 disabled:cursor-not-allowed"),children:[jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-4 w-4"}),p?"Opening Stripe\u2026":"Connect with Stripe"]})]})})]})}
|
|
2
|
-
exports.ASCII_KEY_ART
|
|
1
|
+
'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jn=require('react'),jsxRuntime=require('react/jsx-runtime'),lucideReact=require('lucide-react');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var jn__default=/*#__PURE__*/_interopDefault(jn);var We=["stripe","solana","eth","btc"],Ve={stripe:{method:"stripe",label:"Credit Card",kind:"card"},solana:{method:"solana",label:"Solana",kind:"crypto"},eth:{method:"eth",label:"Ethereum",kind:"crypto"},btc:{method:"btc",label:"Bitcoin",kind:"crypto"}};var At=false;function j(){if(typeof document>"u")return {};let e=document.cookie.match(/(?:^|;\s*)__csrf=([^;]*)/);if(!e)return At||(At=true,console.warn("[keyutils] __csrf cookie not found; mutations will be sent without a CSRF token")),{};let t=e[1];try{t=decodeURIComponent(t);}catch{}return {"x-csrf-token":t}}var Ur=500;function Dt(e,t){if(typeof e!="string"||e.length===0)return t;let r=e.replace(/[\u0000-\u001F\u007F]/g," ");return r.length>500?r.slice(0,500)+"\u2026":r}async function C(e,t){try{let r=await e.json();if(r&&typeof r=="object"&&"error"in r)return Dt(r.error,t)}catch{}return t}function _(e,t="#"){if(!e||typeof e!="string")return t;let r=e.trim();if(r===""||r==="#")return t;if(r.startsWith("/")||r.startsWith("./")||r.startsWith("../"))return r;try{let n=new URL(r);if(n.protocol==="http:"||n.protocol==="https:")return n.toString()}catch{}return t}function ze(e){let t=e&&e.length>0?e:["solana"],r=new Set;for(let n of t){if(typeof n!="string")continue;let l=n.trim().toLowerCase(),a=We.find(s=>s===l);a&&r.add(a);}return We.filter(n=>r.has(n))}function Se(e){return Ve[e]?.label??e}function Kr(e){return Ve[e]?.kind==="crypto"}var Ye={sent:"sent",routed:"routed",confirmed:"confirmed",finalized:"finalized",filed:"filed"},Re={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"}},Lr=["sent","routed","confirmed","finalized","filed"];function qe(e){let t=new Map;(e??[]).forEach(a=>t.set(a.id,a));let r=Lr.map(a=>{let s=t.get(a);return s?{...s,label:s.label||Ye[a]}:{id:a,label:Ye[a],status:"pending",timestampMs:null,detail:null}}),n=r.reduce((a,s,o)=>s.status==="done"||s.status==="failed"?o:a,-1);if(n>0)for(let a=0;a<n;a++)r[a].status!=="failed"&&(r[a]={...r[a],status:"done"});if(!r.some(a=>a.status==="failed")){let a=r.findIndex(s=>s.status!=="done");if(a>=0){let s=r[a];s.status!=="current"&&(r[a]={...s,status:"current"});}}return r}function _t(e){return e.find(t=>t.status==="current")??null}function $t(e){return e.length>0&&e.every(t=>t.status==="done")}function jt(e){return e.some(t=>t.status==="failed")}function Je(e,t){if(!t)return {text:"loading",playing:true,stepId:"sent"};if(jt(e))return {text:"failed",playing:false,stepId:"filed"};if($t(e))return {text:Re.filed.done,playing:false,stepId:"filed"};let n=_t(e)?.id??"sent";return {text:Re[n].progressing,playing:true,stepId:n}}function f(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function F(e){return e==null?"0":e>=1e9?`${(e/1e9).toFixed(1)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function Ht(e,t){return t<=0?0:Math.min(100,Math.round(e/t*100))}function Ot(e){return e>=70?"bg-green-500":e>=30?"bg-yellow-500":"bg-red-500"}function Ae(e,t={}){let r=t.withSymbol!==false,n=Math.max(0,Math.min(6,t.maxDecimals??2));if(e==null||e==="")return r?"$0.00":"0.00";let l;try{if(typeof e=="bigint")l=e;else if(typeof e=="number")l=BigInt(Math.trunc(e));else {let m=String(e).trim().replace(/^\+/,"");if(/^-?\d+$/.test(m))l=BigInt(m);else {let g=Number(m);if(!Number.isFinite(g))return r?"$0.00":"0.00";l=BigInt(Math.trunc(g));}}}catch{return r?"$0.00":"0.00"}let a=l<0n,s=a?-l:l,o=s/1000000n,d=(s%1000000n).toString().padStart(6,"0").slice(0,n),c=o.toLocaleString("en-US"),u=n>0?`.${d}`:"";return `${a?"-":""}${r?"$":""}${c}${u}`}function ee(e){if(e==null||e==="")return "";let t=typeof e=="string"&&/^\d+$/.test(e)?Number(e):e,r=new Date(t);return isNaN(r.getTime())?"":r.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function Wt(){if(typeof navigator>"u")return "mac";let e=navigator.userAgent.toLowerCase();return /iphone|ipad|ipod/.test(e)?"ios":/android/.test(e)?"android":/win/.test(e)?"windows":/linux/.test(e)?"linux":"mac"}var Vt=jn.createContext(null);function k(){let e=jn.useContext(Vt);if(!e)throw new Error("useKeyUtilsContext must be used within a KeyUtilsProvider");return e}function Ge({config:e,callbacks:t={},children:r}){typeof e.apiBaseUrl!="string"&&console.error("[KeyUtils] apiBaseUrl must be a string");let n=jn.useMemo(()=>({config:e,callbacks:t}),[e,t]);return jsxRuntime.jsx(Vt.Provider,{value:n,children:r})}function Xe(){let{config:e}=k(),[t,r]=jn.useState(null),[n,l]=jn.useState(true),[a,s]=jn.useState(null),o=jn.useRef(true),i=jn.useRef(e.apiBaseUrl);i.current=e.apiBaseUrl;let d=async()=>{try{o.current&&(l(!0),s(null));let c=await fetch(`${i.current}/api/keys/pricing`,{credentials:"include"});if(!c.ok)throw new Error(await C(c,`Pricing unavailable (${c.status})`));let u=await c.json();o.current&&r(u);}catch(c){o.current&&s(c instanceof Error?c.message:"Failed to fetch pricing");}finally{o.current&&l(false);}};return jn.useEffect(()=>{o.current=true,d();let c=setInterval(d,6e4);return ()=>{o.current=false,clearInterval(c);}},[]),{pricing:t,loading:n,error:a,refresh:d}}function Wr(e){return {id:e.id||"",keyIndex:e.keyIndex??e.key_index??null,key:e.id||e.key||e.keyPrefix||"",userId:e.userId||e.user_id||"",status:e.status||"active",tokenBalance:e.tokenBalance??e.currentTokenBalance??e.current_token_balance??0,maxTokens:e.maxTokens??e.initialTokenBalance??e.initial_token_balance??0,createdAt:String(e.createdAt??e.created_at??""),expiresAt:e.expiresAt,label:e.label||void 0,paperWork:e.paperWork||e.paper_work||void 0,stackId:e.stackId,stackName:e.stackName}}function te(){let{config:e}=k(),[t,r]=jn.useState([]),[n,l]=jn.useState(true),[a,s]=jn.useState(null),o=jn.useRef(true),i=e.apiBaseUrl,d=jn.useCallback(async()=>{try{l(!0),s(null);let u=await fetch(`${i}/api/keys`,{credentials:"include"});if(!u.ok)throw new Error(await C(u,`Failed to fetch keys (${u.status})`));let p=await u.json(),m=Array.isArray(p)?p:p.keys??[];o.current&&r(m.map(Wr));}catch(u){o.current&&s(u instanceof Error?u.message:"Failed to fetch keys");}finally{o.current&&l(false);}},[i]);jn.useEffect(()=>(o.current=true,d(),()=>{o.current=false;}),[d]);let c=t.reduce((u,p)=>u+p.tokenBalance,0);return {keys:t,totalBalance:c,loading:n,error:a,refresh:d}}function et(e){let t=e.type||e.entry_type||"debit",r=e.amount??e.tokens??e.token_amount??0,n=e.description||e.memo||e.reason||Vr(t);return {id:e.id||"",keyId:e.keyId||e.key_id||"",type:t,amount:r,description:n,createdAt:String(e.createdAt??e.created_at??e.timestamp??""),metadata:e.metadata||void 0}}function Vr(e){switch(e){case "credit":return "Credit";case "debit":return "Usage";case "mint":return "Mint";case "reward":return "Reward";default:return ""}}function zr(e){return {id:e.id||"",keyIndex:e.keyIndex??e.key_index??null,key:e.id||e.key||e.keyPrefix||"",userId:e.userId||e.user_id||"",status:e.status||"active",tokenBalance:e.tokenBalance??e.currentTokenBalance??e.current_token_balance??0,maxTokens:e.maxTokens??e.initialTokenBalance??e.initial_token_balance??0,createdAt:String(e.createdAt??e.created_at??""),expiresAt:e.expiresAt,label:e.label||void 0,paperWork:e.paperWork||e.paper_work||void 0,stackId:e.stackId,stackName:e.stackName}}async function Yr(e){if(!e)return {};let t=e();return t instanceof Promise?await t:t}function qr(e){if(!e)return false;let t=e.toUpperCase();return t==="POST"||t==="PUT"||t==="PATCH"||t==="DELETE"}async function be(e,t={}){let{getHeaders:r,...n}=t,l=await Yr(r),a=qr(n.method)?j():{},s=await fetch(e,{...n,headers:{"Content-Type":"application/json",...a,...l,...n.headers},credentials:"include"});if(!s.ok)throw new Error(await C(s,`Request failed (${s.status})`));return s.json()}function Jr(e){let{apiBaseUrl:t,stackId:r,stackName:n,getHeaders:l}=e,a=`${t}/api/keys`;return {async getKeys(){let s=await be(a,{getHeaders:l});return (Array.isArray(s)?s:s.keys??[]).map(zr)},async getLedger(s){let o=await be(`${a}/${encodeURIComponent(s)}/ledger`,{getHeaders:l});return (Array.isArray(o)?o:o.entries??[]).map(et)},async getPricing(){return be(`${a}/pricing`,{getHeaders:l})},async mint(s,o,i=1){try{let d=await be(a+"/mint",{method:"POST",body:JSON.stringify({paymentMethod:s,paymentRef:o,quantity:i,stackId:r}),getHeaders:l}),c=d.keys?.[0]||d;return {success:!0,key:{id:c.keyId||c.id||"",key:c.key||"",userId:c.userId||"",status:"active",tokenBalance:c.tokenBalance??c.currentTokenBalance??0,maxTokens:c.initialTokenBalance??c.tokenBalance??0,createdAt:String(c.createdAt||Date.now())},transactionId:o}}catch(d){return {success:false,error:d instanceof Error?d.message:"Key generation failed"}}},async listKey(s,o){return be(`${a}/${encodeURIComponent(s)}/list`,{method:"POST",body:JSON.stringify({askPriceCents:o,stackId:r,stackName:n}),getHeaders:l})},async delistKey(s){await be(`${a}/${encodeURIComponent(s)}/list`,{method:"DELETE",getHeaders:l});},async transferKey(s,o){return be(`${a}/${encodeURIComponent(s)}/transfer`,{method:"POST",body:JSON.stringify({recipientId:o}),getHeaders:l})},async createStripeSession(s,o,i){return be(`${a}/stripe-session`,{method:"POST",body:JSON.stringify({priceCents:s,quantity:o,stackId:r,referrerUrl:i}),getHeaders:l})}}}function Te(e){let{config:t}=k(),[r,n]=jn.useState([]),[l,a]=jn.useState(false),[s,o]=jn.useState(null),i=jn.useRef(true),d=t.apiBaseUrl,c=jn.useCallback(async()=>{if(e)try{a(!0),o(null);let u=await fetch(`${d}/api/keys/${encodeURIComponent(e)}/ledger`,{credentials:"include"});if(!u.ok)throw new Error(await C(u,`Failed to fetch ledger (${u.status})`));let p=await u.json(),m=Array.isArray(p)?p:p.entries??[];i.current&&n(m.map(et));}catch(u){i.current&&o(u instanceof Error?u.message:"Failed to fetch ledger");}finally{i.current&&a(false);}},[d,e]);return jn.useEffect(()=>(i.current=true,c(),()=>{i.current=false;}),[c]),{entries:r,loading:l,error:s,refresh:c}}function nt(){let{config:e,callbacks:t}=k(),[r,n]=jn.useState(false),[l,a]=jn.useState(null),[s,o]=jn.useState(null);return {mint:jn.useCallback(async(d,c,u=1)=>{try{n(!0),o(null),t.onPaymentComplete?.(d,c);let p=await fetch(`${e.apiBaseUrl}/api/keys/mint`,{method:"POST",headers:{"Content-Type":"application/json",...j()},credentials:"include",body:JSON.stringify({paymentMethod:d,paymentRef:c,quantity:u,stackId:e.stackId})});if(!p.ok)throw new Error(await C(p,`Key generation failed (${p.status})`));let m=await p.json(),g=m.keys?.[0]||m,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:c};return a(y),t.onMintSuccess?.(y),y}catch(p){let m=p instanceof Error?p:new Error("Key generation failed");return o(m.message),t.onMintError?.(m),{success:false,error:m.message}}finally{n(false);}},[e.apiBaseUrl,t]),minting:r,result:l,error:s}}function Ie(){let{config:e,callbacks:t}=k(),[r,n]=jn.useState(false),[l,a]=jn.useState(null),[s,o]=jn.useState(null),i=jn.useRef(true),d=jn.useCallback(async(u,p)=>{try{n(!0),o(null);let m=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/list`,{method:"POST",headers:{"Content-Type":"application/json",...j()},credentials:"include",body:JSON.stringify({askPriceCents:p,stackId:e.stackId,stackName:e.stackName})});if(!m.ok)throw new Error(await C(m,`Listing failed (${m.status})`));let g=await m.json();return i.current&&(a(g),t.onListingCreated?.(g)),g}catch(m){let g=m instanceof Error?m.message:"Listing failed";return i.current&&o(g),null}finally{i.current&&n(false);}},[e.apiBaseUrl,e.stackId,e.stackName,t]),c=jn.useCallback(async u=>{try{n(!0),o(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/list`,{method:"DELETE",headers:{...j()},credentials:"include"});if(!p.ok)throw new Error(await C(p,`Delist failed (${p.status})`));return i.current&&a(null),!0}catch(p){let m=p instanceof Error?p.message:"Delist failed";return i.current&&o(m),false}finally{i.current&&n(false);}},[e.apiBaseUrl]);return {listKey:d,delistKey:c,listing:r,result:l,error:s}}function ot(){let{config:e}=k(),[t,r]=jn.useState(false),[n,l]=jn.useState(null),a=jn.useRef(true);return {createSession:jn.useCallback(async(o,i)=>{try{r(!0),l(null);let d=await fetch(`${e.apiBaseUrl}/api/keys/stripe-session`,{method:"POST",headers:{"Content-Type":"application/json",...j()},credentials:"include",body:JSON.stringify({priceCents:o,quantity:i,stackId:e.stackId,referrerUrl:window.location.href})});if(!d.ok)throw new Error(await C(d,`Checkout failed (${d.status})`));let{url:c}=await d.json();if(!c)throw new Error("No checkout URL returned");let u;try{u=new URL(c);}catch{throw new Error("Invalid checkout URL")}if(u.protocol!=="https:"||!/(^|\.)stripe\.com$/.test(u.hostname))throw new Error("Refusing to redirect to non-Stripe URL");try{sessionStorage.setItem("keyutils_stripe_pending","1"),sessionStorage.setItem("keyutils_stripe_quantity",String(i));}catch{}window.location.href=u.toString();}catch(d){if(a.current){let c=d instanceof Error?d.message:"Checkout failed";l(c),r(false);}}},[e.apiBaseUrl,e.stackId]),loading:t,error:n}}var Gt=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function sn(){let{config:e}=k(),[t,r]=jn.useState(false),[n,l]=jn.useState(null);return {pay:jn.useCallback(async s=>{if(!e.merchantWallet||!Gt.test(e.merchantWallet))throw new Error("Merchant wallet not configured");try{r(!0),l(null);let{Connection:o,PublicKey:i,Transaction:d,SystemProgram:c}=await import('@solana/web3.js'),u=typeof window<"u"?window.solana:void 0;if(!u||typeof u!="object"||!u.isPhantom)throw new Error("Phantom wallet not found. Please install Phantom.");let p=u,m=new i(e.merchantWallet),g=await p.connect(),y=new i(g.publicKey.toString()),b="https://api.mainnet-beta.solana.com",h=_(e.solanaRpcUrl,b),E=h==="#"?b:h,M=new o(E),{blockhash:w}=await M.getLatestBlockhash(),H=BigInt(Math.floor(s*1e9)),D=e.protocolTreasuryWallet,K=e.protocolFeeBps??500,z=new d({recentBlockhash:w,feePayer:y});if(D&&Gt.test(D)&&K>0){let O=H*BigInt(K)/10000n,W=H-O,Z=new i(D);z.add(c.transfer({fromPubkey:y,toPubkey:m,lamports:Number(W)}),c.transfer({fromPubkey:y,toPubkey:Z,lamports:Number(O)}));}else z.add(c.transfer({fromPubkey:y,toPubkey:m,lamports:Number(H)}));let{signature:q}=await p.signAndSendTransaction(z);return q}catch(o){let i=o instanceof Error?o:new Error("SOL payment failed");throw l(i.message),i}finally{r(false);}},[e.merchantWallet,e.protocolTreasuryWallet,e.protocolFeeBps,e.solanaRpcUrl]),processing:t,error:n}}function Ee(){let{config:e,callbacks:t}=k(),[r,n]=jn.useState(false),[l,a]=jn.useState(null),[s,o]=jn.useState(null),i=jn.useRef(true);return {transferKey:jn.useCallback(async(c,u)=>{try{n(!0),o(null);let p=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(c)}/transfer`,{method:"POST",headers:{"Content-Type":"application/json",...j()},credentials:"include",body:JSON.stringify({recipientId:u})});if(!p.ok)throw new Error(await C(p,`Transfer failed (${p.status})`));let m=await p.json();return i.current&&(a(m),t.onTransferComplete?.(m)),m}catch(p){let m=p instanceof Error?p.message:"Transfer failed";return i.current&&o(m),null}finally{i.current&&n(false);}},[e.apiBaseUrl,t]),transferring:r,result:l,error:s}}function lt(){let{config:e,callbacks:t}=k(),[r,n]=jn.useState(false),[l,a]=jn.useState(null),[s,o]=jn.useState(null),i=jn.useRef(true);jn.useEffect(()=>(i.current=true,()=>{i.current=false;}),[]);let d=jn.useCallback(async(u,p)=>{try{n(!0),o(null);let m={stackId:e.stackId};p&&(m.payoutMethod=p);let g=await fetch(`${e.apiBaseUrl}/api/keys/${encodeURIComponent(u)}/file`,{method:"POST",headers:{"Content-Type":"application/json",...j()},credentials:"include",body:JSON.stringify(m)});if(!g.ok)throw new Error(await C(g,`Filing failed (${g.status})`));let y=await g.json();return i.current&&(a(y),t.onFilingComplete?.(y)),y}catch(m){let g=m instanceof Error?m:new Error("Filing failed");return i.current&&o(g.message),t.onFilingError?.(g),null}finally{i.current&&n(false);}},[e.apiBaseUrl,e.stackId,t]),c=jn.useCallback(()=>{a(null),o(null);},[]);return {filePaperwork:d,filing:r,result:l,error:s,reset:c}}function fn(){let{config:e}=k(),[t,r]=jn.useState([]),[n,l]=jn.useState(true),[a,s]=jn.useState(null),o=jn.useRef(true),i=e.apiBaseUrl,d=jn.useCallback(async()=>{try{l(!0),s(null);let c=await fetch(`${i}/api/keys/filings`,{credentials:"include"});if(!c.ok)throw new Error(await C(c,`Failed to fetch filings (${c.status})`));let u=await c.json(),p=Array.isArray(u)?u:u.filings??[];o.current&&r(p);}catch(c){o.current&&s(c instanceof Error?c.message:"Failed to fetch filings");}finally{o.current&&l(false);}},[i]);return jn.useEffect(()=>(o.current=true,d(),()=>{o.current=false;}),[d]),{entries:t,loading:n,error:a,refresh:d}}function ut(e){let{config:t}=k(),r=e??t.stackId,n=t.apiBaseUrl,[l,a]=jn.useState(null),[s,o]=jn.useState(!!r),[i,d]=jn.useState(null),c=jn.useRef(true),u=jn.useCallback(async()=>{if(!r){a(null),o(false);return}try{o(!0),d(null);let p=await fetch(`${n}/api/stacks/${encodeURIComponent(r)}/payout-capabilities`,{credentials:"include"});if(!p.ok)throw new Error(await C(p,`Failed to load payout capabilities (${p.status})`));let m=await p.json();c.current&&a(m);}catch(p){c.current&&d(p instanceof Error?p.message:"Failed to load payout capabilities");}finally{c.current&&o(false);}},[n,r]);return jn.useEffect(()=>(c.current=true,u(),()=>{c.current=false;}),[u]),{caps:l,loading:s,error:i,refresh:u}}var kn=5e3;function vn(e){return e==="paid"||e==="failed"}function ft(e){let{config:t}=k(),r=t.apiBaseUrl,[n,l]=jn.useState(null),[a,s]=jn.useState(!!e),[o,i]=jn.useState(null),d=jn.useRef(true),c=jn.useCallback(async()=>{if(!e){l(null),s(false);return}try{i(null);let u=await fetch(`${r}/api/keys/filings/${encodeURIComponent(e)}`,{credentials:"include"});if(!u.ok)throw new Error(await C(u,`Failed to load filing (${u.status})`));let p=await u.json();d.current&&l(p);}catch(u){d.current&&i(u instanceof Error?u.message:"Failed to load filing");}finally{d.current&&s(false);}},[r,e]);return jn.useEffect(()=>{if(d.current=true,!e)return l(null),s(false),()=>{d.current=false;};s(true),c();let u=setInterval(()=>{d.current&&(n&&vn(n.status)||c());},kn);return ()=>{d.current=false,clearInterval(u);}},[e,c,n]),{detail:n,loading:a,error:o,refresh:c}}function Ue(e){let{config:t}=k(),r=e??t.stackId??"",n=t.apiBaseUrl,[l,a]=jn.useState(null),[s,o]=jn.useState(true),[i,d]=jn.useState(null),[c,u]=jn.useState(false),p=jn.useRef(true),m=jn.useCallback(async()=>{try{o(!0),d(null);let y=r?`${n}/api/payout?stackId=${encodeURIComponent(r)}`:`${n}/api/payout`,b=await fetch(y,{credentials:"include"});if(!b.ok)throw new Error(await C(b,`Failed to load payout account (${b.status})`));let h=await b.json();p.current&&a(h);}catch(y){p.current&&d(y instanceof Error?y.message:"Failed to load payout account");}finally{p.current&&o(false);}},[n,r]);jn.useEffect(()=>(p.current=true,m(),()=>{p.current=false;}),[m]);let g=jn.useCallback(async y=>{try{u(!0),d(null);let b=y?`${n}/api/payout?stackId=${encodeURIComponent(y)}`:`${n}/api/payout`,h=await fetch(b,{method:"DELETE",headers:{...j()},credentials:"include"});if(!h.ok&&h.status!==204)throw new Error(await C(h,`Disconnect failed (${h.status})`));return await m(),!0}catch(b){return p.current&&d(b instanceof Error?b.message:"Disconnect failed"),false}finally{p.current&&u(false);}},[n,m]);return {account:l,loading:s,error:i,refresh:m,disconnect:g,disconnecting:c}}function Rn(){let{config:e}=k(),t=e.apiBaseUrl,[r,n]=jn.useState([]),[l,a]=jn.useState(true),[s,o]=jn.useState(null),i=jn.useRef(true),d=jn.useCallback(async()=>{try{a(!0),o(null);let c=await fetch(`${t}/api/payout/stripe-stacks`,{credentials:"include"});if(!c.ok)throw new Error(await C(c,`Failed to load stripe stacks (${c.status})`));let u=await c.json();i.current&&n(u.stacks??[]);}catch(c){i.current&&o(c instanceof Error?c.message:"Failed to load stripe stacks");}finally{i.current&&a(false);}},[t]);return jn.useEffect(()=>(i.current=true,d(),()=>{i.current=false;}),[d]),{stacks:r,loading:l,error:s,refresh:d}}function gt(e){let{config:t}=k(),r=e??t.stackId,[n,l]=jn.useState(false),[a,s]=jn.useState(null);return {startStripeConnect:jn.useCallback(async()=>{try{l(!0),s(null);let i=await fetch(`${t.apiBaseUrl}/api/payout/stripe/start`,{method:"POST",headers:{"Content-Type":"application/json",...j()},credentials:"include",body:JSON.stringify({stackId:r})});if(!i.ok)throw new Error(await C(i,`Stripe Connect start failed (${i.status})`));let d=await i.json();if(typeof window<"u"&&d.onboardingUrl){let c;try{c=new URL(d.onboardingUrl);}catch{throw new Error("Invalid onboarding URL")}if(c.protocol!=="https:"||!/(^|\.)stripe\.com$/.test(c.hostname))throw new Error("Refusing to redirect to non-Stripe URL");window.location.href=c.toString();return}}catch(i){s(i instanceof Error?i.message:"Stripe Connect start failed");}finally{l(false);}},[t.apiBaseUrl,r]),starting:n,error:a}}function En(){if(typeof window>"u")return null;let e=window,t=e.solana,r=e.phantom?.solana;return ((t&&t.isPhantom?t:null)||(r&&r.isPhantom?r:null))??null}function Un(e){let t="";for(let r=0;r<e.length;r+=1)t+=String.fromCharCode(e[r]);return typeof btoa=="function"?btoa(t):Buffer.from(e).toString("base64")}function yt(){let{config:e}=k(),[t,r]=jn.useState(false),[n,l]=jn.useState(null);return {connectAndVerify:jn.useCallback(async()=>{try{r(!0),l(null);let s=En();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",...j()},credentials:"include",body:JSON.stringify({address:i})});if(!d.ok)throw new Error(await C(d,`Nonce request failed (${d.status})`));let{nonce:c,message:u}=await d.json(),p=new TextEncoder().encode(u),m=await s.signMessage(p,"utf8"),g=Un(m.signature),y=await fetch(`${e.apiBaseUrl}/api/payout/crypto/verify`,{method:"POST",headers:{"Content-Type":"application/json",...j()},credentials:"include",body:JSON.stringify({address:i,nonce:c,signature:g})});if(!y.ok)throw new Error(await C(y,`Verification failed (${y.status})`));return {address:i}}catch(s){let o=s instanceof Error?s:new Error("Wallet verification failed");return l(o.message),null}finally{r(false);}},[e.apiBaseUrl]),connecting:t,error:n}}var rr=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function ht({amountSol:e,onSuccess:t,onError:r,disabled:n,className:l,style:a}){let{config:s}=k(),[o,i]=jn.useState(false),[d,c]=jn.useState(null),u=!!(s.merchantWallet&&rr.test(s.merchantWallet)),p=jn.useCallback(async()=>{if(u)try{i(!0),c(null);let{Connection:m,PublicKey:g,Transaction:y,SystemProgram:b,LAMPORTS_PER_SOL:h}=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 M=E,w;try{w=new g(s.merchantWallet);}catch{throw new Error("Invalid merchant wallet address.")}let H=await M.connect(),D=new g(H.publicKey.toString()),K="https://api.mainnet-beta.solana.com",z=_(s.solanaRpcUrl,K),q=z==="#"?K:z,O=new m(q),{blockhash:W}=await O.getLatestBlockhash(),Z=BigInt(Math.floor(e*1e9)),me=s.protocolTreasuryWallet,fe=s.protocolFeeBps??500,ie=new y({recentBlockhash:W,feePayer:D});if(me&&rr.test(me)&&fe>0){let le=Z*BigInt(fe)/10000n,Ir=Z-le,Er=new g(me);ie.add(b.transfer({fromPubkey:D,toPubkey:w,lamports:Number(Ir)}),b.transfer({fromPubkey:D,toPubkey:Er,lamports:Number(le)}));}else ie.add(b.transfer({fromPubkey:D,toPubkey:w,lamports:Number(Z)}));let{signature:xe}=await M.signAndSendTransaction(ie);t(xe);}catch(m){let g=m instanceof Error?m:new Error("Payment failed");c(g.message),r?.(g);}finally{i(false);}},[e,s.merchantWallet,u,t,r]);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("button",{onClick:p,disabled:n||o||!u,"aria-label":`Pay ${e.toFixed(4)} SOL`,className:f("flex w-full items-center justify-center gap-2 rounded-2xl bg-purple-600 py-6 text-base font-semibold text-white transition-colors hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed",l),style:a,children:o?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 kt({result:e,className:t,style:r}){let[n,l]=jn.useState(false),a=jn.useRef(null);jn.useEffect(()=>()=>{a.current&&clearTimeout(a.current);},[]);let s=jn.useCallback(()=>{e.key?.key&&(navigator.clipboard.writeText(e.key.key),l(true),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>l(false),2e3));},[e.key?.key]);return !e.success||!e.key?null:jsxRuntime.jsxs("div",{className:f("rounded-lg border border-green-500/20 bg-green-500/10 p-6 text-center",t),style:r,children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"mx-auto mb-3 h-12 w-12 text-green-500"}),jsxRuntime.jsx("h3",{className:"mb-2 text-lg font-semibold text-foreground",children:"Key Generated!"}),jsxRuntime.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Your node key has been successfully generated."}),jsxRuntime.jsxs("div",{className:"mx-auto flex max-w-md items-center gap-2 rounded-md border bg-background p-3",children:[jsxRuntime.jsx("code",{className:"flex-1 truncate text-xs text-foreground",children:e.key.key}),jsxRuntime.jsx("button",{onClick: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:f("animate-pulse rounded-xl bg-muted",e)})}function vt(){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 he({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(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"})]})]},r))})}function qn({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 ar({pricing:e,quantity:t}){let[r,n]=jn.useState(false),l=e.priceUsd*t;return jsxRuntime.jsxs("div",{className:"rounded-2xl border bg-background",children:[jsxRuntime.jsxs("button",{onClick:()=>n(!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:["$",l.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:["$",l.toFixed(2)]})]})]})]})}function Jn({method:e}){return jsxRuntime.jsxs("div",{role:"status","data-payment-method":e,className:"flex flex-col items-center gap-2 rounded-2xl border border-border bg-muted/20 px-6 py-8 text-center",children:[jsxRuntime.jsx(lucideReact.Wallet,{className:"h-6 w-6 text-muted-foreground"}),jsxRuntime.jsxs("p",{className:"text-sm font-medium text-foreground",children:["Pay with ",Se(e)]}),jsxRuntime.jsxs("p",{className:"text-xs text-muted-foreground",children:["A deposit address will appear here once the ",Se(e)," rail confirms your payment. Your key mints automatically after the network confirms."]})]})}function Nt({className:e,style:t}){let{config:r}=k(),{pricing:n,loading:l,error:a,refresh:s}=Xe(),{mint:o,minting:i,result:d,error:c}=nt(),{createSession:u,loading:p,error:m}=ot(),[g,y]=jn.useState(1),b=ze(r.paymentMethods),[h,E]=jn.useState(b[0]??"solana"),[M,w]=jn.useState(0),[H,D]=jn.useState(false),K=jn__default.default.useRef(g);K.current=g;let z=Math.max(1,r.maxQuantity||5);if(jn.useEffect(()=>{if(typeof window>"u")return;let Z=new URLSearchParams(window.location.search).get("session_id");if(!Z){try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}return}if(/^cs_(test|live)_/.test(Z)&&!H&&!d?.success){let me=false;try{me=sessionStorage.getItem("keyutils_stripe_pending")==="1";}catch{}if(!me)return;try{sessionStorage.removeItem("keyutils_stripe_pending");}catch{}D(true);let fe=new URL(window.location.href);fe.searchParams.delete("session_id"),window.history.replaceState({},"",fe.toString());let ie=K.current;try{let xe=sessionStorage.getItem("keyutils_stripe_quantity");xe&&(ie=parseInt(xe,10)||1,sessionStorage.removeItem("keyutils_stripe_quantity"));}catch{}o("stripe",Z,ie);}},[H,d,o]),d?.success)return jsxRuntime.jsx("div",{className:f("flex flex-col items-center justify-center",e),style:t,children:jsxRuntime.jsx(kt,{result:d})});if(H||i)return jsxRuntime.jsx("div",{className:f("flex flex-col",e),style:t,children:jsxRuntime.jsx(vt,{})});if(l)return jsxRuntime.jsx("div",{className:f("flex flex-col",e),style:t,children:jsxRuntime.jsx(vt,{})});if(a||!n)return jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-24",e),style:t,children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load pricing"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a||"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 q=async W=>{w(2),await o(h,W,g);},O=()=>{u(n.priceCents,g);};return jsxRuntime.jsx("div",{className:f("flex flex-col",e),style:t,children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[M===0&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[r.keyImage&&jsxRuntime.jsx("img",{src:_(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:["$",n.priceUsd.toFixed(2)]}),jsxRuntime.jsxs("p",{className:"mt-2 text-base text-muted-foreground",children:["per key \xB7 ",n.tokenAllocationFormatted||F(n.tokenAllocation)," tokens included"]})]}),jsxRuntime.jsx(qn,{quantity:g,max:z,onChange:y}),jsxRuntime.jsx(ar,{pricing:n,quantity:g}),jsxRuntime.jsx("button",{onClick:()=>w(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"})]}),M===1&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[b.length>1&&jsxRuntime.jsx("div",{role:"tablist",className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5",children:b.map(W=>jsxRuntime.jsxs("button",{role:"tab","aria-selected":h===W,onClick:()=>E(W),className:f("flex flex-1 items-center justify-center gap-2.5 rounded-xl py-4 text-sm font-medium transition-colors",h===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"}),Se(W)]},W))}),jsxRuntime.jsx(ar,{pricing:n,quantity:g}),h==="stripe"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{onClick:O,disabled:p,className:"flex w-full items-center justify-center gap-2 rounded-2xl bg-foreground py-6 text-base font-semibold text-background transition-colors hover:bg-foreground/90 disabled:opacity-50",children:p?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin"}),"Redirecting to Stripe..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-5 w-5"}),"Pay with Card"]})}),m&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-500",children:m})]}):h==="solana"?jsxRuntime.jsx(ht,{amountSol:n.priceSol??0,onSuccess:q}):jsxRuntime.jsx(Jn,{method:h}),c&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-500",children:c}),jsxRuntime.jsx("button",{type:"button",onClick:()=>w(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 Zn={ios:"iOS",android:"Android",windows:"Windows",mac:"macOS",linux:"Linux"},es=["mac","windows","linux","ios","android"],ts="https://www.stacknet.org/download";function wt({downloads:e,className:t,style:r}){let{config:n}=k(),l=jn.useMemo(()=>Wt(),[]),a=e||es.map(i=>({platform:i,label:Zn[i],url:ts,compatible:i===l})),s=a.find(i=>i.compatible)||a[0],o=a.filter(i=>i.platform!==s.platform);return jsxRuntime.jsxs("div",{className:f("space-y-8",t),style:r,children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-6 pt-4 mt-4",children:[n.aispImage&&jsxRuntime.jsx("img",{src:_(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:_(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"," ",o.map((i,d)=>jsxRuntime.jsxs(jn__default.default.Fragment,{children:[d>0&&(d===o.length-1?" and ":", "),jsxRuntime.jsx("a",{href:_(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:_(n.termsUrl,"/terms"),target:"_blank",rel:"noopener noreferrer",className:"text-foreground underline hover:text-foreground/80",children:"Open Source Applications Terms"})]})]})]})}var rs={"bg-green-500":"bg-green-900/50","bg-yellow-500":"bg-yellow-900/50","bg-red-500":"bg-red-900/50"};function oe({current:e,max:t,className:r,style:n,showLabel:l=true,segments:a=40}){let s=Ht(e,t),o=Ot(s),i=rs[o]||"bg-muted",d=Math.round(s/100*a);return jsxRuntime.jsxs("div",{className:f("w-full",r),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:[F(e)," / ",F(t)]}),jsxRuntime.jsxs("span",{children:[s,"%"]})]}),jsxRuntime.jsx("div",{className:"flex h-6 w-full items-stretch gap-1",children:Array.from({length:a}).map((c,u)=>jsxRuntime.jsx("div",{className:f("flex-1 rounded-[1px] transition-colors duration-300",u<d?o:i)},u))})]})}function Fe({open:e,onClose:t,title:r,children:n}){let l=jn.useRef(null),[a,s]=jn.useState(false),[o,i]=jn.useState(false),d=jn.useCallback(c=>{c.key==="Escape"&&t();},[t]);return jn.useEffect(()=>{if(e)s(true),document.addEventListener("keydown",d),document.body.style.overflow="hidden",requestAnimationFrame(()=>{requestAnimationFrame(()=>i(true));});else {i(false);let c=setTimeout(()=>{s(false),document.body.style.overflow="";},300);return document.removeEventListener("keydown",d),()=>clearTimeout(c)}return ()=>{document.removeEventListener("keydown",d);}},[e,d]),a?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",children:[jsxRuntime.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm transition-opacity duration-300",style:{opacity:o?1:0},onClick:t}),jsxRuntime.jsxs("div",{ref:l,className:f("relative z-10 w-full max-w-xl rounded-t-2xl bg-background shadow-2xl","max-h-[85vh] flex flex-col","transition-transform duration-300 ease-out"),style:{transform:o?"translateY(0)":"translateY(100%)"},children:[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:n})]})]}):null}var je=[" .-----."," / (_) \\"," / \\","( )"," \\ /"," \\_______/"," || |"," || |"," || /"," || /"," || \\"," || /"," || /"," \\// "],Ct=16,is=Ct*.6,dr=Ct*1;function St({className:e,style:t,color:r="currentColor",ariaLabel:n="Node key",keyImage:l,keyImageClass:a}){if(l)return jsxRuntime.jsx("img",{src:_(l),alt:n,className:f(a||"h-20 w-auto mx-auto",e),style:t});let s=je.reduce((p,m)=>Math.max(p,m.length),0),o=je.length,i=s*is,c=o*dr;return jsxRuntime.jsx("svg",{viewBox:`0 0 ${c} ${i}`,xmlns:"http://www.w3.org/2000/svg",className:f("block",e),style:t,role:"img","aria-label":n,preserveAspectRatio:"xMidYMid meet",children:jsxRuntime.jsx("g",{transform:`translate(0 ${i}) rotate(-90)`,children:je.map((p,m)=>jsxRuntime.jsx("text",{x:0,y:(m+.8)*dr,fill:r,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:Ct,xmlSpace:"preserve",children:p},m))})})}function fs(e){if(!e)return "";try{return new Date(e).toLocaleTimeString()}catch{return ""}}function ps({state:e,isLast:t}){let r=e.status==="done",n=e.status==="current",l=e.status==="failed",a=r?lucideReact.Check:l?lucideReact.AlertCircle:n?lucideReact.ArrowRight:lucideReact.Circle,s=f("flex h-8 w-8 shrink-0 items-center justify-center rounded-full",n&&"bg-foreground text-background",r&&"bg-green-500/15 text-green-500",l&&"bg-red-500/15 text-red-500",!r&&!n&&!l&&"bg-muted text-muted-foreground"),o=Re[e.id],i=r?o.done:n?o.progressing:o.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(a,{className:"h-4 w-4"})}),!t&&jsxRuntime.jsx("div",{className:f("w-px flex-1 mt-1",r?"bg-green-500/30":"bg-border"),style:{minHeight:32}})]}),jsxRuntime.jsxs("div",{className:f("flex-1 pb-6",t&&"pb-0"),children:[jsxRuntime.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[jsxRuntime.jsxs("span",{className:f("text-sm font-medium lowercase",r&&"text-foreground font-bold",n&&"text-foreground",l&&"text-red-500",!r&&!n&&!l&&"text-muted-foreground"),children:[i,e.id==="confirmed"&&e.approvalsCount!=null&&e.approvalsThreshold!=null&&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:fs(e.timestampMs)})]}),e.detail&&jsxRuntime.jsx("p",{className:f("mt-0.5 text-xs",l?"text-red-500":"text-muted-foreground"),children:e.detail}),e.externalUrl&&jsxRuntime.jsxs("a",{href:_(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 Rt({states:e,className:t}){return jsxRuntime.jsx("ol",{className:f("flex flex-col",t),children:e.map((r,n)=>jsxRuntime.jsx(ps,{state:r,isLast:n===e.length-1},r.id))})}function Tt({text:e,speedMs:t=40,playing:r,className:n}){let[l,a]=jn.useState(()=>r?"":e);return jn.useEffect(()=>{if(!r){a(e);return}a("");let s=0,o=false,i,d=()=>{o||(s+=1,a(e.slice(0,s)),s<e.length&&(i=setTimeout(d,t)));};return i=setTimeout(d,t),()=>{o=true,clearTimeout(i);}},[e,t,r]),jsxRuntime.jsxs("span",{className:n,children:[l,r?jsxRuntime.jsx("span",{"aria-hidden":"true",className:"font-mono font-normal opacity-70",children:"\u258A"}):null]})}function ge(e,t=6,r=6){return e?e.length<=t+r+1?e:`${e.slice(0,t)}\u2026${e.slice(-r)}`:""}function Cs({value:e}){let[t,r]=jn.useState(false);return jsxRuntime.jsx("button",{type:"button",onClick:()=>{typeof navigator>"u"||!navigator.clipboard||(navigator.clipboard.writeText(e),r(true),setTimeout(()=>r(false),1200));},className:"text-muted-foreground hover:text-foreground transition-colors","aria-label":"Copy",children:t?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 G({label:e,value:t,href:r,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:[r?jsxRuntime.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"text-xs font-mono text-foreground underline underline-offset-4 break-all",children:t}):jsxRuntime.jsx("span",{className:"text-xs font-mono text-foreground break-all",children:t}),n&&jsxRuntime.jsx(Cs,{value:n})]})]})}function Ss({detail:e}){let[t,r]=jn.useState(false);return jsxRuntime.jsxs("div",{className:"border border-border rounded-xl",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>r(!t),className:"flex w-full items-center justify-between p-4 text-sm font-semibold text-foreground hover:bg-muted/40 transition-colors rounded-xl",children:["Technical details",t?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"h-4 w-4"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-4 w-4"})]}),t&&jsxRuntime.jsxs("div",{className:"px-4 pb-3",children:[jsxRuntime.jsx(G,{label:"Filing ID",value:ge(e.filingId,8,8),copyValue:e.filingId}),jsxRuntime.jsx(G,{label:"Key ID",value:ge(e.keyId,8,8),copyValue:e.keyId}),jsxRuntime.jsx(G,{label:"File hash",value:ge(e.fileHash,8,8),copyValue:e.fileHash}),e.intentHashHex&&jsxRuntime.jsx(G,{label:"Intent hash",value:ge(e.intentHashHex,8,8),copyValue:e.intentHashHex}),e.proofPda&&jsxRuntime.jsx(G,{label:"Proof PDA",value:ge(e.proofPda,8,8),copyValue:e.proofPda}),e.txSignature&&jsxRuntime.jsx(G,{label:"Tx",value:ge(e.txSignature,8,8),href:`https://solscan.io/tx/${encodeURIComponent(e.txSignature)}`,copyValue:e.txSignature}),jsxRuntime.jsx(G,{label:"Beneficiary",value:ge(e.beneficiary,8,8),copyValue:e.beneficiary}),e.onchainBeneficiary&&e.onchainBeneficiary!==e.beneficiary&&jsxRuntime.jsx(G,{label:"On-chain wallet",value:ge(e.onchainBeneficiary,8,8),copyValue:e.onchainBeneficiary}),jsxRuntime.jsx(G,{label:"Payout method",value:e.payoutMethod}),jsxRuntime.jsx(G,{label:"Memo",value:e.memo}),jsxRuntime.jsx(G,{label:"Amount",value:Ae(e.amountUsdc)}),jsxRuntime.jsx(G,{label:"Tokens used",value:e.tokensUsed}),jsxRuntime.jsx(G,{label:"Filed at",value:ee(e.filedAt)}),e.stripePaymentIntentId&&jsxRuntime.jsx(G,{label:"Stripe PI",value:ge(e.stripePaymentIntentId,6,6),copyValue:e.stripePaymentIntentId}),e.failureReason&&jsxRuntime.jsx(G,{label:"Failure",value:e.failureReason})]})]})}function It({filingId:e,className:t,style:r}){let{detail:n,loading:l,error:a}=ft(e),s=jn__default.default.useMemo(()=>qe(n?.tracker),[n?.tracker]),o=Je(s,!!n),i=s.find(d=>d.status==="failed");return a&&!n?jsxRuntime.jsxs("div",{className:f("space-y-4",t),style:r,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:a})]}):jsxRuntime.jsxs("div",{className:f("space-y-5",t),style:r,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:f("text-4xl font-mono tracking-tight",i?"text-red-500":"text-foreground"),children:i?o.text:jsxRuntime.jsx(Tt,{text:o.text,playing:o.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(Rt,{states:s}),n&&jsxRuntime.jsx(Ss,{detail:n})]})}function Ms(e,t=6,r=6){return !e||e.length<=t+r+1?e:`${e.slice(0,t)}\u2026${e.slice(-r)}`}function Fs({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 Bs({nodeKey:e,stackName:t}){let r=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:Ms(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:[F(r)," / ",F(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:ee(e.createdAt)})]})]})}function Et({keyId:e,onComplete:t,onBack:r,onViewFiling:n,onConfigureEarnings:l,className:a,style:s}){let{config:o}=k(),{keys:i,loading:d,error:c,refresh:u}=te(),p=i.find(le=>le.id===e),{account:m,loading:g,error:y}=Ue(p?.stackId),{filePaperwork:b,filing:h,result:E,error:M}=lt(),[w,H]=jn.useState(false),[D,K]=jn.useState(false),z=le=>D?"* * * *":le;jn.useEffect(()=>{E&&!w&&(H(true),t?.(E),u());},[E,w,t,u]);let q=!!p?.paperWork&&p.paperWork!=="0",O=!!m?.method,W=q&&O&&!h&&!E,Z=async()=>{if(!W||!p)return;let le=m?.method==="solana"?"usdc":m?.method==="stripe"?"stripe":null;await b(p.id,le);};if(E)return jsxRuntime.jsxs("div",{className:f("space-y-6",a),style:s,children:[jsxRuntime.jsx(It,{filingId:E.filingId}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[n&&jsxRuntime.jsx("button",{type:"button",onClick:()=>n(E.filingId),className:"flex-1 rounded-xl bg-foreground text-background py-3 text-sm font-semibold hover:bg-foreground/90 transition-colors",children:"Open filing"}),r&&jsxRuntime.jsx("button",{type:"button",onClick:r,className:"flex-1 rounded-xl border border-border bg-background text-foreground py-3 text-sm font-semibold hover:bg-muted/50 transition-colors",children:"Back to dashboard"})]})]});if(d||g)return jsxRuntime.jsxs("div",{className:f("space-y-4",a),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(c||!p)return jsxRuntime.jsxs("div",{className:f("space-y-4",a),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:c?"Unable to load keys":"Key not found"})]}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:c||`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 me=p.stackName||o.stackName,fe=null,ie=null,xe="";return m?.method==="solana"&&m.solana?(ie=jsxRuntime.jsx(Fs,{className:"h-7 w-7 shrink-0"}),xe="USDC",fe=jsxRuntime.jsx("code",{className:"text-xs text-foreground break-all",children:z(m.solana.address)})):m?.method==="stripe"&&m.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"})}),xe="USD via Stripe",fe=jsxRuntime.jsxs("span",{className:"text-xs text-foreground",children:["Stripe account ",jsxRuntime.jsx("code",{className:"text-xs",children:z(m.stripe.accountIdMasked)}),!m.stripe.payoutsEnabled&&jsxRuntime.jsx("span",{className:"ml-2 text-amber-600",children:"(payouts pending)"})]})),jsxRuntime.jsxs("div",{className:f("space-y-6",a),style:s,children:[jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Your earnings will be deposited into your earnings account."}),jsxRuntime.jsx(Bs,{nodeKey:p,stackName:me}),!q&&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."}),y&&!O&&jsxRuntime.jsxs("div",{className:"rounded-xl bg-muted/30 p-4 text-sm text-muted-foreground",children:["Couldn't load your earnings account (",y,"). Try again in a moment."]}),!O&&!y?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"]})]}):O&&q?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:xe}),fe]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>K(le=>!le),"aria-label":D?"Show address":"Hide address","aria-pressed":D,className:"ml-auto mt-0.5 p-0.5 text-muted-foreground hover:text-foreground transition-colors shrink-0",children:D?jsxRuntime.jsx(lucideReact.Eye,{className:"h-4 w-4"}):jsxRuntime.jsx(lucideReact.EyeOff,{className:"h-4 w-4"})})]})]}):null,M&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:M}),jsxRuntime.jsx("button",{type:"button",onClick:Z,disabled:!W,className:f("w-full rounded-xl py-4 text-sm font-semibold transition-colors",W?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:h?"Filing\u2026":"File Paperwork"})]})}function js({nodeKey:e,onSuccess:t}){let{transferKey:r,transferring:n,result:l,error:a}=Ee(),[s,o]=jn.useState(""),[i,d]=jn.useState(false),c=s.trim()===e.userId,u=s.trim().length>0&&i&&!c&&!n,p=async()=>{if(!u)return;await r(e.id,s.trim())&&t();};return l?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:m=>{o(m.target.value),d(false);},placeholder:"Enter recipient's user ID or global ID",className:"w-full rounded-xl border border-border bg-background px-4 py-3 text-sm text-foreground placeholder:text-muted-foreground focus:border-foreground/30 focus:outline-none focus:ring-1 focus:ring-foreground/10"}),c&&jsxRuntime.jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),s.trim().length>0&&!c&&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)})," ","(",F(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:m=>d(m.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border"}),jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"I confirm this transfer is permanent and cannot be undone."})]})]})]})}),a&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:a}),jsxRuntime.jsx("button",{onClick:p,disabled:!u,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",u?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children: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 Hs({nodeKey:e,onSuccess:t}){let{config:r}=k(),{listKey:n,listing:l,result:a,error:s}=Ie(),[o,i]=jn.useState(""),[d,c]=jn.useState(false),u=parseInt(o.replace(/[^0-9]/g,""),10)||0,m=u>0&&Number.isFinite(u)&&d&&!l,g=async()=>{if(!m)return;let y=u*100;await n(e.id,y)&&t();};return a?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:a.listingId})]}),jsxRuntime.jsxs("a",{href:`https://market.stacknet.org/keys/${encodeURIComponent(a.keyId)}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 rounded-xl bg-foreground px-6 py-3 text-sm font-semibold text-background transition-colors hover:bg-foreground/90",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),"View Listing"]})]}):jsxRuntime.jsxs("div",{className:"space-y-5",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{htmlFor:"listing-price",className:"mb-2 block text-sm font-semibold text-foreground",children:"Listing Price (USD)"}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-2xl font-bold text-muted-foreground",children:"$"}),jsxRuntime.jsx("input",{id:"listing-price",type:"text",inputMode:"numeric",value:o,onChange:y=>{let b=y.target.value.replace(/[^0-9]/g,""),h=parseInt(b,10);i(isNaN(h)?"":h.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:()=>c(!d),className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors cursor-pointer",d?"border-foreground bg-foreground":"border-muted-foreground/40"),children:d&&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:_(r.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:!m,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",m?"bg-foreground text-background hover:bg-foreground/90":"bg-muted text-muted-foreground cursor-not-allowed"),children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"h-4 w-4"}),l?"Listing...":"List on Marketplace"]})]})}function Os({nodeKey:e,onSuccess:t,onClose:r,onViewFiling:n,onConfigureEarnings:l}){return jsxRuntime.jsx(Et,{keyId:e.id,onComplete:t,onBack:r,onViewFiling:n,onConfigureEarnings:l})}function Ut({nodeKey:e,onBack:t,onKeysChanged:r,onViewFiling:n,onConfigureEarnings:l,className:a,style:s}){let{config:o}=k(),{entries:i,loading:d}=Te(e.id),[c,u]=jn.useState(null),[p,m]=jn.useState(false),g=()=>{u(null),r?.();},y=E=>{},b=()=>{e.key&&(navigator.clipboard.writeText(e.key),m(true),setTimeout(()=>m(false),2e3));},h=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsxRuntime.jsxs("div",{className:f("space-y-5",a),style:s,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(St,{className:f("mx-auto text-foreground px-0 sm:px-0",o.keyImage?"w-2/3 h-auto":"h-20 w-auto"),keyImage:o.keyImage,keyImageClass:o.keyImageClass}),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:f("text-sm font-medium capitalize",h),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:[(o.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||o.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:ee(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:ee(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:Ae(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(Fe,{open:c==="transfer",onClose:()=>u(null),title:"Transfer Key",children:jsxRuntime.jsx(js,{nodeKey:e,onSuccess:g})}),jsxRuntime.jsx(Fe,{open:c==="sell",onClose:()=>u(null),title:"Sell Key",children:jsxRuntime.jsx(Hs,{nodeKey:e,onSuccess:g})}),jsxRuntime.jsx(Fe,{open:c==="file",onClose:()=>u(null),title:"File Paperwork",children:jsxRuntime.jsx(Os,{nodeKey:e,onSuccess:y,onClose:()=>u(null),onViewFiling:n,onConfigureEarnings:l})})]})}function Ws({nodeKey:e,onClick:t}){let r=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500";return jsxRuntime.jsx("button",{onClick:t,className:"flex w-full items-start gap-3 rounded-xl border border-border p-4 text-left transition-all hover:border-foreground/20 hover:bg-muted/30",children:jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:f("text-xs font-medium capitalize",r),children:e.status})]}),jsxRuntime.jsx(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 Kt({onViewFiling:e,onConfigureEarnings:t,className:r,style:n}){let{keys:l,totalBalance:a,loading:s,error:o,refresh:i}=te(),[d,c]=jn.useState(null),[u,p]=jn.useState("active"),m=l.filter(b=>b.status===u),g=m.reduce((b,h)=>b+h.tokenBalance,0),y=l.find(b=>b.id===d);return y?jsxRuntime.jsx(Ut,{nodeKey:y,onBack:()=>c(null),onKeysChanged:()=>{c(null),i();},onViewFiling:e,onConfigureEarnings:t,className:r,style:n}):s?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:n,children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx(he,{count:3})]}):o?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-16",r),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:o})]}),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:f("flex flex-col items-center justify-center gap-4 rounded-xl border border-dashed py-16",r),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:f("space-y-4",r),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:[m.length," key",m.length!==1?"s":""," \xB7 ",F(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:f("rounded-md px-3 py-1 text-xs font-medium capitalize transition-all",u===b?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:b},b))})]}),m.length===0?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:m.map(b=>jsxRuntime.jsx(Ws,{nodeKey:b,onClick:()=>c(b.id)},b.id))})]})}var zs=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function Ys({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:zs.map(({id:r,label:n})=>jsxRuntime.jsx("button",{role:"tab","aria-selected":e===r,"aria-controls":`panel-${r}`,id:`tab-${r}`,onClick:()=>t(r),className:f("flex flex-1 items-center justify-center gap-2.5 rounded-xl py-3.5 text-sm font-medium transition-all",e===r?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:jsxRuntime.jsx("span",{className:"inline",children:n})},r))})}function qs({defaultTab:e="buy",onViewFiling:t,onConfigureEarnings:r,className:n,style:l}){let[a,s]=jn.useState(e);return jsxRuntime.jsxs("div",{className:f("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(Ys,{active:a,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-${a}`,"aria-labelledby":`tab-${a}`,children:[a==="buy"&&jsxRuntime.jsx(Nt,{className:"flex-1"}),a==="use"&&jsxRuntime.jsx(wt,{className:"flex-1"}),a==="keys"&&jsxRuntime.jsx(Kt,{className:"flex-1",onViewFiling:t,onConfigureEarnings:r})]})})})]})}function Js({apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:n,merchantWallet:l,stripePublicKey:a,theme:s,maxQuantity:o,keyImage:i,keyImageClass:d,aispImage:c,termsUrl:u,onMintSuccess:p,onMintError:m,onPaymentStart:g,onPaymentComplete:y,onListingCreated:b,onTransferComplete:h,onFilingComplete:E,onFilingError:M,defaultTab:w,onViewFiling:H,onConfigureEarnings:D,className:K,style:z}){return jsxRuntime.jsx(Ge,{config:{apiBaseUrl:e,stackId:t,stackName:r,paymentMethods:n,merchantWallet:l,stripePublicKey:a,theme:s,maxQuantity:o,keyImage:i,keyImageClass:d,aispImage:c,termsUrl:u},callbacks:{onMintSuccess:p,onMintError:m,onPaymentStart:g,onPaymentComplete:y,onListingCreated:b,onTransferComplete:h,onFilingComplete:E,onFilingError:M},children:jsxRuntime.jsx(qs,{defaultTab:w,onViewFiling:H,onConfigureEarnings:D,className:K,style:z})})}function Xs({nodeKey:e,selected:t,onSelect:r}){return jsxRuntime.jsxs("button",{onClick:r,className:f("flex w-full items-start gap-3 rounded-xl border p-4 text-left transition-all",t?"border-foreground/30 bg-foreground/5 ring-1 ring-foreground/10":"border-border hover:border-foreground/20"),children:[jsxRuntime.jsx("div",{className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors",t?"border-foreground bg-foreground":"border-muted-foreground/40"),children:t&&jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 text-background"})}),jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:f("text-xs font-medium capitalize",e.status==="active"?"text-green-500":"text-muted-foreground"),children:e.status})]}),jsxRuntime.jsx(oe,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function Zs({className:e,style:t}){let{config:r}=k(),{keys:n,loading:l,error:a,refresh:s}=te(),{listKey:o,listing:i,result:d,error:c}=Ie(),[u,p]=jn.useState(null),[m,g]=jn.useState(""),[y,b]=jn.useState(false),h=n.find(K=>K.id===u),E=parseInt(m.replace(/[^0-9]/g,""),10)||0,M=E>0&&Number.isFinite(E),w=!!h&&M&&y&&!i,H=async()=>{if(!w||!h)return;let K=E*100;await o(h.id,K)&&s();};if(d)return jsxRuntime.jsxs("div",{className:f("flex flex-col items-center gap-4 rounded-xl bg-green-500/10 py-12",e),style:t,children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Key Listed!"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Your key is now on the Global Open AI Network marketplace."}),jsxRuntime.jsxs("p",{className:"text-xs text-muted-foreground",children:["Listing ID: ",jsxRuntime.jsx("code",{children: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:f("space-y-5 px-1",e),style:t,children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx(he,{count:2})]});if(a)return jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-4 py-16",e),style:t,children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a})]}),jsxRuntime.jsx("button",{onClick:()=>s(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]});let D=n.filter(K=>K.status==="active");return D.length===0?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16",e),style:t,children:[jsxRuntime.jsx(lucideReact.AlertTriangle,{className:"h-8 w-8 text-muted-foreground"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"No active keys to sell."})]}):jsxRuntime.jsxs("div",{className:f("space-y-5",e),style:t,children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-2xl mt-3 mb-2 font-semibold text-foreground",children:"Your Keys"}),jsxRuntime.jsx("div",{className:"space-y-2",children:D.map(K=>jsxRuntime.jsx(Xs,{nodeKey:K,selected:u===K.id,onSelect:()=>p(K.id)},K.id))})]}),h&&jsxRuntime.jsxs("div",{className:"rounded-xl border bg-muted/30 p-5 space-y-2 text-sm",children:[h.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:["#",h.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:h.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:[F(h.tokenBalance)," / ",F(h.maxTokens)]})]}),h.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:h.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:ee(h.createdAt)})]})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{htmlFor:"listing-price",className:"mb-2 block text-sm sm:text-lg font-semibold text-foreground",children:"Listing Price (USD)"}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-2xl font-bold text-muted-foreground",children:"$"}),jsxRuntime.jsx("input",{id:"listing-price",type:"text",inputMode:"numeric",value:m,onChange:K=>{let z=K.target.value.replace(/[^0-9]/g,""),q=parseInt(z,10);g(isNaN(q)?"":q.toLocaleString("en-US"));},placeholder:"0",className:"w-full rounded-xl border bg-background py-6 pl-10 pr-4 text-3xl font-bold text-foreground placeholder:text-muted-foreground/30 focus:outline-none focus:ring-2 focus:ring-foreground/20"})]})]}),jsxRuntime.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntime.jsx("button",{type:"button",role:"checkbox","aria-checked":y,onClick:()=>b(!y),className:f("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:_(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:H,disabled:!w,className:f("flex w-full items-center justify-center gap-2 rounded-xl py-4 text-sm font-semibold transition-colors",w?"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 Mt=20;function Ft({nodeKey:e,className:t,style:r}){let[n,l]=jn.useState(false),[a,s]=jn.useState(false),o=jn.useRef(null),{entries:i,loading:d}=Te(n?e.id:null);jn.useEffect(()=>()=>{o.current&&clearTimeout(o.current);},[]);let c=jn.useCallback(()=>{e.key&&(navigator.clipboard.writeText(e.key),s(true),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>s(false),2e3));},[e.key]),u=e.status==="active"?"text-green-500":e.status==="expired"?"text-red-500":"text-yellow-500",p=i.slice(0,Mt);return jsxRuntime.jsxs("div",{className:f("rounded-lg border bg-background",t),style:r,children:[jsxRuntime.jsxs("div",{className:"p-4",children:[jsxRuntime.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("button",{onClick:()=>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:f("text-xs font-medium capitalize",u),children:e.status})]}),e.key&&jsxRuntime.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[jsxRuntime.jsx("code",{className:"flex-1 truncate rounded bg-muted px-2 py-1 text-xs text-muted-foreground",children:e.key}),jsxRuntime.jsx("button",{onClick:c,"aria-label":"Copy key to clipboard",className:"shrink-0 rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:a?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 ",ee(e.createdAt)]}),e.expiresAt&&jsxRuntime.jsxs("span",{children:["Expires ",ee(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(m=>jsxRuntime.jsxs("div",{className:"flex items-center justify-between text-xs",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("span",{className:f("font-medium",m.type==="credit"||m.type==="reward"?"text-green-500":"text-red-500"),children:[m.type==="credit"||m.type==="reward"?"+":"-",F(Math.abs(m.amount))]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:m.description})]}),jsxRuntime.jsx("span",{className:"text-muted-foreground",children:ee(m.createdAt)})]},m.id)),i.length>Mt&&jsxRuntime.jsxs("p",{className:"pt-1 text-xs text-muted-foreground",children:["Showing ",Mt," of ",i.length," entries"]})]})]})]})}var lo=[{id:"buy",label:"Buy"},{id:"use",label:"Use"},{id:"keys",label:"Keys"}];function He({baseHref:e}){return jsxRuntime.jsx("div",{className:"flex gap-1 rounded-2xl bg-muted/50 p-1.5 mb-6",children:lo.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 co({getKeyHref:e="/keys/get",showTabs:t=true,className:r,style:n}){let{keys:l,totalBalance:a,loading:s,error:o,refresh:i}=te();return s?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:n,children:[t&&e&&jsxRuntime.jsx(He,{baseHref:e}),jsxRuntime.jsx(he,{count:3})]}):o?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:n,children:[t&&e&&jsxRuntime.jsx(He,{baseHref:e}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 py-12",children:[jsxRuntime.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 px-6 py-5 text-center max-w-sm",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o})]}),jsxRuntime.jsx("button",{onClick:()=>i(),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Try again"})]})]}):l.length===0?jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:n,children:[t&&e&&jsxRuntime.jsx(He,{baseHref:e}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 rounded-lg border border-dashed py-12",children:[jsxRuntime.jsx(lucideReact.KeyRound,{className:"h-10 w-10 text-muted-foreground"}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys yet"}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:"Get your first node key to start earning."})]}),e&&jsxRuntime.jsx("a",{href:e,className:"rounded-lg bg-foreground px-4 py-2 text-sm font-medium text-background transition-colors hover:bg-foreground/90",children:"Get a Key"})]})]}):jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:n,children:[t&&e&&jsxRuntime.jsx(He,{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: ",F(a)]}),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(Ft,{nodeKey:d},d.id))]})}function go({nodeKey:e,selected:t,onSelect:r}){return jsxRuntime.jsxs("button",{onClick:r,className:f("flex w-full items-start gap-3 rounded-xl border p-4 text-left transition-all",t?"border-foreground/30 bg-foreground/5 ring-1 ring-foreground/10":"border-border hover:border-foreground/20"),children:[jsxRuntime.jsx("div",{className:f("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors",t?"border-foreground bg-foreground":"border-muted-foreground/40"),children:t&&jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 text-background"})}),jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-foreground",children:[e.keyIndex?`#${e.keyIndex} `:"",e.label||e.id.slice(0,16)]}),jsxRuntime.jsx("span",{className:"text-xs font-medium capitalize text-green-500",children:e.status})]}),jsxRuntime.jsx(oe,{current:e.tokenBalance,max:e.maxTokens,className:"mt-2"})]})]})}function yo({className:e,style:t}){let{keys:r,loading:n}=te(),{transferKey:l,transferring:a,result:s,error:o}=Ee(),[i,d]=jn.useState(null),[c,u]=jn.useState(""),[p,m]=jn.useState(false),g=r.filter(w=>w.status==="active"),y=g.find(w=>w.id===i),b=y&&c.trim()===y.userId,h=i&&c.trim().length>0&&p&&!b&&!a,E=async()=>{!i||!c.trim()||await l(i,c.trim());},M=()=>{d(null),u(""),m(false);};return s?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center gap-4 py-8",e),style:t,children:[jsxRuntime.jsx(lucideReact.CheckCircle,{className:"h-12 w-12 text-green-500"}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Transfer Complete"}),jsxRuntime.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Key transferred successfully"})]}),jsxRuntime.jsxs("div",{className:"w-full max-w-sm space-y-2 rounded-xl border border-border bg-muted/30 p-4 text-sm",children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Key"}),jsxRuntime.jsxs("span",{className:"font-mono text-foreground",children:[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:f("space-y-5",e),style:t,children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"mb-3 text-sm font-medium text-foreground",children:"Select Key to Transfer"}),n?jsxRuntime.jsx(he,{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(w=>jsxRuntime.jsx(go,{nodeKey:w,selected:i===w.id,onSelect:()=>d(w.id)},w.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:c,onChange:w=>{u(w.target.value),m(false);},placeholder:"Enter recipient's user ID or global ID",className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:border-foreground/30 focus:outline-none focus:ring-1 focus:ring-foreground/10"}),b&&jsxRuntime.jsx("p",{className:"mt-1.5 text-xs text-red-500",children:"Cannot transfer a key to yourself"})]}),y&&c.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)})," ","(",F(y.tokenBalance)," tokens) to"," ",jsxRuntime.jsxs("span",{className:"font-mono font-medium",children:[c.trim().slice(0,20),"..."]})]})]}),jsxRuntime.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:p,onChange:w=>m(w.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:E,disabled:!h,className:f("flex w-full items-center justify-center gap-2 rounded-lg px-4 py-3 text-sm font-medium transition-all",h?"bg-foreground text-background hover:opacity-90":"bg-muted text-muted-foreground cursor-not-allowed"),children:a?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 ho(e){return e.status==="active"}function ko({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 vo({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:[F(r)," / ",F(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 No({onSelect:e,className:t,style:r}){let{keys:n,loading:l,error:a,refresh:s}=te();if(l)return jsxRuntime.jsx("div",{className:f("space-y-3",t),style:r,children:jsxRuntime.jsx(ko,{count:3})});if(a)return jsxRuntime.jsx("div",{className:f("space-y-3",t),style:r,children:jsxRuntime.jsxs("div",{className:"bg-muted/30 p-5 text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"Unable to load your keys"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a}),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 o=n.filter(ho);return o.length===0?jsxRuntime.jsxs("div",{className:f("flex flex-col items-center justify-center gap-3 bg-muted/20 py-16",t),style:r,children:[jsxRuntime.jsx(lucideReact.FileText,{className:"h-10 w-10 text-muted-foreground","aria-hidden":true}),jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-foreground",children:"No keys with pending paperwork"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Run a node to earn Paper, then return here to file."})]})]}):jsxRuntime.jsx("div",{className:f("space-y-2",t),style:r,children:o.map(i=>jsxRuntime.jsx(vo,{nodeKey:i,onSelect:()=>e(i.id)},i.id))})}function Pr({label:e,sub:t,icon:r,selected:n,enabled:l,disabledLabel:a,onClick:s}){let o=l;return jsxRuntime.jsxs("button",{type:"button",onClick:o?s:void 0,disabled:!o,"aria-disabled":!o,className:f("flex flex-col items-start gap-1 rounded-xl border p-4 text-left transition-colors",o?n?"border-foreground bg-foreground/5 cursor-pointer":"border-border hover:bg-muted/50 cursor-pointer":"border-border bg-muted/20 cursor-not-allowed opacity-70"),children:[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:f("flex h-7 w-7 items-center justify-center rounded-md",n&&l?"bg-foreground text-background":"bg-muted text-foreground"),children:r}),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:f("text-xs",l?"text-muted-foreground":"text-muted-foreground/80"),children:l?t:a??t})]})}function So({caps:e,value:t,onChange:r,className:n,disabled:l=false}){let a=e.stripe.enabled&&!l,s=e.usdc.enabled&&!l,o=`disabled by ${e.stackName} stack`,i=`disabled by ${e.stackName} stack`;return jsxRuntime.jsxs("div",{className:f("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(Pr,{label:"USDC",sub:"On-chain payout to your stack address",icon:jsxRuntime.jsx(lucideReact.Wallet,{className:"h-4 w-4"}),selected:t==="usdc",enabled:s,disabledLabel:i,onClick:()=>r("usdc")}),jsxRuntime.jsx(Pr,{label:"Stripe",sub:"USD payout to your bank via Stripe",icon:jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-4 w-4"}),selected:t==="stripe",enabled:a,disabledLabel:o,onClick:()=>r("stripe")})]})]})}function Oe({ok:e,label:t}){return jsxRuntime.jsxs("span",{className:f("inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-[11px] font-medium",e?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"),children:[e?jsxRuntime.jsx(lucideReact.CheckCircle2,{className:"h-3 w-3"}):jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-3 w-3"}),t]})}function Rr({active:e,onClick:t,icon:r,label:n,sub:l}){return jsxRuntime.jsxs("button",{type:"button",onClick:t,className:f("flex flex-1 items-start gap-3 rounded-xl border p-4 text-left transition-colors",e?"border-foreground bg-foreground/5":"border-border hover:bg-muted/40"),children:[jsxRuntime.jsx("span",{className:f("flex h-8 w-8 shrink-0 items-center justify-center rounded-md",e?"bg-foreground text-background":"bg-muted text-foreground"),children:r}),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 Mo({stackId:e,onChange:t,className:r,style:n}){let{account:l,loading:a,error:s,refresh:o,disconnect:i,disconnecting:d}=Ue(e),{caps:c,loading:u}=ut(e),{startStripeConnect:p,starting:m,error:g}=gt(e),{connectAndVerify:y,connecting:b,error:h}=yt(),E=!!c?.stripe.enabled,M=l?.method??null,[w,H]=jn.useState(M??"solana");jn.useEffect(()=>{M?H(M):!E&&w==="stripe"&&H("solana");},[M,E,w]);let D=async()=>{await p(),t?.();},K=async()=>{await y()&&(await o(),t?.());},z=async()=>{await i(M==="stripe"?e:void 0)&&t?.();};if(a||u)return jsxRuntime.jsxs("div",{className:f("space-y-3",r),style:n,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(s)return jsxRuntime.jsxs("div",{className:f("space-y-3",r),style:n,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:()=>o(),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 q=l?.solana,O=l?.stripe,W=E||M==="stripe";return jsxRuntime.jsxs("div",{className:f("space-y-4",r),style:n,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."})]}),M&&jsxRuntime.jsxs("button",{type:"button",onClick:z,disabled:d,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"}),d?"disconnecting\u2026":"disconnect"]})]}),W&&jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx(Rr,{active:w==="solana",onClick:()=>H("solana"),icon:jsxRuntime.jsx(lucideReact.Wallet,{className:"h-4 w-4"}),label:"Crypto (Solana)",sub:"Connect a wallet, sign once"}),jsxRuntime.jsx(Rr,{active:w==="stripe",onClick:()=>H("stripe"),icon:jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-4 w-4"}),label:"Bank (Stripe)",sub:"Stripe-hosted onboarding"})]}),w==="solana"&&jsxRuntime.jsx("div",{className:"space-y-3 rounded-xl border border-border p-4",children:q?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(Oe,{ok:true,label:"verified"})]}),jsxRuntime.jsx("code",{className:"block text-xs text-foreground break-all",children:q.address}),jsxRuntime.jsxs("p",{className:"text-xs text-muted-foreground",children:["You signed a server-issued nonce on ",new Date(q.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."}),h&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:h}),jsxRuntime.jsxs("button",{type:"button",onClick:K,disabled:b,className:f("inline-flex items-center gap-2 rounded-md bg-foreground text-background px-4 py-2 text-sm font-semibold transition-colors","hover:bg-foreground/90 disabled:opacity-50 disabled:cursor-not-allowed"),children:[jsxRuntime.jsx(lucideReact.Wallet,{className:"h-4 w-4"}),b?"Waiting for signature\u2026":"Connect Phantom & sign"]})]})}),w==="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(Oe,{ok:O.detailsSubmitted,label:"details"}),jsxRuntime.jsx(Oe,{ok:O.chargesEnabled,label:"charges"}),jsxRuntime.jsx(Oe,{ok:O.payoutsEnabled,label:"payouts"})]}),O.pendingOnboardingUrl&&jsxRuntime.jsxs("a",{href:_(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."}),g&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:g}),jsxRuntime.jsxs("button",{type:"button",onClick:D,disabled:m,className:f("inline-flex items-center gap-2 rounded-md bg-foreground text-background px-4 py-2 text-sm font-semibold transition-colors","hover:bg-foreground/90 disabled:opacity-50 disabled:cursor-not-allowed"),children:[jsxRuntime.jsx(lucideReact.CreditCard,{className:"h-4 w-4"}),m?"Opening Stripe\u2026":"Connect with Stripe"]})]})})]})}
|
|
2
|
+
exports.ASCII_KEY_ART=je;exports.BottomSheet=Fe;exports.BuyKeyWidget=Js;exports.BuyPanel=Nt;exports.DefaultKeyArt=St;exports.FilePaperworkList=No;exports.FilePaperworkView=Et;exports.FilingDetailView=It;exports.FilingTracker=Rt;exports.KNOWN_PAYMENT_METHODS=We;exports.KeyBalanceBar=oe;exports.KeyCard=Ft;exports.KeyDetailView=Ut;exports.KeyList=co;exports.KeyUtilsProvider=Ge;exports.KeysPanel=Kt;exports.MAX_ERROR_LEN=Ur;exports.MintSuccess=kt;exports.PAYMENT_METHOD_META=Ve;exports.PayoutAccountPanel=Mo;exports.PayoutMethodPicker=So;exports.SellPanel=Zs;exports.SolanaPayButton=ht;exports.TRACKER_LABELS=Ye;exports.TRACKER_VERBS=Re;exports.TransferPanel=yo;exports.TypingText=Tt;exports.UsePanel=wt;exports.calculateBalancePercentage=Ht;exports.clampErrorMessage=Dt;exports.cn=f;exports.createKeyClient=Jr;exports.csrfHeaders=j;exports.currentState=_t;exports.deriveTrackerStates=qe;exports.detectPlatform=Wt;exports.formatDate=ee;exports.formatPaperUsd=Ae;exports.formatTokens=F;exports.getBalanceColor=Ot;exports.hasFailed=jt;exports.isAllDone=$t;exports.isCryptoPaymentMethod=Kr;exports.paymentMethodLabel=Se;exports.pickHeadline=Je;exports.readErrorMessage=C;exports.safeUrl=_;exports.supportedPaymentMethods=ze;exports.useCryptoConnect=yt;exports.useFilePaperwork=lt;exports.useFilingDetail=ft;exports.useFilingHistory=fn;exports.useKeyLedger=Te;exports.useKeyUtilsContext=k;exports.useKeys=te;exports.useListKey=Ie;exports.useMintKey=nt;exports.usePayoutAccount=Ue;exports.usePricing=Xe;exports.useSolanaPayment=sn;exports.useStackPayoutCapabilities=ut;exports.useStripeCheckout=ot;exports.useStripeConnect=gt;exports.useTransferKey=Ee;exports.useUserStripeStacks=Rn;
|