import{d as J,n as ee,p as ue,o as r,c as i,F as W,m as X,a as e,q as Y,t as j,f,T as ce,g as p,s as le,b as N,r as _,j as te,h as w,l as y,k as ie,x as ve,y as pe,e as ne,v as ae,w as re}from"./index-D2fAAQJ2.js";import{u as oe}from"./projects-CWhQXAJL.js";import{u as fe,H as he}from"./Header-BawqVjtJ.js";import{_ as Z,B as C}from"./Button-D-QrZfPJ.js";import{M as O}from"./Modal-C7dh6Uqe.js";const _e={class:"tree"},me=["onClick"],ge=["onClick"],ye={key:1,class:"tree__icon"},we={class:"tree__label"},ke=J({__name:"TreeView",props:{nodes:{}},emits:["node-click"],setup(E,{emit:D}){const P=E,n=D,a=_(new Set);ee(()=>P.nodes,v=>{v.forEach(o=>{o.type==="folder"&&a.value.add(o.id)})},{immediate:!0});function x(v,o){o.stopPropagation(),a.value.has(v.id)?a.value.delete(v.id):a.value.add(v.id)}function k(v){n("node-click",v)}return(v,o)=>{const m=ue("TreeView",!0);return r(),i("ul",_e,[(r(!0),i(W,null,X(E.nodes,d=>(r(),i("li",{key:d.id,class:"tree__item"},[e("div",{class:Y(["tree__node",{"tree__node--folder":d.type==="folder"}]),onClick:$=>k(d)},[d.type==="folder"?(r(),i("button",{key:0,class:"tree__toggle",onClick:$=>x(d,$)},[(r(),i("svg",{class:Y(["tree__arrow",{"tree__arrow--expanded":a.value.has(d.id)}]),width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[...o[1]||(o[1]=[e("path",{d:"m9 18 6-6-6-6"},null,-1)])],2))],8,ge)):(r(),i("span",ye,[...o[2]||(o[2]=[e("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e("polyline",{points:"14 2 14 8 20 8"})],-1)])])),e("span",we,j(d.name),1)],10,me),f(ce,{name:"expand"},{default:p(()=>{var $;return[d.type==="folder"&&a.value.has(d.id)&&(($=d.children)!=null&&$.length)?(r(),le(m,{key:0,nodes:d.children,class:"tree__children",onNodeClick:o[0]||(o[0]=g=>n("node-click",g))},null,8,["nodes"])):N("",!0)]}),_:2},1024)]))),128))])}}}),xe=Z(ke,[["__scopeId","data-v-e9acf25c"]]),Ce={class:"sidebar"},$e={key:0,class:"sidebar__content"},je={class:"sidebar__project"},be={class:"sidebar__project-name"},Me={key:0,class:"sidebar__project-desc"},Pe={class:"sidebar__actions"},Ve={class:"sidebar__tree"},De={key:1,class:"sidebar__empty"},Fe=J({__name:"Sidebar",emits:["create-folder","create-document"],setup(E,{emit:D}){const P=te(),n=oe(),a=D;function x(v){v.type==="document"&&P.push(`/documents/${v.id}`)}function k(){P.push("/dashboard")}return(v,o)=>(r(),i("aside",Ce,[e("div",{class:"sidebar__header"},[e("button",{class:"sidebar__back",onClick:k},[...o[2]||(o[2]=[e("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("path",{d:"m15 18-6-6 6-6"})],-1),w(" All Projects ",-1)])])]),y(n).currentProject?(r(),i("div",$e,[e("div",je,[e("h2",be,j(y(n).currentProject.name),1),y(n).currentProject.description?(r(),i("p",Me,j(y(n).currentProject.description),1)):N("",!0)]),e("div",Pe,[f(C,{size:"sm",variant:"ghost",onClick:o[0]||(o[0]=m=>a("create-folder"))},{default:p(()=>[...o[3]||(o[3]=[e("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"}),e("line",{x1:"12",y1:"11",x2:"12",y2:"17"}),e("line",{x1:"9",y1:"14",x2:"15",y2:"14"})],-1),w(" New Folder ",-1)])]),_:1}),f(C,{size:"sm",variant:"ghost",onClick:o[1]||(o[1]=m=>a("create-document"))},{default:p(()=>[...o[4]||(o[4]=[e("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e("polyline",{points:"14 2 14 8 20 8"}),e("line",{x1:"12",y1:"11",x2:"12",y2:"17"}),e("line",{x1:"9",y1:"14",x2:"15",y2:"14"})],-1),w(" New Doc ",-1)])]),_:1})]),e("div",Ve,[f(xe,{nodes:y(n).treeNodes,onNodeClick:x},null,8,["nodes"])])])):(r(),i("div",De,[...o[5]||(o[5]=[e("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[e("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})],-1),e("p",null,"Select a project to view its contents",-1)])]))]))}}),Ne=Z(Fe,[["__scopeId","data-v-f979c4be"]]),ze={class:"graph-view"},Be={class:"graph-view__header"},Se={class:"graph-view__controls"},Re={class:"graph-view__depth"},Ee={key:0,class:"graph-view__stats"},He={key:0,class:"graph-view__stat--warning"},Te={key:0,class:"graph-view__loading"},Ie={key:1,class:"graph-view__error"},Le=["width","height"],Ge={class:"graph-view__edges"},Ue=["d"],Ae={class:"graph-view__nodes"},qe=["transform","onClick"],Oe={key:3,class:"graph-view__empty"},We=J({__name:"GraphView",props:{projectId:{}},emits:["close"],setup(E){const D=E,P=te(),n=oe(),a=_(null),x=_(!1),k=_(null),v=_(2),o=_(new Map),m=_(800),d=_(600),$=_(null),g=_(null);async function b(){x.value=!0,k.value=null;try{a.value=await n.fetchProjectGraph(D.projectId,v.value),H(),G()}catch(h){k.value=h instanceof Error?h.message:"Failed to load graph"}finally{x.value=!1}}function H(){if(!a.value)return;const h=m.value/2,u=d.value/2,s=Math.min(m.value,d.value)*.35,t=new Map;a.value.nodes.forEach((l,T)=>{const q=2*Math.PI*T/a.value.nodes.length;t.set(l.id,{id:l.id,title:l.title,x:h+s*Math.cos(q),y:u+s*Math.sin(q),vx:0,vy:0})}),o.value=t}function G(h=150){if(a.value)for(let u=0;u{g.value&&(m.value=g.value.clientWidth,d.value=g.value.clientHeight,z=new ResizeObserver(A),z.observe(g.value)),await b()}),ve(()=>{z==null||z.disconnect()}),ee(v,()=>{b()}),(h,u)=>(r(),i("div",ze,[e("div",Be,[u[2]||(u[2]=e("h2",{class:"graph-view__title"},"Project Graph",-1)),e("div",Se,[e("div",Re,[u[0]||(u[0]=e("span",{class:"graph-view__depth-label"},"Depth:",-1)),(r(),i(W,null,X([1,2,3],s=>f(C,{key:s,variant:v.value===s?"primary":"ghost",size:"sm",onClick:t=>v.value=s},{default:p(()=>[w(j(s),1)]),_:2},1032,["variant","onClick"])),64))]),f(C,{variant:"ghost",size:"sm",onClick:b},{default:p(()=>[...u[1]||(u[1]=[e("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("path",{d:"M23 4v6h-6"}),e("path",{d:"M1 20v-6h6"}),e("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})],-1),w(" Refresh ",-1)])]),_:1})])]),a.value?(r(),i("div",Ee,[e("span",null,j(a.value.stats.total_documents)+" documents",1),e("span",null,j(a.value.stats.total_references)+" references",1),a.value.stats.orphaned_documents>0?(r(),i("span",He,j(a.value.stats.orphaned_documents)+" orphaned ",1)):N("",!0)])):N("",!0),e("div",{ref_key:"containerRef",ref:g,class:"graph-view__canvas"},[x.value?(r(),i("div",Te,[...u[3]||(u[3]=[e("div",{class:"graph-view__spinner"},null,-1),w(" Loading graph... ",-1)])])):k.value?(r(),i("div",Ie,j(k.value),1)):a.value&&o.value.size>0?(r(),i("svg",{key:2,ref_key:"svgRef",ref:$,width:m.value,height:d.value,class:"graph-view__svg"},[e("g",Ge,[(r(!0),i(W,null,X(a.value.edges,s=>(r(),i("path",{key:`${s.source}-${s.target}`,d:Q(s.source,s.target),class:"graph-view__edge"},null,8,Ue))),128))]),e("g",Ae,[(r(!0),i(W,null,X(o.value,([s,t])=>(r(),i("g",{key:s,class:"graph-view__node",transform:`translate(${t.x}, ${t.y})`,onClick:l=>U(s)},[u[4]||(u[4]=e("circle",{r:"24",class:"graph-view__node-circle"},null,-1)),u[5]||(u[5]=e("text",{class:"graph-view__node-icon","text-anchor":"middle","dominant-baseline":"central",dy:"0.05em"},"📄",-1)),e("title",null,j(t.title),1)],8,qe))),128))])],8,Le)):a.value&&a.value.nodes.length===0?(r(),i("div",Oe," No documents in this project yet. ")):N("",!0)],512),u[6]||(u[6]=e("div",{class:"graph-view__legend"},[e("span",null,"Click a node to open the document")],-1))]))}}),Xe=Z(We,[["__scopeId","data-v-fc6c0833"]]),Ye={class:"layout"},Je={class:"layout__body"},Ze={class:"layout__content"},Ke={key:0,class:"loading"},Qe={key:1,class:"error"},et={key:2,class:"project"},tt={class:"project__welcome"},ot={class:"project__title"},st={key:0,class:"project__desc"},nt={class:"project__actions"},at={class:"form__field"},rt={class:"form__field"},lt={class:"form__field"},it={class:"export-formats"},dt=J({__name:"ProjectView",setup(E){const D=pe(),P=te(),n=oe(),a=fe(),x=_(!1),k=_(!1),v=_(""),o=_(""),m=_(null),d=_(!1),$=_(!1),g=_(!1),b=_("zip"),H=_(!1);ie(async()=>{const s=D.params.id;await n.fetchProject(s)}),ee(()=>D.params.id,async s=>{s&&await n.fetchProject(s)});function G(s){P.push(`/documents/${s}`)}function K(){m.value=null,x.value=!0}function Q(){m.value=null,k.value=!0}async function U(){if(!(!v.value.trim()||!n.currentProject)){d.value=!0;try{await n.createFolder(n.currentProject.id,v.value.trim(),m.value),x.value=!1,v.value=""}catch(s){console.error("Failed to create folder:",s)}finally{d.value=!1}}}async function A(){if(!(!o.value.trim()||!n.currentProject)){d.value=!0;try{const s=await a.createDocument(n.currentProject.id,o.value.trim(),"",m.value);k.value=!1,o.value="",await n.fetchProjectTree(n.currentProject.id),G(s.id)}catch(s){console.error("Failed to create document:",s)}finally{d.value=!1}}}function z(){$.value=!0}function h(){g.value=!0}async function u(){if(n.currentProject){H.value=!0;try{const s=await n.exportProject(n.currentProject.id,b.value),t=URL.createObjectURL(s),l=document.createElement("a"),T=n.currentProject.name.replace(/[^a-z0-9]/gi,"_");l.href=t,l.download=`${T}.${b.value}`,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(t),g.value=!1}catch(s){console.error("Export failed:",s)}finally{H.value=!1}}}return(s,t)=>(r(),i("div",Ye,[f(he),e("div",Je,[f(Ne,{onCreateFolder:K,onCreateDocument:Q}),e("main",Ze,[y(n).loading?(r(),i("div",Ke,[...t[13]||(t[13]=[e("div",{class:"loading__spinner"},null,-1),e("p",null,"Loading project...",-1)])])):y(n).error?(r(),i("div",Qe,[e("p",null,j(y(n).error),1),f(C,{variant:"secondary",onClick:t[0]||(t[0]=l=>y(P).push("/dashboard"))},{default:p(()=>[...t[14]||(t[14]=[w(" Back to Dashboard ",-1)])]),_:1})])):y(n).currentProject?(r(),i("div",et,[e("div",tt,[e("h1",ot,j(y(n).currentProject.name),1),y(n).currentProject.description?(r(),i("p",st,j(y(n).currentProject.description),1)):N("",!0),t[17]||(t[17]=e("p",{class:"project__hint"}," Select a document from the sidebar or create a new one to get started. ",-1)),e("div",nt,[f(C,{variant:"secondary",onClick:z},{default:p(()=>[...t[15]||(t[15]=[e("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("circle",{cx:"18",cy:"5",r:"3"}),e("circle",{cx:"6",cy:"12",r:"3"}),e("circle",{cx:"18",cy:"19",r:"3"}),e("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"}),e("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"})],-1),w(" View Graph ",-1)])]),_:1}),f(C,{variant:"secondary",onClick:h},{default:p(()=>[...t[16]||(t[16]=[e("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e("polyline",{points:"7 10 12 15 17 10"}),e("line",{x1:"12",y1:"15",x2:"12",y2:"3"})],-1),w(" Export ",-1)])]),_:1})])])])):N("",!0)])]),f(O,{show:x.value,title:"Create New Folder",onClose:t[3]||(t[3]=l=>x.value=!1)},{footer:p(()=>[f(C,{variant:"secondary",onClick:t[2]||(t[2]=l=>x.value=!1)},{default:p(()=>[...t[19]||(t[19]=[w("Cancel",-1)])]),_:1}),f(C,{variant:"primary",loading:d.value,onClick:U},{default:p(()=>[...t[20]||(t[20]=[w("Create Folder",-1)])]),_:1},8,["loading"])]),default:p(()=>[e("form",{onSubmit:re(U,["prevent"])},[e("div",at,[t[18]||(t[18]=e("label",{for:"folder-name",class:"form__label"},"Folder Name",-1)),ne(e("input",{id:"folder-name","onUpdate:modelValue":t[1]||(t[1]=l=>v.value=l),type:"text",class:"form__input",placeholder:"My Folder",autofocus:""},null,512),[[ae,v.value]])])],32)]),_:1},8,["show"]),f(O,{show:k.value,title:"Create New Document",onClose:t[6]||(t[6]=l=>k.value=!1)},{footer:p(()=>[f(C,{variant:"secondary",onClick:t[5]||(t[5]=l=>k.value=!1)},{default:p(()=>[...t[22]||(t[22]=[w("Cancel",-1)])]),_:1}),f(C,{variant:"primary",loading:d.value,onClick:A},{default:p(()=>[...t[23]||(t[23]=[w("Create Document",-1)])]),_:1},8,["loading"])]),default:p(()=>[e("form",{onSubmit:re(A,["prevent"])},[e("div",rt,[t[21]||(t[21]=e("label",{for:"doc-name",class:"form__label"},"Document Title",-1)),ne(e("input",{id:"doc-name","onUpdate:modelValue":t[4]||(t[4]=l=>o.value=l),type:"text",class:"form__input",placeholder:"Untitled Document",autofocus:""},null,512),[[ae,o.value]])])],32)]),_:1},8,["show"]),f(O,{show:$.value,title:"",size:"lg",onClose:t[8]||(t[8]=l=>$.value=!1)},{default:p(()=>[y(n).currentProject?(r(),le(Xe,{key:0,"project-id":y(n).currentProject.id,onClose:t[7]||(t[7]=l=>$.value=!1)},null,8,["project-id"])):N("",!0)]),_:1},8,["show"]),f(O,{show:g.value,title:"Export Project",onClose:t[12]||(t[12]=l=>g.value=!1)},{footer:p(()=>[f(C,{variant:"secondary",onClick:t[11]||(t[11]=l=>g.value=!1)},{default:p(()=>[...t[27]||(t[27]=[w("Cancel",-1)])]),_:1}),f(C,{variant:"primary",loading:H.value,onClick:u},{default:p(()=>[...t[28]||(t[28]=[w("Download",-1)])]),_:1},8,["loading"])]),default:p(()=>[e("div",lt,[t[26]||(t[26]=e("label",{class:"form__label"},"Format",-1)),e("div",it,[e("button",{class:Y(["export-format",{"export-format--selected":b.value==="zip"}]),onClick:t[9]||(t[9]=l=>b.value="zip")},[...t[24]||(t[24]=[e("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})],-1),e("span",null,"ZIP Archive",-1),e("small",null,"Documents as .md files",-1)])],2),e("button",{class:Y(["export-format",{"export-format--selected":b.value==="json"}]),onClick:t[10]||(t[10]=l=>b.value="json")},[...t[25]||(t[25]=[e("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[e("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e("polyline",{points:"14 2 14 8 20 8"}),e("path",{d:"M8 13h2"}),e("path",{d:"M8 17h2"}),e("path",{d:"M14 13h2"}),e("path",{d:"M14 17h2"})],-1),e("span",null,"JSON",-1),e("small",null,"Full project with metadata",-1)])],2)])])]),_:1},8,["show"])]))}}),ht=Z(dt,[["__scopeId","data-v-ddea94bc"]]);export{ht as default};