import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{O as t,k as n}from"./vendor-markdown-DngssFHR.js";import{c as r,l as i}from"./vendor-react-Cts2Wj-s.js";import{Q as a,X as o,at as s,nt as c,rt as l}from"./vendor-mui-Ckcy4Lfd.js";import"./vendor-md-editor-DC6xr_29.js";import{G as u,W as d}from"./vendor-mui-icons-606Bohdn.js";import{a as f,g as p,h as m,l as h,m as g,n as _,p as v,r as y,v as b,x}from"./ui-BLXHSX1T.js";import{A as S,B as C,I as w,L as T,N as E,P as D,V as O,k}from"./index-JB73_g7R.js";import"./skill-ZS39xCGU.js";import{t as A}from"./relation-manager-DQ9I91YW.js";import{n as j}from"./attachments-BKCJWgDD.js";var M=e(n(),1),N=t();function P(){let{projectId:e,noteId:t}=i(),n=r(),P=O(`knowledge`),[F,I]=(0,M.useState)(null),[L,R]=(0,M.useState)([]),[z,B]=(0,M.useState)([]),[V,H]=(0,M.useState)(!0),[U,W]=(0,M.useState)(null),[G,K]=(0,M.useState)(!1),q=(0,M.useCallback)(async()=>{if(!(!e||!t))try{let[n,r,i]=await Promise.all([E(e,t),w(e,t),D(e,t)]);I(n),R(r),B(i),W(null)}catch(e){W(e instanceof Error?e.message:String(e))}finally{H(!1)}},[e,t]);return(0,M.useEffect)(()=>{q()},[q]),x(e??null,(0,M.useCallback)(e=>{e.type.startsWith(`note:`)&&q()},[q])),V?(0,N.jsx)(a,{sx:{display:`flex`,justifyContent:`center`,py:4},children:(0,N.jsx)(s,{})}):U||!F?(0,N.jsx)(l,{severity:`error`,children:U||`Note not found`}):(0,N.jsxs)(a,{children:[(0,N.jsx)(v,{breadcrumbs:[{label:`Knowledge`,to:`/${e}/knowledge`},{label:F.title}],actions:P?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(o,{variant:`contained`,color:`success`,startIcon:(0,N.jsx)(u,{}),onClick:()=>n(`/${e}/knowledge/${t}/edit`),children:`Edit`}),(0,N.jsx)(o,{color:`error`,startIcon:(0,N.jsx)(d,{}),onClick:()=>K(!0),children:`Delete`})]}):void 0}),(0,N.jsx)(f,{main:(0,N.jsx)(N.Fragment,{children:F.content&&(0,N.jsx)(b,{title:`Content`,sx:{mb:3},children:(0,N.jsx)(_,{children:F.content})})}),sidebar:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(b,{title:`Details`,sx:{mb:3},children:[(0,N.jsx)(h,{label:`ID`,children:(0,N.jsxs)(a,{sx:{display:`flex`,alignItems:`center`,gap:.5},children:[(0,N.jsx)(c,{variant:`body2`,sx:{fontFamily:`monospace`},children:F.id}),(0,N.jsx)(m,{value:F.id})]})}),(0,N.jsx)(h,{label:`Version`,children:(0,N.jsxs)(c,{variant:`body2`,sx:{fontFamily:`monospace`},children:[`v`,F.version]})}),(0,N.jsx)(h,{label:`Tags`,children:F.tags.length>0?(0,N.jsx)(p,{tags:F.tags}):(0,N.jsx)(c,{variant:`body2`,color:`text.secondary`,children:`—`})}),F.createdBy&&(0,N.jsx)(h,{label:`Created by`,children:(0,N.jsx)(c,{variant:`body2`,children:F.createdBy})}),F.updatedBy&&F.updatedBy!==F.createdBy&&(0,N.jsx)(h,{label:`Updated by`,children:(0,N.jsx)(c,{variant:`body2`,children:F.updatedBy})}),(0,N.jsx)(h,{label:`Created`,children:(0,N.jsx)(g,{value:F.createdAt,showTime:!0,showRelative:!0})}),(0,N.jsx)(h,{label:`Updated`,divider:!1,children:(0,N.jsx)(g,{value:F.updatedAt,showTime:!0,showRelative:!0})})]}),(0,N.jsx)(b,{title:`Attachments`,sx:{mb:3},children:(0,N.jsx)(j,{attachments:z,getUrl:n=>T(e,t,n),onUpload:async n=>{await C(e,t,n),B(await D(e,t))},onDelete:async n=>{await S(e,t,n),B(await D(e,t))},readOnly:!P})}),(0,N.jsx)(b,{title:`Relations`,children:(0,N.jsx)(A,{projectId:e,entityId:t,entityType:`knowledge`,relations:L,onRefresh:q})})]})}),(0,N.jsx)(y,{open:G,title:`Delete Note`,message:`Are you sure you want to delete "${F.title}"? This cannot be undone.`,confirmLabel:`Delete`,confirmColor:`error`,onConfirm:async()=>{!e||!t||(await k(e,t),n(`/${e}/knowledge`))},onCancel:()=>K(!1)})]})}export{P as default};