import{i as e}from"./chunk-B3pr0VN8.js";import{n as t}from"./jsx-runtime-wTfS3W87.js";import{i as n,r}from"./ToolConversationBilling-tfxRkJpq.js";var i=e(t(),1);function a(e){let[t,a]=(0,i.useState)(null),o=(0,i.useRef)(new Set),s=(0,i.useRef)(!1),c=(0,i.useRef)(``),l=(0,i.useCallback)(()=>{s.current=!1,c.current=``,o.current=new Set,a(null)},[]),u=(0,i.useCallback)(async()=>(s.current=!0,c.current=``,a(null),o.current=await n({rangeDays:e?.rangeDays??7,pageSize:e?.pageSize??100}),o.current),[e?.pageSize,e?.rangeDays]),d=(0,i.useCallback)(e=>{let t=String(e?.requestId||``).trim();t&&(c.current=t)},[]);return{billing:t,setBilling:a,begin:u,finish:(0,i.useCallback)(async t=>{if(!s.current)return null;let n=await r({beforeIds:o.current,requestId:c.current||void 0,aggregateAllNew:t?.aggregateAllNew!==!1&&o.current.size>0,rangeDays:e?.rangeDays??7,pageSize:e?.pageSize??100,attempts:e?.attempts??3,retryDelayMs:e?.retryDelayMs??450});return a(n),n},[e?.attempts,e?.pageSize,e?.rangeDays,e?.retryDelayMs]),captureRequestId:d,reset:l}}export{a as t};