import{vV as x,wV as d}from"./cli-0.5.12-f5pfjvdk.mjs";import{IX as y,JX as g}from"./cli-0.5.12-fqp5s15p.mjs";import{EZ as S}from"./cli-0.5.12-w3hy6c60.mjs";import{SZ as w,UZ as F,ZZ as t}from"./cli-0.5.12-khvy67r3.mjs";import{K3 as m,N3 as W,Q3 as b,d4 as s}from"./cli-0.5.12-pycnjaeg.mjs";import{Bca as E,Jaa as f,Jca as r,Maa as L,eba as n,gaa as P,haa as i}from"./cli-0.5.12-g4wb8mj2.mjs";import{bfa as A,cfa as a}from"./cli-0.5.12-k1crwtdc.mjs";import{fga as G,iga as u}from"./cli-0.5.12-p5ps8gf0.mjs";import{Dna as o,lna as U}from"./cli-0.5.12-495d826j.mjs";import{Yna as k,aoa as K}from"./cli-0.5.12-xzeb7mtb.mjs";function v(z,N,J){let Q=Z.useRef(0),V=Z.useRef(void 0),X=Z.useCallback(()=>{if(V.current)clearTimeout(V.current),V.current=void 0},[]);return Z.useEffect(()=>{return()=>{X()}},[X]),Z.useCallback(()=>{let Y=Date.now();if(Y-Q.current<=T&&V.current!==void 0)X(),z(!1),N();else J?.(),z(!0),X(),V.current=setTimeout((j,H)=>{j(!1),H.current=void 0},T,z,V);Q.current=Y},[z,N,J,X])}var Z,T=800;var R=K(()=>{Z=k(S(),1)});function C(z,N,J,Q=!0){let{exit:V}=y(),[X,Y]=$.useState({pending:!1,keyName:null}),q=$.useMemo(()=>J??V,[J,V]),M=v((_)=>Y({pending:_,keyName:"Ctrl-C"}),q),j=v((_)=>Y({pending:_,keyName:"Ctrl-D"}),q),H=$.useCallback(()=>{if(N?.())return;M()},[M,N]),O=$.useCallback(()=>{j()},[j]),c=$.useMemo(()=>({"app:interrupt":H,"app:exit":O}),[H,O]);return z(c,{context:"Global",isActive:Q}),X}var $;var I=K(()=>{g();R();$=k(S(),1)});function Gz(z,N,J){return C(x,N,z,J)}var l=K(()=>{d();I()});async function e(z="claude_code_guest_pass"){let{accessToken:N,orgUUID:J}=await w(),Q={...F(N),"x-organization-uuid":J},V=`${A().BASE_API_URL}/api/oauth/organizations/${J}/referral/eligibility`;return(await U.get(V,{headers:Q,params:{campaign:z},timeout:5000})).data}async function vz(z="claude_code_guest_pass"){let{accessToken:N,orgUUID:J}=await w(),Q={...F(N),"x-organization-uuid":J},V=`${A().BASE_API_URL}/api/oauth/organizations/${J}/referral/redemptions`;return(await U.get(V,{headers:Q,params:{campaign:z},timeout:1e4})).data}function p(){return!!(W()?.organizationUuid&&m()&&b()==="max")}function Az(){if(!p())return{eligible:!1,needsRefresh:!1,hasCache:!1};let z=W()?.organizationUuid;if(!z)return{eligible:!1,needsRefresh:!1,hasCache:!1};let J=L().passesEligibilityCache?.[z];if(!J)return{eligible:!1,needsRefresh:!0,hasCache:!1};let{eligible:Q,timestamp:V}=J,Y=Date.now()-V>h;return{eligible:Q,needsRefresh:Y,hasCache:!0}}function Uz(z){let N=zz[z.currency]??`${z.currency} `,J=z.amount_minor_units/100,Q=J%1===0?J.toString():J.toFixed(2);return`${N}${Q}`}function wz(){let z=W()?.organizationUuid;if(!z)return null;return L().passesEligibilityCache?.[z]?.referrer_reward??null}function Fz(){let z=W()?.organizationUuid;if(!z)return null;return L().passesEligibilityCache?.[z]?.remaining_passes??null}async function D(){if(B)return G("Passes: Reusing in-flight eligibility fetch"),B;let z=W()?.organizationUuid;if(!z)return null;return B=(async()=>{try{let N=await e(),J={...N,timestamp:Date.now()};return f((Q)=>({...Q,passesEligibilityCache:{...Q.passesEligibilityCache,[z]:J}})),G(`Passes eligibility cached for org ${z}: ${N.eligible}`),N}catch(N){return G("Failed to fetch and cache passes eligibility"),E(N),null}finally{B=null}})(),B}async function Jz(){if(!p())return null;let z=W()?.organizationUuid;if(!z)return null;let J=L().passesEligibilityCache?.[z],Q=Date.now();if(!J)return G("Passes: No cache, fetching eligibility in background (command unavailable this session)"),D(),null;if(Q-J.timestamp>h){G("Passes: Cache stale, returning cached data and refreshing in background"),D();let{timestamp:Y,...q}=J;return q}G("Passes: Using fresh cached eligibility data");let{timestamp:V,...X}=J;return X}async function Oz(){if(P())return;Jz()}var h=86400000,B=null,zz;var Nz=K(()=>{o();a();s();n();u();r();i();t();zz={USD:"$",EUR:"€",GBP:"£",BRL:"R$",CAD:"CA$",AUD:"A$",NZD:"NZ$",SGD:"S$"}});
export{v as sU,R as tU,Gz as uU,l as vU,vz as wU,Az as xU,Uz as yU,wz as zU,Fz as AU,Jz as BU,Oz as CU,Nz as DU};
