1import{u as E,j as e,al as p,gd as L,X as b,an as R,a as x,x as A,r as F}from"./index-CLLuKEAZ.js";import{r as a}from"./vendor-dnd-Cjb-GulA.js";import"./vendor-socket-SYmKJpIj.js";import"./vendor-tiptap-deelaI2W.js";function B({linkType:i,linkId:l}){const{t:s}=E(),[m,o]=a.useState([]),[w,h]=a.useState(!0),[f,c]=a.useState(!1),[k,d]=a.useState(""),[u,r]=a.useState([]),[S,j]=a.useState(!1),v=()=>{if(!i||!l){o([]),h(!1);return}x.get(`/documents/links?link_type=${i}&link_id=${l}`).then(t=>o(t.data||[])).catch(()=>o([])).finally(()=>h(!1))};a.useEffect(()=>{h(!0),v()},[i,l]);const _=async t=>{if(d(t),!t.trim()){r([]);return}j(!0);try{const{data:n}=await x.get(`/documents/search?q=${encodeURIComponent(t)}`),g=Array.isArray(n)?n:n.documents||[],$=new Set(m.map(y=>y.id));r(g.filter(y=>!$.has(y.id)).slice(0,10))}catch{r([])}j(!1)},C=async t=>{try{await x.post(`/documents/list/${t}/links`,{link_type:i,link_id:l}),c(!1),d(""),r([]),v()}catch{}},D=async t=>{if(await A(s("document.links.unlinkConfirm","Verknüpfung wirklich entfernen?")))try{await x.delete(`/documents/list/${t.id}/links/${t.link_id}`),o(n=>n.filter(g=>g.id!==t.id))}catch{}};if(w)return e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"w-5 h-5 border-2 border-indigo-400 border-t-transparent rounded-full animate-spin"})});const N=()=>e.jsx("div",{className:"flex gap-2",children:e.jsxs("button",{onClick:()=>{c(t=>!t),d(""),r([])},className:"flex-1 flex items-center justify-center gap-1.5 px-3 py-2 text-xs font-medium text-gray-600 dark:text-gray-300 bg-gray-100 dark:bg-gray-800 hover:bg-indigo-50 dark:hover:bg-indigo-950 hover:text-indigo-600 dark:hover:text-indigo-400 rounded-lg transition-colors",children:[e.jsx(F,{className:"w-3.5 h-3.5"}),s("document.links.link","Dokument verknüpfen")]})});return m.length===0&&!f?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center py-6",children:[e.jsx(p,{className:"w-8 h-8 text-gray-300 dark:text-gray-600 mx-auto mb-2"}),e.jsx("p",{className:"text-xs text-gray-400",children:s("document.links.emptyLinked","Keine Dokumente verknüpft")})]}),e.jsx(N,{})]}):e.jsxs("div",{className:"space-y-2",children:[m.map(t=>e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-xl border border-gray-200 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors group",children:[e.jsx(p,{className:"w-4 h-4 text-indigo-500 mt-0.5 flex-shrink-0"}),e.jsxs("a",{href:`/documents/${t.id}`,className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-gray-800 dark:text-gray-200 truncate group-hover:text-indigo-600 dark:group-hover:text-indigo-400 transition-colors",children:t.name||s("common.untitled","Ohne Titel")}),t.folder_name&&e.jsxs("div",{className:"flex items-center gap-1.5 mt-1",children:[e.jsx(L,{className:"w-3 h-3 text-gray-400"}),e.jsx("span",{className:"text-[11px] text-gray-400 truncate",children:t.folder_name})]})]}),e.jsx("button",{onClick:()=>D(t),className:"p-0.5 text-gray-300 hover:text-red-500 dark:text-gray-600 dark:hover:text-red-400 opacity-0 group-hover:opacity-100 transition-all flex-shrink-0",children:e.jsx(b,{className:"w-3.5 h-3.5"})})]},t.id)),f&&e.jsxs("div",{className:"border border-gray-200 dark:border-gray-600 rounded-xl p-3 space-y-2 mt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{className:"w-3.5 h-3.5 text-gray-400"}),e.jsx("input",{autoFocus:!0,value:k,onChange:t=>_(t.target.value),onKeyDown:t=>t.key==="Escape"&&c(!1),placeholder:s("document.links.searchPlaceholder","Dokument suchen..."),className:"flex-1 text-sm bg-transparent text-gray-700 dark:text-gray-200 outline-none"}),e.jsx("button",{onClick:()=>{c(!1),d(""),r([])},className:"p-0.5 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:e.jsx(b,{className:"w-3.5 h-3.5"})})]}),u.length>0&&e.jsx("div",{className:"max-h-40 overflow-y-auto space-y-0.5",children:u.map(t=>e.jsxs("button",{onClick:()=>C(t.id),className:"w-full text-left flex items-center gap-2 px-2 py-1.5 rounded-lg text-sm text-gray-700 dark:text-gray-300 hover:bg-indigo-50 dark:hover:bg-indigo-950/50 truncate",children:[e.jsx(p,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),t.name||s("common.untitled","Ohne Titel"),t.folder_name&&e.jsxs("span",{className:"text-[10px] text-gray-400 ml-1",children:["(",t.folder_name,")"]})]},t.id))}),k&&!S&&u.length===0&&e.jsx("p",{className:"text-xs text-gray-400 text-center py-2",children:s("common.noResults","Keine Ergebnisse")})]}),e.jsx("div",{className:"mt-3",children:e.jsx(N,{})})]})}export{B as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.