import{i as e}from"./chunk-B3pr0VN8.js";import{n as t,t as n}from"./jsx-runtime-wTfS3W87.js";import{r}from"./authSession-CrP9lMPq.js";import{r as i}from"./billing-DcgqA98_.js";import{t as a}from"./promoTokenEvents-D_UTsplE.js";var o=e(t(),1),s=n(),c=1440*60*1e3,l=(...e)=>{for(let t of e){let e=Number(t);if(Number.isFinite(e)&&e>=0)return e}return null},u=(...e)=>{for(let t of e){let e=String(t||``).trim();if(e)return e}return``},d=e=>{if(!e)return!1;let t=Date.parse(e);return Number.isFinite(t)&&t<=Date.now()},f=e=>{let t=Math.max(0,Math.round(Number(e||0)));return t>=1e8?`${(t/1e8).toLocaleString(`zh-CN`,{maximumFractionDigits:1})}亿`:t>=1e4?`${(t/1e4).toLocaleString(`zh-CN`,{maximumFractionDigits:+(t>=1e6)})}万`:t.toLocaleString(`zh-CN`)},p=e=>Math.max(0,Math.round(Number(e||0))).toLocaleString(`zh-CN`),m=e=>{if(!e)return``;let t=Date.parse(e);if(!Number.isFinite(t))return``;let n=Math.ceil((t-Date.now())/c);return n<=0?`今日到期`:n===1?`明日到期`:`剩余 ${n} 天`},h=(e,t)=>{let n=e||{},r=n.active||{};if(t&&r.audience!==t)return null;let i=l(r.remainingTokens,r.remaining_tokens),a=l(r.totalTokens,r.total_tokens),o=u(r.expiresAt,r.expires_at)||null;if(i==null||a==null||i<=0||a<=0||d(o))return null;let s=u(r.campaignCode,r.campaign_code,n.campaign?.code);return{kind:`promo`,label:/618/i.test(s)?`618体验额度`:`体验额度`,roleLabel:r.audience===`recruiter`?`AI招聘`:`AI求职`,totalTokens:a,remainingTokens:i,expiresAt:o}},g=(e,t)=>!e||e.ok!==!0?null:h(e.promo,t)||null;function _({variant:e=`default`,audience:t=null}){let[n,c]=(0,o.useState)(null),u=(0,o.useRef)(!1),d=(0,o.useRef)(0),h=(0,o.useRef)(0),_=(0,o.useCallback)(async(e=`event`)=>{let n=Date.now(),a=e===`focus`?1800:500;if(u.current||n-d.current<a)return;u.current=!0,d.current=n;let o=++h.current;try{if(!(await r())?.token){o===h.current&&c(null);return}let e=await i(t?{promoAudience:t}:void 0);o===h.current&&c(g(e,t))}catch{o===h.current&&c(null)}finally{u.current=!1}},[t]);if((0,o.useEffect)(()=>{_(`mount`);let e=()=>{_(`focus`)},t=()=>{_(`event`)},n=e=>{let t=e?.detail||{},n=l(t.remainingTokens,t.remaining_tokens);n!=null&&c(e=>e&&{...e,remainingTokens:n}),_(`event`)};try{window.addEventListener(`focus`,e)}catch{}try{window.addEventListener(`pageshow`,e)}catch{}try{window.addEventListener(`AUTH_SESSION_UPDATED_WEB`,t)}catch{}try{window.addEventListener(a,n)}catch{}return()=>{try{window.removeEventListener(`focus`,e)}catch{}try{window.removeEventListener(`pageshow`,e)}catch{}try{window.removeEventListener(`AUTH_SESSION_UPDATED_WEB`,t)}catch{}try{window.removeEventListener(a,n)}catch{}}},[_]),!n)return null;let v=Math.max(0,n.remainingTokens),y=Math.max(1,n.totalTokens),b=Math.max(0,y-v),x=Math.max(0,Math.min(100,v/y*100)),S=m(n.expiresAt);return(0,s.jsxs)(`div`,{className:[`promo-token-quota-bar`,e===`biz`?`promo-token-quota-bar--biz`:``].filter(Boolean).join(` `),style:{"--promo-token-quota-progress":`${x}%`},"aria-label":`Token 体验额度`,children:[(0,s.jsxs)(`div`,{className:`promo-token-quota-main`,children:[(0,s.jsxs)(`div`,{className:`promo-token-quota-title-row`,children:[(0,s.jsx)(`span`,{className:`promo-token-quota-label`,children:n.label}),n.roleLabel?(0,s.jsx)(`span`,{className:`promo-token-quota-chip`,children:n.roleLabel}):null,S?(0,s.jsx)(`span`,{className:`promo-token-quota-expiry`,children:S}):null]}),(0,s.jsxs)(`div`,{className:`promo-token-quota-meta`,title:`剩余 ${p(v)} / ${p(y)} Token`,children:[`剩余 `,f(v),` / `,f(y),` Token`]})]}),(0,s.jsxs)(`div`,{className:`promo-token-quota-side`,children:[(0,s.jsx)(`div`,{className:`promo-token-quota-track`,"aria-hidden":`true`,children:(0,s.jsx)(`span`,{className:`promo-token-quota-fill`})}),(0,s.jsxs)(`div`,{className:`promo-token-quota-sub`,children:[`已用 `,f(b)]})]}),(0,s.jsx)(`a`,{className:`promo-token-quota-link`,href:`/me?tab=billing`,target:`_blank`,rel:`noopener noreferrer`,children:`查看明细`})]})}export{_ as t};