import{i as e}from"./rolldown-runtime-B1FJdls4.js";import{m as t}from"./vendor-dnd-C1cICjTT.js";import{s as n}from"./vendor-markdown-Db1-9wH7.js";import{W as r}from"./useSessionAttentionAcks-ru3bu2LG.js";import{t as i}from"./SidebarSessionTimeline-BQYELqYL.js";import{t as a}from"./SidebarSessionViewToggle-DJhYhtWi.js";var o=e(t(),1),s=new Map;function c(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,64)||`folder-${Date.now()}`}function l(e){let t=(e.id??e.folder_id??``).trim(),n=(e.name??t).trim();return!t||!n?null:{id:t,name:n,icon:e.icon??`▣`,description:e.description??e.purpose??null}}function u(e,t=!0){let[n,r]=(0,o.useState)(()=>s.get(e)??[]),[i,a]=(0,o.useState)(null),u=(0,o.useCallback)(async()=>{try{let t=await fetch(`/api/projects/topic-folders?projectPath=${encodeURIComponent(e)}&includeSessions=false`),n=await t.json().catch(()=>({}));if(!t.ok)throw Error(n.error||`Folders failed (${t.status})`);let i=(n.folders??[]).map(l).filter(e=>!!e);s.set(e,i),r(i),a(null)}catch(e){a(e instanceof Error?e.message:String(e))}},[e]);return(0,o.useEffect)(()=>{r(s.get(e)??[]),t&&u()},[t,e,u]),{folders:n,error:i,setError:a,refresh:u,createFolder:(0,o.useCallback)(async t=>{let n=t.trim();if(!n)return;let r=await fetch(`/api/projects/topic-folders`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({projectPath:e,folderId:c(n),name:n,icon:`▣`,purpose:``,source:`user`})});if(!r.ok)throw Error(`Could not create folder (${r.status})`);await u()},[e,u]),renameFolder:(0,o.useCallback)(async(t,n)=>{let r=n.trim();if(!r||r===t.name)return;let i=await fetch(`/api/projects/topic-folders/${encodeURIComponent(t.id)}?projectPath=${encodeURIComponent(e)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({projectPath:e,folderId:t.id,name:r,icon:t.icon??`▣`})});if(!i.ok)throw Error(`Could not rename folder (${i.status})`);await u()},[e,u]),deleteFolder:(0,o.useCallback)(async t=>{let n=await fetch(`/api/projects/topic-folders/${encodeURIComponent(t.id)}?projectPath=${encodeURIComponent(e)}`,{method:`DELETE`});if(!n.ok)throw Error(`Could not delete folder (${n.status})`);await u()},[e,u])}}var d=n();function f({projectPath:e,sessions:t,onContinue:n,onNewSession:s,onLoadOlder:c,hasOlder:l=!1,loadingOlder:f=!1}){let p=(0,o.useMemo)(()=>r(t),[t]),[m,h]=(0,o.useState)(`recent`),{folders:g,error:_,setError:v,createFolder:y}=u(e,m===`folders`);return(0,d.jsxs)(`div`,{className:`session-timeline-panel flex h-full min-h-0 w-full flex-col`,children:[(0,d.jsxs)(`div`,{className:`project-pane-heading session-timeline-heading`,children:[(0,d.jsx)(`h2`,{children:`Sessions`}),(0,d.jsxs)(`span`,{children:[p.length,` total`]})]}),(0,d.jsx)(a,{mode:m,onChange:h,onCreateFolder:()=>{let e=window.prompt(`Folder name`,`New folder`)?.trim();e&&y(e).catch(e=>v(e instanceof Error?e.message:String(e)))},className:`session-timeline-view-toggle mb-4 mt-3`}),m===`folders`&&_?(0,d.jsx)(`div`,{className:`mb-3 rounded-lg border border-terminal-red/40 bg-terminal-red/10 px-2.5 py-1.5 text-[11px] text-terminal-red`,children:_}):null,(0,d.jsx)(i,{sessions:p,onSessionClick:(e,t)=>n?.(e,t),showProjectTag:!1,variant:`embedded`,emptyLabel:`No sessions for this project yet.`,onNewSession:s,groupBy:m===`folders`?`folder`:`time`,folders:g,folderPresentation:`sidebar-accordion`,onLoadOlder:c,hasOlder:l,loadingOlder:f,className:`mc-minimal-scrollbar session-timeline-content min-h-0 w-full flex-1 overflow-y-auto`})]})}export{f as t};