import{s as e}from"./chunk-Bj-mKKzh.js";import{n as t}from"./jsx-runtime-CiQ1k8xo.js";import{n}from"./vscode-api-DjORcpSo.js";import{n as r}from"./react-0SBwfqBm.js";import{c as i,r as a}from"./lib-MoKmYgcO.js";import{t as o}from"./persisted-atom-D9Fx3rWR.js";import{t as s}from"./use-is-remote-host-CH9dfL3P.js";var c=e(t(),1),l=a({bodyPersonalized:{id:`codex.fastModeHomeBanner.body.personalized`,defaultMessage:`Based on your work last week across {threadCountLabel}, Fast could have saved about {duration}. Increased plan usage.`,description:`Personalized body shown in the Fast mode home banner`},threadCountOne:{id:`codex.fastModeHomeBanner.threadCount.one`,defaultMessage:`{count} chat`,description:`Thread count label used in the Fast mode home banner for a single thread`},threadCountOther:{id:`codex.fastModeHomeBanner.threadCount.other`,defaultMessage:`{count} chats`,description:`Thread count label used in the Fast mode home banner for multiple threads`},durationHoursLabel:{id:`codex.fastModeHomeBanner.duration.hoursLabel`,defaultMessage:`{hours, plural, one {# hour} other {# hours}}`,description:`Hours label used in the Fast mode home banner duration`},durationMinutesLabel:{id:`codex.fastModeHomeBanner.duration.minutesLabel`,defaultMessage:`{minutes, plural, one {# minute} other {# minutes}}`,description:`Minutes label used in the Fast mode home banner duration`},durationHoursAndMinutes:{id:`codex.fastModeHomeBanner.duration.hoursAndMinutes`,defaultMessage:`{hoursLabel} {minutesLabel}`,description:`Duration label used in the Fast mode home banner when hours and minutes are both present`}}),u=45*6e4,d=10080*60*1e3,f=128,p=3600*1e3,m=3600*1e3,h=1440*60*1e3,g=o(`fast-mode-personalized-estimate`,null);function _(e,t=Date.now()){return t-e<=h}var v={failedAtMs:null,inFlight:null,lastStartedBucket:null};function y(e=Date.now()){return Math.floor(e/p)}function b(e){let t=i(),a=s(),[o,l]=r(g),[p,h]=(0,c.useState)(null),[b,C]=(0,c.useState)(`idle`),w=(0,c.useRef)(o);(0,c.useEffect)(()=>{w.current=o},[o]),(0,c.useEffect)(()=>{if(!e||a){h(null),C(`idle`);return}let t=w.current,r=t!=null;h(t),C(r?`ready`:`idle`);let i=Date.now(),o=y(i);if(v.inFlight!=null||v.lastStartedBucket===o||v.failedAtMs!=null&&i-v.failedAtMs<m)return;let s=!1;return v.lastStartedBucket=o,v.inFlight=(async()=>{try{let e=await n(`fast-mode-rollout-metrics`,{params:{startTimeMs:Date.now()-d,maxRollouts:f}});if(e==null)return;l({estimatedSavedMs:e.estimatedSavedMs,rolloutCountWithCompletedTurns:e.rolloutCountWithCompletedTurns,computedAtMs:Date.now()}),v.failedAtMs=null}catch{v.failedAtMs=Date.now(),!s&&!r&&C(`failed`)}finally{v.inFlight=null}})(),()=>{s=!0}},[e,a,l]);let T=(0,c.useMemo)(()=>!e||a||p==null||p.rolloutCountWithCompletedTurns<1||p.estimatedSavedMs<u?null:{threadCountLabel:S(t,p.rolloutCountWithCompletedTurns),savedDuration:x(t,p.estimatedSavedMs)},[e,t,a,p]);return!e||a?{estimate:null,estimateStatus:`idle`,isEstimateFreshForAnnouncement:!1}:T==null||p==null?{estimate:null,estimateStatus:b,isEstimateFreshForAnnouncement:!1}:{estimate:T,estimateStatus:b,isEstimateFreshForAnnouncement:_(p.computedAtMs)}}function x(e,t){let n=Math.max(1,Math.round(t/6e4)),r=Math.floor(n/60),i=n%60,a=e.formatMessage(l.durationHoursLabel,{hours:r}),o=e.formatMessage(l.durationMinutesLabel,{minutes:i});return r>0&&i>0?e.formatMessage(l.durationHoursAndMinutes,{hoursLabel:a,minutesLabel:o}):r>0?a:o}function S(e,t){return e.formatMessage(t===1?l.threadCountOne:l.threadCountOther,{count:t})}export{b as n,l as t};
//# sourceMappingURL=use-fast-mode-personalized-estimate-CYddgJOI.js.map