import{A as Z,r as h,B as I,C as ee,d as H,j as F,n as N,o as v,s as te,f as L,T as Q,g as V,c as _,w as z,a as e,e as O,v as P,h as E,F as G,m as ne,q as se,t as q,b as K,O as ae,K as j,u as oe,P as ie,k as le,x as re,p as ue,l as b,M as ce}from"./index-Bwmlaq-e.js";import{_ as J}from"./Button-BCQM6xXJ.js";const de=Z("documents",()=>{const r=h(null),x=h([]),w=h(!1),k=h(null),m=h(!1),i=ee();async function y(t){w.value=!0,k.value=null;try{r.value=await i.get(`/documents/${t}`)}catch(n){throw k.value=n instanceof Error?n.message:"Failed to fetch document",n}finally{w.value=!1}}async function d(t,n,o="",u=null){const $={title:n,content:o};return u&&($.folder_id=u),await i.post(`/projects/${t}/documents`,$)}async function c(t,n,o){var A;const u={title:n};o!==void 0&&(u.folder_id=o);const $=await i.put(`/documents/${t}`,u);return((A=r.value)==null?void 0:A.id)===t&&(r.value=$),$}async function S(t,n){var o;m.value=!0;try{await i.put(`/documents/${t}/content`,{content:n}),((o=r.value)==null?void 0:o.id)===t&&(r.value.content=n)}finally{m.value=!1}}async function D(t){var n;await i.delete(`/documents/${t}`),((n=r.value)==null?void 0:n.id)===t&&(r.value=null)}async function g(){try{x.value=await i.get("/tags")}catch(t){console.error("Failed to fetch tags:",t)}}async function a(t,n){const o=await i.post("/tags",{name:t,color:n});return x.value.push(o),o}async function M(t,n){var o;await i.put(`/documents/${t}/tags`,{tag_ids:n}),((o=r.value)==null?void 0:o.id)===t&&(r.value.tags=x.value.filter(u=>n.includes(u.id)))}async function B(t,n){var o;await i.delete(`/documents/${t}/tags/${n}`),((o=r.value)==null?void 0:o.id)===t&&(r.value.tags=r.value.tags.filter(u=>u.id!==n))}async function C(t,n){var o;m.value=!0;try{await i.put(`/documents/${t}/content`,{content:n,format:"tiptap"}),((o=r.value)==null?void 0:o.id)===t&&(r.value.tiptap_content=n)}finally{m.value=!1}}async function T(t){try{return(await i.get(`/documents/${t}/content?format=tiptap`)).content}catch{return null}}async function p(t){try{return await i.get(`/documents/${t}/reasoning-panel`)}catch{return null}}async function s(t,n){var u;const o=await i.put(`/documents/${t}/reasoning`,n);return((u=r.value)==null?void 0:u.id)===t&&(r.value.reasoning=o),o}async function l(t,n,o){try{return await i.post(`/documents/${t}/reasoning-steps`,{thought:n,conclusion:o})}catch{return null}}async function f(t,n){await i.delete(`/documents/${t}/reasoning-steps/${n}`)}async function R(t){return await i.get(`/documents/${t}/backlinks`)}async function U(t){return await i.get(`/documents/${t}/outgoing-links`)}async function W(t){return await i.get(`/documents/${t}/links`)}async function X(t,n="documents",o=10,u){const $=new URLSearchParams({q:t,type:n,limit:String(o)});return u&&$.set("project_id",u),await i.get(`/search?${$}`)}async function Y(t,n){const u=await fetch(`http://localhost:8000/api/v1/documents/${t}/export?format=${n}`,{headers:{Authorization:`Bearer ${I()}`},credentials:"include"});if(!u.ok)throw new Error("Export failed");return await u.blob()}return{currentDocument:r,tags:x,loading:w,error:k,saving:m,fetchDocument:y,createDocument:d,updateDocument:c,updateDocumentContent:S,updateDocumentTipTapContent:C,fetchTipTapContent:T,fetchReasoningPanel:p,updateReasoning:s,addReasoningStep:l,deleteReasoningStep:f,deleteDocument:D,fetchTags:g,createTag:a,assignTags:M,removeTag:B,fetchBacklinks:R,fetchOutgoingLinks:U,fetchDocumentLinks:W,search:X,exportDocument:Y}}),he={class:"quick-switcher__dialog"},fe={class:"quick-switcher__input-wrap"},ve={key:0,class:"quick-switcher__loading"},pe=["onClick","onMouseenter"],_e={class:"quick-switcher__result-icon"},we={class:"quick-switcher__result-info"},me=["innerHTML"],ye={key:0,class:"quick-switcher__result-subtitle"},ke={class:"quick-switcher__result-type"},ge={key:2,class:"quick-switcher__empty"},xe={key:3,class:"quick-switcher__hint"},$e=H({__name:"QuickSwitcher",props:{show:{type:Boolean}},emits:["close"],setup(r,{emit:x}){const w=r,k=x,m=F(),i=de(),y=h(""),d=h([]),c=h(0),S=h(!1),D=h(null),g=h(null);let a=null;N(()=>w.show,async s=>{var l;s&&(y.value="",d.value=[],c.value=0,await j(),(l=D.value)==null||l.focus())}),N(y,s=>{if(a&&clearTimeout(a),!s.trim()){d.value=[];return}a=setTimeout(()=>{M(s)},150)});async function M(s){if(s.trim()){S.value=!0;try{const l=await i.search(s,"all",10);d.value=l.results,c.value=0}catch(l){console.error("Search failed:",l),d.value=[]}finally{S.value=!1}}}function B(s){s.key==="ArrowDown"?(s.preventDefault(),c.value=Math.min(c.value+1,d.value.length-1),C()):s.key==="ArrowUp"?(s.preventDefault(),c.value=Math.max(c.value-1,0),C()):s.key==="Enter"?(s.preventDefault(),d.value[c.value]&&T(d.value[c.value])):s.key==="Escape"&&k("close")}function C(){j(()=>{var l;const s=(l=g.value)==null?void 0:l.children[c.value];s==null||s.scrollIntoView({block:"nearest"})})}function T(s){s.type==="document"?m.push(`/documents/${s.id}`):s.type==="project"&&m.push(`/projects/${s.id}`),k("close")}function p(s){return s==="document"?"📄":s==="project"?"📁":"📄"}return(s,l)=>(v(),te(ae,{to:"body"},[L(Q,{name:"quick-switcher"},{default:V(()=>[r.show?(v(),_("div",{key:0,class:"quick-switcher",onClick:l[1]||(l[1]=z(f=>k("close"),["self"]))},[e("div",he,[e("div",fe,[l[2]||(l[2]=e("svg",{class:"quick-switcher__icon",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("circle",{cx:"11",cy:"11",r:"8"}),e("path",{d:"m21 21-4.35-4.35"})],-1)),O(e("input",{ref_key:"inputRef",ref:D,"onUpdate:modelValue":l[0]||(l[0]=f=>y.value=f),type:"text",class:"quick-switcher__input",placeholder:"Search documents and projects...",onKeydown:B},null,544),[[P,y.value]]),l[3]||(l[3]=e("kbd",{class:"quick-switcher__kbd"},"Esc",-1))]),S.value?(v(),_("div",ve,[...l[4]||(l[4]=[e("div",{class:"quick-switcher__spinner"},null,-1),E(" Searching... ",-1)])])):d.value.length>0?(v(),_("ul",{key:1,ref_key:"listRef",ref:g,class:"quick-switcher__results"},[(v(!0),_(G,null,ne(d.value,(f,R)=>(v(),_("li",{key:f.id,class:se(["quick-switcher__result",{"quick-switcher__result--selected":R===c.value}]),onClick:U=>T(f),onMouseenter:U=>c.value=R},[e("span",_e,q(p(f.type)),1),e("div",we,[e("span",{class:"quick-switcher__result-title",innerHTML:f.highlight||f.title},null,8,me),f.subtitle?(v(),_("span",ye,q(f.subtitle),1)):K("",!0)]),e("span",ke,q(f.type),1)],42,pe))),128))],512)):y.value.trim()?(v(),_("div",ge," No results found ")):(v(),_("div",xe,[...l[5]||(l[5]=[e("p",null,"Start typing to search...",-1),e("div",{class:"quick-switcher__shortcuts"},[e("span",null,[e("kbd",null,"↑"),e("kbd",null,"↓"),E(" Navigate")]),e("span",null,[e("kbd",null,"Enter"),E(" Open")]),e("span",null,[e("kbd",null,"Esc"),E(" Close")])],-1)])]))])])):K("",!0)]),_:1})]))}}),be=J($e,[["__scopeId","data-v-992dcfce"]]),Se={class:"header"},Ce={class:"header__left"},Te={class:"header__center"},qe={class:"header__right"},De=["title"],Be={key:0,width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},Me={key:1,width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},Ee={class:"header__avatar"},Re={class:"header__username"},Le={key:0,class:"header__dropdown"},Ue={class:"header__dropdown-item header__dropdown-item--info"},Ae=H({__name:"Header",setup(r){const x=F(),w=oe(),{resolvedTheme:k,toggleTheme:m}=ie(),i=h(""),y=h(!1),d=h(!1);function c(g){(g.metaKey||g.ctrlKey)&&g.key==="k"&&(g.preventDefault(),d.value=!0)}le(()=>{document.addEventListener("keydown",c)}),re(()=>{document.removeEventListener("keydown",c)});function S(){i.value.trim()&&x.push({name:"dashboard",query:{q:i.value}})}function D(){w.logout(),x.push("/login")}return(g,a)=>{var B,C,T;const M=ue("router-link");return v(),_(G,null,[e("header",Se,[e("div",Ce,[L(M,{to:"/dashboard",class:"header__logo"},{default:V(()=>[...a[4]||(a[4]=[e("svg",{width:"28",height:"28",viewBox:"0 0 28 28",fill:"none"},[e("rect",{width:"28",height:"28",rx:"6",fill:"var(--accent)"}),e("path",{d:"M8 10h12M8 14h8M8 18h10",stroke:"white","stroke-width":"2","stroke-linecap":"round"})],-1),e("span",{class:"header__title"},"Claudia Docs",-1)])]),_:1})]),e("div",Te,[e("form",{class:"header__search",onSubmit:z(S,["prevent"])},[a[5]||(a[5]=e("svg",{class:"header__search-icon",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("circle",{cx:"11",cy:"11",r:"8"}),e("path",{d:"m21 21-4.35-4.35"})],-1)),O(e("input",{"onUpdate:modelValue":a[0]||(a[0]=p=>i.value=p),type:"text",placeholder:"Search documents...",class:"header__search-input"},null,512),[[P,i.value]]),a[6]||(a[6]=e("kbd",{class:"header__kbd"},"⌘K",-1))],32)]),e("div",qe,[e("button",{class:"header__theme-toggle",onClick:a[1]||(a[1]=(...p)=>b(m)&&b(m)(...p)),title:b(k)==="dark"?"Switch to light mode":"Switch to dark mode"},[b(k)==="dark"?(v(),_("svg",Be,[...a[7]||(a[7]=[ce('',9)])])):(v(),_("svg",Me,[...a[8]||(a[8]=[e("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},null,-1)])]))],8,De),e("div",{class:"header__user",onClick:a[2]||(a[2]=p=>y.value=!y.value)},[e("div",Ee,q(((C=(B=b(w).user)==null?void 0:B.username)==null?void 0:C.charAt(0).toUpperCase())||"U"),1),e("span",Re,q(((T=b(w).user)==null?void 0:T.username)||"User"),1),a[11]||(a[11]=e("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("path",{d:"m6 9 6 6 6-6"})],-1)),L(Q,{name:"fade"},{default:V(()=>{var p,s;return[y.value?(v(),_("div",Le,[e("div",Ue,[e("span",null,q((p=b(w).user)==null?void 0:p.username),1),e("small",null,q((s=b(w).user)==null?void 0:s.role),1)]),a[10]||(a[10]=e("hr",{class:"header__dropdown-divider"},null,-1)),e("button",{class:"header__dropdown-item",onClick:D},[...a[9]||(a[9]=[e("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),e("polyline",{points:"16 17 21 12 16 7"}),e("line",{x1:"21",y1:"12",x2:"9",y2:"12"})],-1),E(" Logout ",-1)])])])):K("",!0)]}),_:1})])])]),L(be,{show:d.value,onClose:a[3]||(a[3]=p=>d.value=!1)},null,8,["show"])],64)}}}),Ne=J(Ae,[["__scopeId","data-v-f3e028bf"]]);export{Ne as H,de as u};