import{n as e,s as t,t as n}from"./jsx-runtime-Bzw2jH9X.js";import{Qt as r,f as i}from"./services-Ddh4dHvP.js";import{i as a,n as o,t as s}from"./date-CTxYulDo.js";import{t as c}from"./spin-DUmNjrhn.js";import{t as l}from"./clock-B5dcDzZw.js";import{t as u}from"./x-CkbzgTHo.js";import{dt as d,lt as f,q as p}from"./index-DkcBoy_T.js";var m=`https://zj.xianjianai.com/v1/document/image/`,h=`https://zj.xianjianai.com/api/v1/documents/`,g=`UfReg7Iy49E65KTe7OaVpA5kn3qbQdJn`,_=`new-session`,v=t(e(),1),y=n(),b=[{id:`all`,label:`全部`},{id:`3days`,label:`近3天`,offsetDays:-2},{id:`7days`,label:`近7天`,offsetDays:-6},{id:`30days`,label:`近30天`,offsetDays:-29}];function x(e){let t=b.find(t=>t.id===e);if(t?.offsetDays==null)return{};let n=new Date;return{createdAtStart:a(n,t.offsetDays,`day`),createdAtEnd:s(n)}}function S({onClose:e,onSelect:t}){let[n,a]=(0,v.useState)(`all`),[s,m]=(0,v.useState)([]),[h,g]=(0,v.useState)(!1),[_,S]=(0,v.useState)(!0),C=(0,v.useRef)(1),w=(0,v.useRef)(!1),T=(0,v.useRef)(0),E=async(e,t)=>{if(!t&&(w.current||!_))return;let r=++T.current;w.current=!0,g(!0),t&&(m([]),S(!0));try{let a=x(n),o=await i({page:e,limit:10,createdAtStart:a.createdAtStart,createdAtEnd:a.createdAtEnd});if(r!==T.current)return;let c=o.data,l=t?c.length:s.length+c.length;S(l<o.meta.itemCount),m(e=>t?c:[...e,...c]),C.current=e}catch(e){if(console.error(`加载 AI 搜索历史失败:`,e),r!==T.current)return;t&&(m([]),S(!1))}finally{r===T.current&&(w.current=!1,g(!1))}};return(0,v.useEffect)(()=>{C.current=1,E(1,!0)},[n]),(0,y.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center bg-slate-900/50 p-4 backdrop-blur-sm ${r.overlay} animate-in fade-in duration-200`,children:(0,y.jsxs)(`div`,{className:`flex h-155 w-full max-w-3xl flex-col overflow-hidden rounded-2xl bg-white shadow-xl animate-in zoom-in-95 duration-200`,children:[(0,y.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-slate-100 bg-slate-50 p-6`,children:[(0,y.jsxs)(`h3`,{className:`flex items-center gap-2 text-lg font-bold text-slate-900`,children:[(0,y.jsx)(l,{size:20,className:`text-indigo-500`}),`历史记录`]}),(0,y.jsx)(`button`,{type:`button`,onClick:e,className:`cursor-pointer p-1 text-slate-400 hover:text-slate-600`,children:(0,y.jsx)(u,{size:20})})]}),(0,y.jsx)(`div`,{className:`flex shrink-0 gap-2 border-b border-slate-100 bg-white p-4`,children:b.map(e=>(0,y.jsx)(`button`,{type:`button`,onClick:()=>{e.id!==n&&a(e.id)},className:`cursor-pointer rounded-full px-4 py-1.5 text-sm font-medium transition-colors ${n===e.id?`bg-indigo-100 text-indigo-700`:`bg-slate-100 text-slate-600 hover:bg-slate-200`}`,children:e.label},e.id))}),(0,y.jsxs)(`div`,{className:`relative z-10 flex-1 overflow-y-auto p-4`,children:[s.length===0&&h&&(0,y.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,y.jsx)(c,{description:`加载中...`})}),s.length===0&&!h&&(0,y.jsx)(`div`,{className:`flex items-center justify-center py-20 text-sm text-slate-400`,children:`暂无记录`}),s.length>0&&(0,y.jsx)(`div`,{className:`grid gap-3`,children:s.map(n=>(0,y.jsxs)(`button`,{type:`button`,onClick:()=>{t(n.sessionId,n.title),e()},className:`group flex w-full cursor-pointer items-center justify-between rounded-xl border border-slate-200 bg-white p-4 text-left transition-all hover:border-indigo-300 hover:shadow-md hover:shadow-indigo-50/50`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-3 overflow-hidden`,children:[(0,y.jsx)(p,{size:16,className:`shrink-0 text-slate-400 group-hover:text-indigo-500`}),(0,y.jsx)(`span`,{className:`line-clamp-1 text-sm font-medium text-slate-700 group-hover:text-indigo-700`,children:n.title})]}),(0,y.jsxs)(`div`,{className:`ml-4 flex shrink-0 items-center gap-3`,children:[(0,y.jsx)(`span`,{className:`text-xs text-slate-400 opacity-60 transition-opacity group-hover:opacity-100`,children:o(n.createdAt)}),(0,y.jsx)(f,{size:16,className:`shrink-0 text-slate-300 group-hover:text-indigo-400`})]})]},n.sessionId))}),s.length>0&&_&&(0,y.jsx)(`div`,{className:`flex justify-center pt-4 pb-1`,children:(0,y.jsx)(`button`,{type:`button`,disabled:h,onClick:()=>void E(C.current+1,!1),className:`flex cursor-pointer items-center gap-1 rounded-full border border-indigo-100 bg-indigo-50/80 px-4 py-1.5 text-xs font-semibold text-indigo-600 transition-colors hover:bg-indigo-100 disabled:cursor-not-allowed disabled:opacity-60`,children:h?(0,y.jsx)(c,{size:`small`}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(d,{size:14}),`加载更多`]})})})]})]})})}export{g as a,m as i,_ as n,h as r,S as t};