import{n as e}from"./chunk-DR8-3Aex.js";import{n as t,t as n}from"./axios-DhfaybwJ.js";import{Cc as r,Zt as i,dc as a,dn as o,on as s,tn as c,yc as l}from"./paths-Ci1iwL5Y.js";import{l as u,p as d}from"./debug-otxXY3j-.js";import{l as f,u as p}from"./oauth-CdZEzMww.js";import{d as m,f as h,o as g,s as _}from"./log-DSV4Ht5l.js";import{a as v,l as y,o as b}from"./api-CDmgYrwN.js";async function x(e=`claude_code_guest_pass`){let{accessToken:n,orgUUID:r}=await y(),i={...v(n),"x-organization-uuid":r},a=`${f().BASE_API_URL}/api/oauth/organizations/${r}/referral/eligibility`;return(await t.get(a,{headers:i,params:{campaign:e},timeout:5e3})).data}async function S(e=`claude_code_guest_pass`){let{accessToken:n,orgUUID:r}=await y(),i={...v(n),"x-organization-uuid":r},a=`${f().BASE_API_URL}/api/oauth/organizations/${r}/referral/redemptions`;return(await t.get(a,{headers:i,params:{campaign:e},timeout:1e4})).data}function C(){return!!(i()?.organizationUuid&&o()&&c()===`max`)}function w(){if(!C())return{eligible:!1,needsRefresh:!1,hasCache:!1};let e=i()?.organizationUuid;if(!e)return{eligible:!1,needsRefresh:!1,hasCache:!1};let t=a().passesEligibilityCache?.[e];if(!t)return{eligible:!1,needsRefresh:!0,hasCache:!1};let{eligible:n,timestamp:r}=t;return{eligible:n,needsRefresh:Date.now()-r>j,hasCache:!0}}function T(e){let t=N[e.currency]??`${e.currency} `,n=e.amount_minor_units/100;return`${t}${n%1==0?n.toString():n.toFixed(2)}`}function E(){let e=i()?.organizationUuid;return e?a().passesEligibilityCache?.[e]?.referrer_reward??null:null}function D(){let e=i()?.organizationUuid;return e?a().passesEligibilityCache?.[e]?.remaining_passes??null:null}async function O(){if(M)return d(`Passes: Reusing in-flight eligibility fetch`),M;let e=i()?.organizationUuid;return e?(M=(async()=>{try{let t=await x(),n={...t,timestamp:Date.now()};return r(t=>({...t,passesEligibilityCache:{...t.passesEligibilityCache,[e]:n}})),d(`Passes eligibility cached for org ${e}: ${t.eligible}`),t}catch(e){return d(`Failed to fetch and cache passes eligibility`),_(e),null}finally{M=null}})(),M):null}async function k(){if(!C())return null;let e=i()?.organizationUuid;if(!e)return null;let t=a().passesEligibilityCache?.[e],n=Date.now();if(!t)return d(`Passes: No cache, fetching eligibility in background (command unavailable this session)`),O(),null;if(n-t.timestamp>j){d(`Passes: Cache stale, returning cached data and refreshing in background`),O();let{timestamp:e,...n}=t;return n}d(`Passes: Using fresh cached eligibility data`);let{timestamp:r,...o}=t;return o}async function A(){h()||k()}var j,M,N,P=e((()=>{n(),p(),s(),l(),u(),g(),m(),b(),j=1440*60*1e3,M=null,N={USD:`$`,EUR:`€`,GBP:`£`,BRL:`R$`,CAD:`CA$`,AUD:`A$`,NZD:`NZ$`,SGD:`S$`}}));export{E as a,A as c,k as i,S as n,D as o,T as r,P as s,w as t};