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,on as o,yc as s}from"./paths-Ci1iwL5Y.js";import{l as c,u as l}from"./oauth-CdZEzMww.js";import{d as u,f as d,o as f,s as p}from"./log-DSV4Ht5l.js";import{a as m,l as h,o as g}from"./api-CDmgYrwN.js";async function _(){try{let{accessToken:e,orgUUID:n}=await h(),r=`${c().BASE_API_URL}/api/oauth/organizations/${n}/overage_credit_grant`;return(await t.get(r,{headers:m(e)})).data}catch(e){return p(e),null}}function v(){let e=i()?.organizationUuid;if(!e)return null;let t=a().overageCreditGrantCache?.[e];return!t||Date.now()-t.timestamp>S?null:t.info}function y(){let e=i()?.organizationUuid;if(!e)return;let t=a().overageCreditGrantCache;!t||!(e in t)||r(t=>{let n={...t.overageCreditGrantCache};return delete n[e],{...t,overageCreditGrantCache:n}})}async function b(){if(d())return;let e=i()?.organizationUuid;if(!e)return;let t=await _();t&&r(n=>{let r=n.overageCreditGrantCache?.[e],i=r?.info,a=i&&i.available===t.available&&i.eligible===t.eligible&&i.granted===t.granted&&i.amount_minor_units===t.amount_minor_units&&i.currency===t.currency;if(a&&r&&Date.now()-r.timestamp<=S)return n;let o={info:a?i:t,timestamp:Date.now()};return{...n,overageCreditGrantCache:{...n.overageCreditGrantCache,[e]:o}}})}function x(e){if(e.amount_minor_units==null||!e.currency)return null;if(e.currency.toUpperCase()===`USD`){let t=e.amount_minor_units/100;return Number.isInteger(t)?`$${t}`:`$${t.toFixed(2)}`}return null}var S,C=e((()=>{n(),l(),o(),s(),f(),u(),g(),S=3600*1e3}));export{b as a,y as i,v as n,C as r,x as t};