import{a as A,b as c,r as i,j as e,E as M,P as $,c as d}from"./index-CUDottTv.js";import{B as D}from"./textarea-DAwdLdON.js";import{F as b}from"./file-text-h8kcLd2l.js";import{D as O}from"./download-CwvkYJyJ.js";import{T as L}from"./trash-2-C4Tvwfqn.js";import{S as Y}from"./save-BGeL2PJM.js";/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const H=A("Folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);function T(r){return r<1024?`${r} B`:`${(r/1024).toFixed(1)} KB`}function V(r){const n=r.match(/^---[\s\S]*?type:\s*(\w+)[\s\S]*?---/);return n?n[1]:null}function W(r){const n=r.match(/^---[\s\S]*?name:\s*(.+?)[\s\S]*?---/);return n?n[1].trim():null}function Z(r){const n=r.match(/^---[\s\S]*?description:\s*(.+?)[\s\S]*?---/);return n?n[1].trim():null}const _={user:{bg:"bg-blue-muted",text:"text-blue"},feedback:{bg:"bg-green-muted",text:"text-green"},project:{bg:"bg-purple-muted",text:"text-purple"},reference:{bg:"bg-amber-muted",text:"text-amber"}};function I({projectId:r,claudeProjectKey:n}){const l=c(t=>t.memoryFiles),F=c(t=>t.memoryLoading),[a,h]=i.useState(null),[S,y]=i.useState(""),[C,p]=i.useState(!1),[j,m]=i.useState("preview"),[B,v]=i.useState(!1),[z,g]=i.useState("");i.useEffect(()=>{n&&c.getState().fetchMemoryFiles(r)},[r,n]),i.useEffect(()=>{if(a){const t=l.find(o=>o.filename===a);t&&(y(t.content),p(!1))}},[a,l]);const s=a?l.find(t=>t.filename===a):null,u=s?V(s.content):null,N=s?W(s.content):null,w=s?Z(s.content):null,x=u?_[u]:null,P=async()=>{a&&(await c.getState().saveMemoryFile(r,a,S),p(!1))},E=async()=>{a&&(await c.getState().deleteMemoryFile(r,a),h(null),y(""),p(!1))},R=async()=>{const t=z.trim();if(!t)return;const o=t.endsWith(".md")?t:`${t}.md`;await c.getState().saveMemoryFile(r,o,`---
name: 
description: 
type: user
---

`),v(!1),g(""),h(o),m("edit")},U=()=>{if(!s)return;const t=new Blob([s.content],{type:"text/markdown"}),o=URL.createObjectURL(t),k=document.createElement("a");k.href=o,k.download=s.filename,k.click(),URL.revokeObjectURL(o)};return n?e.jsx("div",{className:"flex-1 flex min-h-0 overflow-hidden p-5",children:e.jsxs("div",{className:"flex-1 border border-border-strong rounded-lg overflow-hidden flex min-h-0",children:[e.jsxs("div",{className:"w-[240px] shrink-0 bg-bg-app border-r border-border-muted flex flex-col min-h-0",children:[e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-3 border-b border-border-muted shrink-0",children:[e.jsx("span",{className:"text-[12px] font-semibold text-text-secondary",children:"Memory Files"}),e.jsx("button",{type:"button",onClick:()=>v(!0),className:"w-[26px] h-[26px] rounded-md flex items-center justify-center text-text-muted hover:text-accent hover:bg-bg-hover transition-all cursor-pointer",title:"New file",children:e.jsx($,{size:14})})]}),e.jsxs("div",{className:"flex items-center gap-1 px-3.5 py-2 text-[11px] text-text-muted border-b border-border-muted shrink-0",children:[e.jsx(H,{size:11}),e.jsx("span",{className:"truncate",children:"~/.claude/projects/.../memory/"})]}),B&&e.jsx("div",{className:"px-3 py-2 border-b border-border-muted shrink-0",children:e.jsx("input",{type:"text",className:"w-full h-7 bg-bg-input text-text-primary text-[12px] rounded-md px-2.5 border border-border-strong outline-none focus:border-accent-border font-mono",placeholder:"filename.md",value:z,onChange:t=>g(t.target.value),onKeyDown:t=>{t.key==="Enter"&&R(),t.key==="Escape"&&(v(!1),g(""))},autoFocus:!0})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-1",children:[F&&e.jsx("p",{className:"px-3 py-4 text-[11px] text-text-muted",children:"Loading..."}),!F&&l.length===0&&e.jsx("p",{className:"px-3 py-4 text-[11px] text-text-muted",children:"No memory files yet"}),l.map(t=>{const o=a===t.filename;return e.jsxs("button",{type:"button",onClick:()=>{h(t.filename),m("preview")},className:d("w-full flex items-center gap-2 px-2.5 py-2 rounded-md text-left transition-colors cursor-pointer",o?"bg-accent-muted":"hover:bg-bg-hover"),children:[e.jsx(b,{size:15,className:d("shrink-0",o?"text-accent":"text-text-muted")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:d("text-[12px] font-medium truncate",o?"text-accent":"text-text-primary"),children:t.filename}),e.jsx("div",{className:"text-[10px] text-text-disabled mt-0.5",children:T(t.sizeBytes)})]})]},t.filename)})]})]}),e.jsx("div",{className:"flex-1 flex flex-col min-h-0 bg-bg-surface",children:a?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-5 py-3 border-b border-border-muted shrink-0",children:[e.jsx(b,{size:16,className:"text-text-muted shrink-0"}),e.jsx("span",{className:"text-[14px] font-semibold text-text-primary flex-1",children:a}),e.jsxs("div",{className:"flex bg-bg-elevated border border-border-default rounded-md p-0.5",children:[e.jsx("button",{onClick:()=>m("preview"),className:d("px-2.5 py-1 text-[11px] font-medium rounded transition-colors cursor-pointer",j==="preview"?"bg-bg-overlay text-text-primary":"text-text-muted hover:text-text-secondary"),children:"Preview"}),e.jsx("button",{onClick:()=>m("edit"),className:d("px-2.5 py-1 text-[11px] font-medium rounded transition-colors cursor-pointer",j==="edit"?"bg-bg-overlay text-text-primary":"text-text-muted hover:text-text-secondary"),children:"Edit"})]}),e.jsxs("button",{onClick:U,className:"h-[28px] px-2 text-[11px] font-medium text-text-tertiary bg-bg-surface border border-border-default rounded-md inline-flex items-center gap-1.5 hover:border-border-hover hover:text-text-primary transition-colors cursor-pointer",children:[e.jsx(O,{size:11})," Download"]})]}),j==="edit"?e.jsxs(e.Fragment,{children:[e.jsx("textarea",{className:"w-full flex-1 bg-transparent text-text-primary text-[13px] font-mono p-5 resize-none outline-none leading-relaxed",value:S,onChange:t=>{y(t.target.value),p(!0)},spellCheck:!1}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-t border-border-muted shrink-0",children:[e.jsxs(D,{variant:"danger",size:"sm",onClick:E,children:[e.jsx(L,{size:12})," Delete"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[C&&e.jsx("span",{className:"text-[11px] text-amber",children:"Unsaved changes"}),e.jsxs(D,{variant:"primary",size:"sm",onClick:P,disabled:!C,children:[e.jsx(Y,{size:12})," Save"]})]})]})]}):e.jsx("div",{className:"flex-1 overflow-y-auto px-8 py-6",children:e.jsx("div",{className:"max-w-[720px] text-[14px] text-text-secondary leading-[1.7] whitespace-pre-wrap font-mono",children:(s==null?void 0:s.content)||"(empty file)"})})]}):e.jsx(M,{icon:e.jsx(b,{size:28}),title:"Select a memory file",description:"Choose a file from the list or create a new one."})}),a&&s&&e.jsxs("div",{className:"w-[280px] shrink-0 bg-bg-app border-l border-border-muted overflow-y-auto hidden xl:block",children:[e.jsxs("div",{className:"p-4 border-b border-border-muted",children:[e.jsx("div",{className:"text-[11px] font-semibold text-text-muted uppercase tracking-wider mb-2.5",children:"Document Info"}),e.jsx(f,{label:"File Size",value:T(s.sizeBytes)}),e.jsx(f,{label:"Format",value:"Markdown"}),e.jsx(f,{label:"Filename",value:s.filename,mono:!0})]}),(N||u||w)&&e.jsxs("div",{className:"p-4 border-b border-border-muted",children:[e.jsx("div",{className:"text-[11px] font-semibold text-text-muted uppercase tracking-wider mb-2.5",children:"Frontmatter"}),N&&e.jsx(f,{label:"Name",value:N}),u&&e.jsxs("div",{className:"flex items-center justify-between py-1",children:[e.jsx("span",{className:"text-[12px] text-text-muted",children:"Type"}),e.jsx("span",{className:d("text-[10px] font-semibold px-2 py-0.5 rounded",(x==null?void 0:x.bg)??"bg-bg-overlay",(x==null?void 0:x.text)??"text-text-muted"),children:u})]}),w&&e.jsx("p",{className:"text-[11px] text-text-tertiary mt-2 leading-relaxed",children:w})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("div",{className:"text-[11px] font-semibold text-text-muted uppercase tracking-wider mb-2.5",children:"Actions"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("button",{onClick:()=>m("edit"),className:"w-full h-8 text-[12px] font-medium text-text-tertiary bg-bg-elevated border border-border-default rounded-md inline-flex items-center justify-center gap-1.5 hover:border-border-hover hover:text-text-primary transition-colors cursor-pointer",children:"Edit File"}),e.jsxs("button",{onClick:E,className:"w-full h-8 text-[12px] font-medium text-red bg-red-muted/50 border border-red-muted rounded-md inline-flex items-center justify-center gap-1.5 hover:bg-red-muted transition-colors cursor-pointer",children:[e.jsx(L,{size:11})," Delete File"]})]})]})]})]})}):e.jsx(M,{icon:e.jsx(b,{size:32}),title:"No Claude project linked",description:"Link a Claude project to manage memory files. Memory files help Claude remember context across conversations."})}function f({label:r,value:n,mono:l}){return e.jsxs("div",{className:"flex items-center justify-between py-1",children:[e.jsx("span",{className:"text-[12px] text-text-muted",children:r}),e.jsx("span",{className:d("text-[12px] font-medium text-text-primary",l&&"font-mono text-[11px]"),children:n})]})}export{I as MemoryPage};
