import{a as E,b as n,r as l,j as t,P,E as b,c as D}from"./index-CUDottTv.js";import{B as o}from"./textarea-DAwdLdON.js";import{T as A}from"./trash-2-C4Tvwfqn.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 j=E("Pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]);function M({projectId:d}){const c=n(e=>e.notes),g=n(e=>e.notesLoading),[a,u]=l.useState(null),[p,x]=l.useState(""),[f,m]=l.useState(""),[v,i]=l.useState(!1);l.useEffect(()=>{n.getState().fetchNotes(d)},[d]);const h=[...c].sort((e,s)=>e.pinned!==s.pinned?e.pinned?-1:1:s.updatedAt-e.updatedAt),r=c.find(e=>e.id===a)??null,N=e=>{const s=c.find(k=>k.id===e);s&&(u(e),x(s.title),m(s.content),i(!1))},y=async()=>{const e=await n.getState().createNote({title:"Untitled",projectId:d});e&&N(e.id)},w=async()=>{a&&(await n.getState().updateNote(a,{title:p,content:f}),i(!1))},S=async()=>{r&&await n.getState().updateNote(r.id,{pinned:!r.pinned})},C=async()=>{a&&(await n.getState().deleteNote(a),u(null),x(""),m(""),i(!1))},z=e=>new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"});return t.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[t.jsxs("div",{className:"w-[280px] shrink-0 border-r border-border-default flex flex-col min-h-0",children:[t.jsxs("div",{className:"flex items-center justify-between px-3 py-3 border-b border-border-default",children:[t.jsx("h2",{className:"text-sm font-semibold text-text-primary",children:"Notes"}),t.jsxs(o,{variant:"ghost",size:"sm",onClick:y,children:[t.jsx(P,{size:14}),"New"]})]}),h.length===0&&!g?t.jsx("div",{className:"p-4",children:t.jsx(b,{title:"No notes yet",description:"Create a note to get started."})}):t.jsx("div",{className:"flex-1 overflow-y-auto",children:h.map(e=>t.jsxs("button",{type:"button",onClick:()=>N(e.id),className:D("px-3 py-2.5 cursor-pointer border-b border-border-muted hover:bg-bg-hover","w-full text-left",e.id===a&&"bg-bg-active"),children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"text-sm font-medium text-text-primary truncate",children:e.title}),e.pinned&&t.jsx(j,{size:12,className:"text-text-muted shrink-0"})]}),t.jsx("p",{className:"text-xs text-text-muted truncate mt-0.5",children:e.content.split(`
`)[0]||"Empty note"}),t.jsx("p",{className:"text-xs text-text-tertiary mt-1",children:z(e.updatedAt)})]},e.id))})]}),t.jsx("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:r?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"text",value:p,onChange:e=>{x(e.target.value),i(!0)},placeholder:"Note title",className:"w-full bg-transparent text-lg font-semibold text-text-primary px-4 pt-4 pb-2 outline-none"}),t.jsx("textarea",{value:f,onChange:e=>{m(e.target.value),i(!0)},placeholder:"Start writing...",className:"w-full flex-1 bg-transparent text-text-primary text-sm font-mono p-4 resize-none outline-none"}),t.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-t border-border-default",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(o,{variant:"ghost",size:"sm",onClick:S,children:[t.jsx(j,{size:14}),r.pinned?"Unpin":"Pin"]}),t.jsxs(o,{variant:"danger",size:"sm",onClick:C,children:[t.jsx(A,{size:14}),"Delete"]})]}),t.jsx(o,{variant:"primary",size:"sm",onClick:w,disabled:!v,children:"Save"})]})]}):t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsx(b,{title:"Select a note",description:"Choose a note from the list or create a new one."})})})]})}export{M as NotesPage};
