import{a as e,n as t,t as n}from"./jsx-runtime-CutOxEx1.js";import{n as r}from"./promoTokenEvents-DnQDjS5Z.js";var i=e(t(),1),a=n(),o=new Intl.NumberFormat(`zh-CN`),s=(...e)=>{for(let t of e){let e=Number(t);if(Number.isFinite(e)&&e>=0)return e}},c=(...e)=>{for(let t of e){let e=String(t||``).trim();if(e)return e}return``},l=e=>e==null||!Number.isFinite(e)?``:e.toFixed(2).replace(/\.00$/g,``).replace(/(\.\d)0$/g,`$1`),u=e=>{if(!e)return[];let t=e.usage||e.totalUsage||{},n=s(e.promptTokens,t.prompt_tokens,t.input_tokens,t.inputTokens,t.totalInputTokens),r=s(e.completionTokens,t.completion_tokens,t.output_tokens,t.outputTokens,t.totalOutputTokens),i=s(e.totalTokens,t.total_tokens,t.totalTokens,n!=null||r!=null?Number(n||0)+Number(r||0):void 0),a=[];return n!=null&&n>0&&a.push(`输入 ${o.format(Math.round(n))} token`),r!=null&&r>0&&a.push(`输出 ${o.format(Math.round(r))} token`),i!=null&&i>0&&a.push(`合计 ${o.format(Math.round(i))} token`),a},d=e=>{if(!e)return``;let t=e.billing||{},n=e.usage||e.totalUsage||{};if(e.memberCovered===!0||n.memberCovered===!0||n.member_covered===!0||t.memberCovered===!0||t.member_covered===!0)return`会员覆盖`;let r=e.promoCovered===!0||n.promoCovered===!0||n.promo_covered===!0||t.promoCovered===!0||t.promo_covered===!0,i=c(e.promoLabel,n.promoLabel,n.promo_label,t.promoLabel,t.promo_label)||`体验Token`,a=s(e.promoTokensCharged,n.promoTokensCharged,n.promo_tokens_charged,t.promoTokensCharged,t.promo_tokens_charged),u=s(e.promoTokensRemaining,n.promoTokensRemaining,n.promo_tokens_remaining,t.promoTokensRemaining,t.promo_tokens_remaining);if(r&&a!=null&&a>0)return`${i} ${o.format(Math.round(a))} Token${u==null?``:`，剩余 ${o.format(Math.round(u))}`}`;let d=s(e.recognitionPromoPointsCharged,n.recognition_promo_points_charged,n.recognitionPromoPointsCharged,t.recognitionPromoPointsCharged,t.recognition_promo_points_charged,n.recognition_promo_point_cents_charged==null?void 0:Number(n.recognition_promo_point_cents_charged)/100);if(d!=null&&d>0)return`${c(e.recognitionPromoLabel,n.recognition_promo_label,n.recognitionPromoLabel,t.recognitionPromoLabel,t.recognition_promo_label)||`618 识别体验积分`}抵扣 ${l(d)} 积分`;let f=s(e.pointsCharged,n.pointsCharged,n.points_charged,t.pointsCharged,t.points_charged);if(f!=null&&f>0)return`消耗 ${l(f)} 积分`;let p=s(n.pointsCalculated,n.points_calculated,t.pointsCalculated,t.points_calculated);return p!=null&&p>0?`计费 ${l(p)} 积分`:``},f=e=>{if(!e)return;let t=e.billing||{},n=e.usage||e.totalUsage||{};return s(e.promoTokensRemaining,n.promoTokensRemaining,n.promo_tokens_remaining,t.promoTokensRemaining,t.promo_tokens_remaining)},p=e=>{if(!e)return``;let t=e.billing||{},n=e.usage||e.totalUsage||{};return c(e.promoLabel,n.promoLabel,n.promo_label,t.promoLabel,t.promo_label)},m=e=>{if(!e)return[];let t=s(e.pages),n=s(e.displayPoints,e.costCents==null?void 0:Number(e.costCents)/100),r=s(e.pointsPerPage,t&&n!=null?n/t:void 0),i=[];t!=null&&t>0&&i.push(`PDF识别 ${Math.round(t)}页`),r!=null&&r>0&&i.push(`${l(r)}积分/页`),n!=null&&n>0&&i.push(`合计 ${l(n)}积分`);let a=s(e.billedPoints);a!=null&&n!=null&&Math.abs(a-n)>.001&&i.push(`账务记录 ${l(a)}积分`);let u=s(e.promoTokensCharged);if(e.promoCovered&&u!=null&&u>0){let t=c(e.promoLabel)||`体验Token`,n=s(e.promoTokensRemaining);i.push(`${t} ${o.format(Math.round(u))} Token${n==null?``:`，剩余 ${o.format(Math.round(n))}`}`)}let d=s(e.recognitionPromoPointsCharged,e.recognitionPromoPointCentsCharged==null?void 0:Number(e.recognitionPromoPointCentsCharged)/100);if(d!=null&&d>0){let t=c(e.recognitionPromoLabel)||`618 识别体验积分`,n=s(e.recognitionPromoPointsRemaining,e.recognitionPromoPointCentsRemaining==null?void 0:Number(e.recognitionPromoPointCentsRemaining)/100);i.push(`${t}抵扣 ${l(d)} 积分${n==null?``:`，剩余 ${l(n)}`}`)}return e.recognitionPromoNotice&&i.push(e.recognitionPromoNotice),i};function h({usage:e,pdfBilling:t,compact:n}){let o=t?s(t.promoTokensRemaining):f(e),l=t?c(t.promoLabel):p(e);(0,i.useEffect)(()=>{o!=null&&r({remainingTokens:o,label:l||void 0})},[o,l]);let h=t?m(t):[...u(e),d(e)].filter(Boolean);return h.length?(0,a.jsx)(`div`,{className:`hr-usage-badge${n?` hr-usage-badge--compact`:``}`,"aria-label":`用量和计费`,children:h.map(e=>(0,a.jsx)(`span`,{children:e},e))}):null}export{h as t};