import{y as B,z as M,r as v,d as V,j as U,u as H,p as N,o as $,c as b,a as e,f as S,g as T,w as A,e as j,v as q,t as w,l as y,T as E,h as F,b as z}from"./index-BgrozaY3.js";import{_ as K}from"./Button-DZq_qu8h.js";const I=B("documents",()=>{const n=v(null),d=v([]),l=v(!1),u=v(null),c=v(!1),r=M();async function k(t){l.value=!0,u.value=null;try{n.value=await r.get(`/documents/${t}`)}catch(s){throw u.value=s instanceof Error?s.message:"Failed to fetch document",s}finally{l.value=!1}}async function D(t,s,o="",i=null){const g=i?`/folders/${i}/documents`:`/projects/${t}/documents`;return await r.post(g,{title:s,content:o})}async function a(t,s,o){var C;const i={title:s};o!==void 0&&(i.folder_id=o);const g=await r.put(`/documents/${t}`,i);return((C=n.value)==null?void 0:C.id)===t&&(n.value=g),g}async function x(t,s){var o;c.value=!0;try{await r.put(`/documents/${t}/content`,{content:s}),((o=n.value)==null?void 0:o.id)===t&&(n.value.content=s)}finally{c.value=!1}}async function f(t){var s;await r.delete(`/documents/${t}`),((s=n.value)==null?void 0:s.id)===t&&(n.value=null)}async function _(){try{d.value=await r.get("/tags")}catch(t){console.error("Failed to fetch tags:",t)}}async function p(t,s){const o=await r.post("/tags",{name:t,color:s});return d.value.push(o),o}async function h(t,s){var o;await r.put(`/documents/${t}/tags`,{tag_ids:s}),((o=n.value)==null?void 0:o.id)===t&&(n.value.tags=d.value.filter(i=>s.includes(i.id)))}async function m(t,s){var o;await r.delete(`/documents/${t}/tags/${s}`),((o=n.value)==null?void 0:o.id)===t&&(n.value.tags=n.value.tags.filter(i=>i.id!==s))}return{currentDocument:n,tags:d,loading:l,error:u,saving:c,fetchDocument:k,createDocument:D,updateDocument:a,updateDocumentContent:x,deleteDocument:f,fetchTags:_,createTag:p,assignTags:h,removeTag:m}}),L={class:"header"},Q={class:"header__left"},R={class:"header__center"},G={class:"header__right"},J={class:"header__avatar"},O={class:"header__username"},P={key:0,class:"header__dropdown"},W={class:"header__dropdown-item header__dropdown-item--info"},X=V({__name:"Header",setup(n){const d=U(),l=H(),u=v(""),c=v(!1);function r(){u.value.trim()&&d.push({name:"dashboard",query:{q:u.value}})}function k(){l.logout(),d.push("/login")}return(D,a)=>{var f,_,p;const x=N("router-link");return $(),b("header",L,[e("div",Q,[S(x,{to:"/dashboard",class:"header__logo"},{default:T(()=>[...a[2]||(a[2]=[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",R,[e("form",{class:"header__search",onSubmit:A(r,["prevent"])},[a[3]||(a[3]=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)),j(e("input",{"onUpdate:modelValue":a[0]||(a[0]=h=>u.value=h),type:"text",placeholder:"Search documents...",class:"header__search-input"},null,512),[[q,u.value]]),a[4]||(a[4]=e("kbd",{class:"header__kbd"},"⌘K",-1))],32)]),e("div",G,[e("div",{class:"header__user",onClick:a[1]||(a[1]=h=>c.value=!c.value)},[e("div",J,w(((_=(f=y(l).user)==null?void 0:f.username)==null?void 0:_.charAt(0).toUpperCase())||"U"),1),e("span",O,w(((p=y(l).user)==null?void 0:p.username)||"User"),1),a[7]||(a[7]=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)),S(E,{name:"fade"},{default:T(()=>{var h,m;return[c.value?($(),b("div",P,[e("div",W,[e("span",null,w((h=y(l).user)==null?void 0:h.username),1),e("small",null,w((m=y(l).user)==null?void 0:m.role),1)]),a[6]||(a[6]=e("hr",{class:"header__dropdown-divider"},null,-1)),e("button",{class:"header__dropdown-item",onClick:k},[...a[5]||(a[5]=[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),F(" Logout ",-1)])])])):z("",!0)]}),_:1})])])])}}}),ee=K(X,[["__scopeId","data-v-0d1f0999"]]);export{ee as H,I as u};
