import{r as b,c as T,m as $e,o as Re,i as W,g as r,w as m,d,b as t,e as s,h as pe,a as u,j as y,af as ge,aR as fe,n as ze,ae as je,bt as mt,t as h,k as C,F as _,ac as Ie,s as vt,v as pt,aV as gt}from"./index-QAlcqU00.js";import{D as ft,g as ye,u as yt,a as ht,b as xt,c as J,d as Le,e as ve,f as Ue,h as bt}from"./useDocumentManagement-BJ6Z87hG.js";import{u as Ee}from"./useFormAutoSave-BrW9Wl2Q.js";import{F as kt,a as Dt}from"./FPPageHeader-CFIwZZgQ.js";import{F as Be}from"./FPModal-DMoPysvU.js";import{_ as Pe}from"./FormRestoreNotification-2Wflg1mH.js";import{F as Z}from"./FPInput-D5RURom0.js";import{F as B}from"./FPSelect-j7n_x8eB.js";import{F as Ct}from"./FPCheckbox-DcRYwN3n.js";import{F as Tt}from"./FPStats-DOY0PQQF.js";import{F as _t}from"./FPTable-CWvngIYd.js";import{F as Ae}from"./FPBadge-DvOitM1C.js";import{F as Me}from"./FPTabs-qq-Tmb7J.js";import"./FPCard-AB6NRXg5.js";function Vt(){const X=new ft,V=b([]),U=b(!1),f=b(null),Q=async()=>{U.value=!0,f.value=null;try{const n=await X.getTemplates();return V.value=n,n}catch(n){return f.value=n.message,V.value=[],console.error("Error loading document templates:",n),[]}finally{U.value=!1}},z=async n=>{if(f.value=null,!n||n.trim().length===0)return f.value="Document type is required",[];try{return await X.getTemplatesByType(n)}catch(v){return f.value=v.message,console.error("Error loading templates by type:",v),[]}},A=n=>(f.value=null,n.templateId?!n.title||n.title.trim().length===0?(f.value="Document title is required",!1):!0:(f.value="Template ID is required",!1)),P=async n=>{if(f.value=null,!A(n))return null;try{return await X.createFromTemplate(n)}catch(v){return f.value=v.message,console.error("Error creating document from template:",v),null}},K=n=>V.value.filter(v=>v.category===n),M=n=>V.value.find(v=>v.id===n)||null,G=(n,v)=>{const D=n.fields||[],F=Object.keys(v||{}),j=D.filter(H=>!F.includes(H)||!v[H]||v[H].toString().trim().length===0);return{isValid:j.length===0,missingFields:j}},k=()=>{const n=V.value.map(v=>v.category).filter(v=>v);return[...new Set(n)].sort()},i=(n,v)=>{const D={...v};return n.defaultValues&&Object.keys(n.defaultValues).forEach(F=>{D[F]||(D[F]=n.defaultValues[F])}),D},$=n=>n?V.value.filter(v=>v.type===n).sort((v,D)=>{const F=v.usageCount||0,j=D.usageCount||0;return F!==j?j-F:v.name.localeCompare(D.name)}):[],c=n=>{if(!n||n.trim().length===0)return V.value;const v=n.toLowerCase().trim();return V.value.filter(D=>D.name.toLowerCase().includes(v)||D.description&&D.description.toLowerCase().includes(v)||D.category&&D.category.toLowerCase().includes(v))},S=T(()=>V.value.length>0),R=T(()=>V.value.length),N=T(()=>k());return{templates:V,templatesLoading:U,error:f,hasTemplates:S,totalTemplates:R,templateCategories:N,loadTemplates:Q,loadTemplatesByType:z,createDocumentFromTemplate:P,getTemplatesByCategory:K,getTemplateById:M,validateTemplateReplacements:G,getTemplateCategories:k,processTemplateReplacements:i,getTemplateSuggestions:$,searchTemplates:c}}const wt={class:"space-y-4"},Ft={class:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-4"},St={key:0,class:"text-center py-8"},It={key:1,class:"text-center py-8"},Lt={key:2,class:"grid grid-cols-1 md:grid-cols-2 gap-4"},Ut=["onClick"],At={class:"flex items-start"},Mt={class:"flex-shrink-0"},$t=["value","onChange"],Rt={class:"ml-3 flex-1"},zt={class:"text-sm font-medium text-gray-900"},jt={class:"text-sm text-gray-500 mt-1"},Et={class:"flex items-center mt-2 space-x-2"},Bt={class:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-blue-100 text-blue-800"},Pt={key:0,class:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-gray-100 text-gray-800"},Nt={key:0,class:"space-y-4"},Ht={key:0,class:"space-y-4"},Ot={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},qt={key:0,class:"text-sm text-red-600"},Jt={key:1,class:"bg-gray-50 rounded-lg p-4"},Wt={class:"text-sm text-gray-600 space-y-1"},Xt={key:0,class:""},Kt={class:"bg-gray-50 border-t border-gray-200 px-6 py-4 -mx-6 -mb-6"},Gt={class:"flex items-center justify-between"},Yt={class:"flex items-center space-x-4"},Zt={key:0,class:"flex items-center space-x-2"},Qt={key:1,class:"flex items-center space-x-2"},el={class:"text-sm text-gray-600"},tl={class:"flex items-center space-x-3"},ll={__name:"DocumentTemplateModal",props:{open:{type:Boolean,default:!1}},emits:["close","document-created"],setup(X,{emit:V}){const U=X,f=V,{loadTemplates:Q,createDocumentFromTemplate:z,getTemplateById:A,validateTemplateReplacements:P,processTemplateReplacements:K,getTemplateCategories:M,searchTemplates:G,templates:k,templatesLoading:i,error:$}=Vt(),c=b({selectedTemplate:null,title:"",replacements:{}}),S=b({category:"",search:""}),R=b(!1),N=b(!1),n=b({}),v=b(!1),{hasUnsavedChanges:D,lastSaveTime:F,saveNow:j,restoreFormData:H,clearSavedData:le,hasSavedData:O,getSavedDataInfo:q,markUserInteraction:he,finishInitialization:ie}=Ee(c,{storageKey:"atlas_document_template_form",saveInterval:3e3,excludeFields:[]}),I=T(()=>c.value.selectedTemplate?A(c.value.selectedTemplate):null),E=T(()=>{const g=M();return[{value:"",label:"All Categories"},...g.map(o=>({value:o,label:o.charAt(0).toUpperCase()+o.slice(1)}))]}),ae=T(()=>{let g=k.value;return S.value.category&&(g=g.filter(o=>o.category===S.value.category)),S.value.search&&(g=G(S.value.search)),g}),xe=T(()=>c.value.selectedTemplate&&c.value.title&&!Object.keys(n.value).length),se=()=>{c.value={selectedTemplate:null,title:"",replacements:{}},S.value={category:"",search:""},n.value={},v.value=!1},ue=g=>{c.value.selectedTemplate=g,de(g)},de=g=>{const o=A(g);if(!o)return;const p={};o.fields&&o.fields.forEach(L=>{var ee;p[L]=((ee=o.defaultValues)==null?void 0:ee[L])||""}),c.value.replacements=p,Y(),oe()},Y=()=>{v.value=!0,he(),oe()},oe=()=>{if(n.value={},c.value.selectedTemplate||(n.value.selectedTemplate="Please select a template"),c.value.title||(n.value.title="Document title is required"),c.value.selectedTemplate&&I.value){const g=P(I.value,c.value.replacements);g.isValid||(n.value.replacements=`Missing required fields: ${g.missingFields.join(", ")}`)}return Object.keys(n.value).length===0},be=async()=>{if(oe()){R.value=!0;try{const g={templateId:c.value.selectedTemplate,title:c.value.title.trim(),replacements:K(I.value,c.value.replacements)},o=await z(g);o?(le(),f("document-created",o),f("close"),await Ie(),se()):$.value&&(n.value.general=$.value)}catch(g){console.error("Error creating document from template:",g),n.value.general="Failed to create document. Please try again."}finally{R.value=!1}}},ce=()=>{f("close")},ke=()=>{H(),v.value=!0},De=()=>{le()},me=g=>g.split(/(?=[A-Z])/).join(" ").replace(/^\w/,o=>o.toUpperCase()),Ce=g=>{const o=new Date,p=new Date(g),L=o-p,ee=Math.floor(L/1e3),ne=Math.floor(ee/60);return ne<1?"just now":ne===1?"1 minute ago":`${ne} minutes ago`};return $e(()=>U.open,g=>{g&&(se(),Q(),Ie(()=>{ie()}))}),Re(()=>{U.open&&(se(),Q(),ie())}),(g,o)=>(r(),W(Be,{open:X.open,title:"Create Document from Template",size:"xl",onClose:ce},{default:m(()=>[d(Pe,{show:s(O).value&&!v.value,"saved-data":s(q)(),onRestore:ke,onDismiss:De},null,8,["show","saved-data"]),t("form",{onSubmit:pe(be,["prevent"]),class:"space-y-6"},[t("div",wt,[o[7]||(o[7]=t("div",{class:"border-b border-gray-200 pb-4"},[t("h3",{class:"text-lg font-medium text-gray-900"},"Select Template"),t("p",{class:"mt-1 text-sm text-gray-500"},"Choose a template to create your document from")],-1)),t("div",Ft,[d(s(B),{modelValue:S.value.category,"onUpdate:modelValue":[o[0]||(o[0]=p=>S.value.category=p),Y],label:"Filter by Category",placeholder:"All categories",options:E.value},null,8,["modelValue","options"]),d(s(Z),{modelValue:S.value.search,"onUpdate:modelValue":o[1]||(o[1]=p=>S.value.search=p),label:"Search Templates",placeholder:"Search by name or description...",onInput:Y},{prepend:m(()=>o[4]||(o[4]=[t("svg",{class:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})],-1)])),_:1},8,["modelValue"])]),s(i)?(r(),u("div",St,o[5]||(o[5]=[t("div",{class:"animate-spin rounded-full h-8 w-8 border-b-2 border-indigo-600 mx-auto"},null,-1),t("p",{class:"mt-2 text-sm text-gray-500"},"Loading templates...",-1)]))):ae.value.length===0?(r(),u("div",It,o[6]||(o[6]=[t("svg",{class:"mx-auto h-12 w-12 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1),t("h3",{class:"mt-2 text-sm font-medium text-gray-900"},"No templates found",-1),t("p",{class:"mt-1 text-sm text-gray-500"},"Try adjusting your filters or search terms",-1)]))):(r(),u("div",Lt,[(r(!0),u(ge,null,fe(ae.value,p=>(r(),u("div",{key:p.id,class:ze(["relative rounded-lg border p-4 cursor-pointer hover:border-indigo-300 transition-colors",{"border-indigo-500 bg-indigo-50":c.value.selectedTemplate===p.id,"border-gray-200":c.value.selectedTemplate!==p.id}]),onClick:L=>ue(p.id)},[t("div",At,[t("div",Mt,[je(t("input",{type:"radio",value:p.id,"onUpdate:modelValue":o[2]||(o[2]=L=>c.value.selectedTemplate=L),class:"h-4 w-4 text-indigo-600 border-gray-300 focus:ring-indigo-500",onChange:L=>de(p.id)},null,40,$t),[[mt,c.value.selectedTemplate]])]),t("div",Rt,[t("h4",zt,h(p.name),1),t("p",jt,h(p.description),1),t("div",Et,[t("span",Bt,h(s(ye)(p.type)),1),p.category?(r(),u("span",Pt,h(p.category),1)):y("",!0)])])])],10,Ut))),128))]))]),c.value.selectedTemplate?(r(),u("div",Nt,[o[13]||(o[13]=t("div",{class:"border-b border-gray-200 pb-4"},[t("h3",{class:"text-lg font-medium text-gray-900"},"Document Details"),t("p",{class:"mt-1 text-sm text-gray-500"},"Provide details for your new document")],-1)),d(s(Z),{modelValue:c.value.title,"onUpdate:modelValue":o[3]||(o[3]=p=>c.value.title=p),label:"Document Title",placeholder:"Enter document title...",error:n.value.title,onInput:Y,required:""},null,8,["modelValue","error"]),I.value&&I.value.fields?(r(),u("div",Ht,[o[8]||(o[8]=t("h4",{class:"text-md font-medium text-gray-900"},"Template Fields",-1)),t("div",Ot,[(r(!0),u(ge,null,fe(I.value.fields,p=>(r(),u("div",{key:p},[d(s(Z),{modelValue:c.value.replacements[p],"onUpdate:modelValue":L=>c.value.replacements[p]=L,label:me(p),placeholder:`Enter ${me(p).toLowerCase()}...`,onInput:Y},null,8,["modelValue","onUpdate:modelValue","label","placeholder"])]))),128))]),n.value.replacements?(r(),u("div",qt,h(n.value.replacements),1)):y("",!0)])):y("",!0),I.value?(r(),u("div",Jt,[o[12]||(o[12]=t("h4",{class:"text-sm font-medium text-gray-900 mb-2"},"Template Information",-1)),t("div",Wt,[t("p",null,[o[9]||(o[9]=t("span",{class:"font-medium"},"Type:",-1)),C(" "+h(s(ye)(I.value.type)),1)]),t("p",null,[o[10]||(o[10]=t("span",{class:"font-medium"},"Category:",-1)),C(" "+h(I.value.category||"Uncategorized"),1)]),I.value.fields?(r(),u("p",Xt,[o[11]||(o[11]=t("span",{class:"font-medium"},"Required Fields:",-1)),C(" "+h(I.value.fields.length),1)])):y("",!0)])])):y("",!0)])):y("",!0),t("div",Kt,[t("div",Gt,[t("div",Yt,[s(D).value?(r(),u("div",Zt,o[14]||(o[14]=[t("div",{class:"w-2 h-2 bg-yellow-400 rounded-full animate-pulse"},null,-1),t("span",{class:"text-sm text-gray-600"},"Unsaved changes",-1)]))):s(F).value?(r(),u("div",Qt,[o[15]||(o[15]=t("div",{class:"w-2 h-2 bg-green-400 rounded-full"},null,-1)),t("span",el," Auto-saved "+h(Ce(s(F).value)),1)])):y("",!0),s(D).value?(r(),W(s(_),{key:2,type:"button",variant:"outline",size:"sm",onClick:s(j),loading:N.value},{default:m(()=>o[16]||(o[16]=[C(" Save Now ",-1)])),_:1,__:[16]},8,["onClick","loading"])):y("",!0)]),t("div",tl,[d(s(_),{type:"button",variant:"outline",onClick:ce,disabled:R.value},{default:m(()=>o[17]||(o[17]=[C(" Cancel ",-1)])),_:1,__:[17]},8,["disabled"]),d(s(_),{type:"submit",variant:"primary",loading:R.value,disabled:!xe.value},{default:m(()=>o[18]||(o[18]=[C(" Create Document ",-1)])),_:1,__:[18]},8,["loading","disabled"])])])])],32)]),_:1},8,["open"]))}},al={class:"p-6"},sl={class:"mb-6 grid grid-cols-1 md:grid-cols-5 gap-4"},ol={key:0,class:"flex items-center space-x-3"},nl={class:"font-medium text-gray-900"},rl={class:"text-sm text-gray-500"},il={key:0,class:"flex items-center space-x-2"},ul={key:0,class:"w-4 h-4 text-green-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},dl={key:1,class:"w-4 h-4 text-red-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},cl={key:2,class:"w-4 h-4 text-blue-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},ml={class:"text-sm"},vl={key:0,class:"text-sm"},pl={class:"font-medium text-gray-900"},gl={class:"text-gray-500"},fl={key:0,class:"text-sm"},yl={key:1,class:"text-gray-400"},hl={key:0,class:"flex items-center space-x-2"},xl={class:"flex items-center justify-between"},bl={class:"text-lg font-medium text-gray-900"},kl={class:"flex items-center space-x-2"},Dl={key:0,class:"text-xs text-amber-600 bg-amber-50 px-2 py-1 rounded"},Cl={key:1,class:"text-xs text-gray-500"},Tl={key:0,class:"space-y-4"},_l={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},Vl={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},wl={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},Fl={key:0,class:"flex flex-wrap gap-2 mt-2"},Sl=["onClick"],Il={key:1,class:"space-y-4"},Ll={class:"border-2 border-dashed border-gray-300 rounded-lg p-6 text-center hover:border-gray-400 transition-colors"},Ul={class:"mt-4"},Al={class:"cursor-pointer"},Ml={key:0,class:"mt-4 p-3 bg-gray-50 rounded-lg border"},$l={class:"flex items-center justify-between"},Rl={class:"flex items-center"},zl={class:"text-sm font-medium text-gray-900"},jl={class:"text-xs text-gray-500"},El={key:2,class:"space-y-4"},Bl={key:0,class:"space-y-4"},Pl={class:"space-y-2"},Nl={class:"flex items-center justify-between"},Hl={class:"flex items-center space-x-4"},Ol={key:0,class:"flex items-center text-sm text-gray-500"},ql={key:0,class:"w-4 h-4 mr-2 text-amber-500 animate-pulse",fill:"currentColor",viewBox:"0 0 20 20"},Jl={key:1,class:"w-4 h-4 mr-2 text-green-500",fill:"currentColor",viewBox:"0 0 20 20"},Wl={key:2},Xl={key:3},Kl={class:"flex space-x-2"},da={__name:"DocumentsListView",setup(X){const V=vt(),U=pt(),f=yt(),{loading:Q,documentStats:z}=ht(),A=b(!1),P=b(!1),K=b("all"),M=b(!1),G=b(!1),k=b("basic"),i=b({title:"",description:"",type:"",status:J.DRAFT,accessLevel:ve.INTERNAL,expirationDate:"",departmentId:null,tags:[],file:null,requiresApproval:!1,approvers:[]}),$=b(""),c=b({search:"",type:"",accessLevel:"",author:""}),S=b({page:0,size:10,total:0}),{hasUnsavedChanges:R,lastSaveTime:N,saveNow:n,restoreFormData:v,clearSavedData:D,hasSavedData:F,getSavedDataInfo:j,markUserInteraction:H,finishInitialization:le}=Ee(i,{storageKey:"atlas_document_form_data",saveInterval:3e3,excludeFields:["file"]}),O=b(!1),q=b(null),he=T(()=>f.filteredDocuments),ie=T(()=>{const a=z.value;return[{label:"Total",value:a.total||0,color:"blue"},{label:"Published",value:a.published||0,color:"green"},{label:"Draft",value:a.draft||0,color:"gray"},{label:"Pending Review",value:a.pendingReview||0,color:"yellow"},{label:"Expired",value:a.expired||0,color:"red"}]}),I=T(()=>[{key:"all",label:"All Documents",count:z.value.total||0},{key:"published",label:"Published",count:z.value.published||0},{key:"draft",label:"Drafts",count:z.value.draft||0},{key:"pending",label:"Pending Review",count:z.value.pendingReview||0},{key:"expired",label:"Expired",count:z.value.expired||0}]),E=[{key:"basic",label:"Basic Information",icon:"info"},{key:"file",label:"File Upload",icon:"document"},{key:"approval",label:"Approval",icon:"check"}],ae=T(()=>Object.values(xt).map(a=>({value:a,label:ye(a)}))),xe=T(()=>ae.value),se=T(()=>Object.values(J).map(a=>({value:a,label:Le(a).label}))),ue=T(()=>Object.values(ve).map(a=>({value:a,label:Ue(a).label}))),de=T(()=>ue.value),Y=T(()=>[{value:"",label:"All Authors"},{value:1,label:"John Doe"},{value:2,label:"Jane Smith"}]),oe=T(()=>[{value:null,label:"No Department"},{value:1,label:"IT Department"},{value:2,label:"HR Department"},{value:3,label:"Operations"}]),be=T(()=>[{value:1,label:"John Doe"},{value:2,label:"Jane Smith"},{value:3,label:"Bob Wilson"}]),ce=[{value:"reviewer",label:"Reviewer"},{value:"approver",label:"Approver"},{value:"manager",label:"Manager"}],ke=[{key:"title",label:"Document",sortable:!0,width:"30%"},{key:"type",label:"Type",sortable:!0,width:"15%"},{key:"status",label:"Status",sortable:!0,width:"12%"},{key:"accessLevel",label:"Access",sortable:!0,width:"12%"},{key:"author",label:"Author",sortable:!0,width:"15%"},{key:"expiration",label:"Expires",sortable:!0,width:"12%"},{key:"actions",label:"Actions",width:"10%",align:"center"}],De=T(()=>{if(!N.value)return"";const a=new Date,e=N.value,l=Math.floor((a-e)/(1e3*60));if(l<1)return"just now";if(l===1)return"1 minute ago";if(l<60)return`${l} minutes ago`;const x=Math.floor(l/60);return x===1?"1 hour ago":x<24?`${x} hours ago`:e.toLocaleDateString()}),me=()=>{v(),O.value=!1,q.value=null},Ce=()=>{D(),O.value=!1,q.value=null},g=()=>{!M.value&&F()&&(q.value=j(),O.value=!0)},o=a=>bt(a),p=a=>a?new Date(a).toLocaleDateString():"Never",L=a=>({policy:"blue",procedure:"green",manual:"purple",report:"yellow",contract:"red",certificate:"indigo",drawing:"pink",specification:"gray"})[a]||"gray",ee=a=>({draft:"gray",pending_review:"yellow",under_review:"blue",approved:"green",published:"green",archived:"gray",expired:"red",rejected:"red"})[a]||"gray",ne=a=>ye(a),Ne=a=>Le(a).label,He=a=>Ue(a).label,Oe=a=>{if(!a)return"text-gray-400";const e=new Date(a),l=new Date,x=new Date(l.getTime()+30*24*60*60*1e3);return e{M.value=!1,g(),F()||Fe(),A.value=!0,k.value="basic",setTimeout(()=>{le()},100)},qe=()=>{P.value=!0},Je=async a=>{P.value=!1,await _e(),U.push(`/documents/${a.id}`)},we=a=>{M.value=!0,We(a),A.value=!0,k.value="basic",F()&&(q.value=j(),O.value=!0),setTimeout(()=>{le()},100)},Te=()=>{R.value&&n(),A.value=!1,O.value=!1,q.value=null,Fe()},Fe=()=>{i.value={title:"",description:"",type:"",status:J.DRAFT,accessLevel:ve.INTERNAL,expirationDate:"",departmentId:null,tags:[],file:null,requiresApproval:!1,approvers:[]},$.value=""},We=a=>{i.value={id:a.id,title:a.title||"",description:a.description||"",type:a.type||"",status:a.status||J.DRAFT,accessLevel:a.accessLevel||ve.INTERNAL,expirationDate:a.expirationDate||"",departmentId:a.departmentId||null,tags:a.tags||[],file:null,requiresApproval:!1,approvers:[]}},Xe=()=>{const a=E.length,e=E.findIndex(l=>l.key===k.value);return Math.round((e+1)/a*100)},Ke=()=>{const a=E.findIndex(e=>e.key===k.value);a{const a=E.findIndex(e=>e.key===k.value);a>0&&(k.value=E[a-1].key)},w=()=>{H()},Ye=()=>{if(w(),$.value.includes(",")){const a=$.value.split(",").map(e=>e.trim()).filter(e=>e);i.value.tags=[...i.value.tags||[],...a],$.value=""}},Ze=a=>{i.value.tags.splice(a,1),w()},Qe=a=>{const e=a.target.files;e&&e[0]&&(i.value.file=e[0],w())},et=()=>{i.value.file=null,w()},tt=()=>{i.value.approvers.push({userId:null,role:"reviewer",order:i.value.approvers.length+1}),w()},lt=a=>{i.value.approvers.splice(a,1),i.value.approvers.forEach((e,l)=>{e.order=l+1}),w()},at=async()=>{G.value=!0;try{M.value?await f.updateDocument(i.value.id,i.value):await f.createDocument(i.value),D(),Te(),await _e()}catch(a){console.error("Error saving document:",a)}finally{G.value=!1}},st=a=>{Se(a)},Se=a=>{U.push(`/documents/${a.id}`)},ot=async a=>{try{const e=await f.downloadDocumentFile(a.id),l=window.URL.createObjectURL(e),x=a.createElement("a");x.style.display="none",x.href=l,x.download=`${a.title}.pdf`,a.body.appendChild(x),x.click(),window.URL.revokeObjectURL(l)}catch(e){console.error("Error downloading document:",e)}},nt=()=>{te()},te=()=>{f.updateFilters(c.value)},rt=()=>{c.value={search:"",type:"",accessLevel:"",author:""},te()},it=a=>{K.value=a;const e={all:"",published:J.PUBLISHED,draft:J.DRAFT,pending:J.PENDING_REVIEW,expired:J.EXPIRED};c.value.status=e[a]||"",te()},ut=({column:a,direction:e})=>{f.changeSorting(a,e)},dt=a=>{f.changePage(a)},_e=async()=>{await f.refreshDocuments()},ct=()=>{console.log("Export documents functionality")};return $e(i,()=>{A.value&&H()},{deep:!0}),Re(async()=>{await f.initializeDocuments();const a=V.query.edit;a&&setTimeout(()=>{const l=f.documents.find(x=>x.id===parseInt(a));l&&we(l),U.replace({path:"/documents"})},500),V.query.create==="true"&&setTimeout(()=>{Ve(),U.replace({path:"/documents"})},500)}),(a,e)=>(r(),W(kt,null,{header:m(()=>[d(Dt,{title:"Documents",description:"Manage documents, templates, versions, and approval workflows",breadcrumbs:[{text:"Documents",to:null}]},{actions:m(()=>[d(s(_),{variant:"outline",size:"sm",onClick:_e},{default:m(()=>e[17]||(e[17]=[t("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})],-1),C(" Refresh ",-1)])),_:1,__:[17]}),d(s(_),{variant:"outline",size:"sm",onClick:ct},{default:m(()=>e[18]||(e[18]=[t("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1),C(" Export ",-1)])),_:1,__:[18]}),d(s(_),{variant:"outline",size:"sm",onClick:qe},{default:m(()=>e[19]||(e[19]=[t("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1),C(" From Template ",-1)])),_:1,__:[19]}),d(s(_),{variant:"primary",size:"sm",onClick:Ve},{default:m(()=>e[20]||(e[20]=[t("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})],-1),C(" Add Document ",-1)])),_:1,__:[20]})]),stats:m(()=>[d(s(Tt),{stats:ie.value},null,8,["stats"])]),tabs:m(()=>[d(s(Me),{modelValue:K.value,"onUpdate:modelValue":e[0]||(e[0]=l=>K.value=l),tabs:I.value,onTabChange:it},null,8,["modelValue","tabs"])]),_:1})]),default:m(()=>[t("div",al,[t("div",sl,[d(s(Z),{modelValue:c.value.search,"onUpdate:modelValue":e[1]||(e[1]=l=>c.value.search=l),placeholder:"Search documents...",onInput:nt},{prepend:m(()=>e[21]||(e[21]=[t("svg",{class:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})],-1)])),_:1},8,["modelValue"]),d(s(B),{modelValue:c.value.type,"onUpdate:modelValue":[e[2]||(e[2]=l=>c.value.type=l),te],placeholder:"Filter by Type",options:ae.value},null,8,["modelValue","options"]),d(s(B),{modelValue:c.value.accessLevel,"onUpdate:modelValue":[e[3]||(e[3]=l=>c.value.accessLevel=l),te],placeholder:"Filter by Access Level",options:de.value},null,8,["modelValue","options"]),d(s(B),{modelValue:c.value.author,"onUpdate:modelValue":[e[4]||(e[4]=l=>c.value.author=l),te],placeholder:"Filter by Author",options:Y.value},null,8,["modelValue","options"]),d(s(_),{variant:"outline",size:"sm",onClick:rt},{default:m(()=>e[22]||(e[22]=[C(" Clear Filters ",-1)])),_:1,__:[22]})]),d(s(_t),{columns:ke,data:he.value,loading:s(Q),pagination:S.value,"empty-message":"No documents found",onSortChange:ut,onPageChange:dt,onRowClick:st},{title:m(({row:l})=>[l?(r(),u("div",ol,[e[23]||(e[23]=t("div",{class:"w-8 h-8 rounded bg-primary-100 flex items-center justify-center"},[t("svg",{class:"w-4 h-4 text-primary-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})])],-1)),t("div",null,[t("div",nl,h((l==null?void 0:l.title)||"Untitled Document"),1),t("div",rl,h((l==null?void 0:l.description)||"No description"),1)])])):y("",!0)]),type:m(({row:l})=>[l?(r(),W(s(Ae),{key:0,variant:L(l==null?void 0:l.type)},{default:m(()=>[C(h(ne(l==null?void 0:l.type)),1)]),_:2},1032,["variant"])):y("",!0)]),status:m(({row:l})=>[l?(r(),W(s(Ae),{key:0,variant:ee(l==null?void 0:l.status)},{default:m(()=>[C(h(Ne(l==null?void 0:l.status)),1)]),_:2},1032,["variant"])):y("",!0)]),accessLevel:m(({row:l})=>[l?(r(),u("div",il,[(l==null?void 0:l.accessLevel)==="public"?(r(),u("svg",ul,e[24]||(e[24]=[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9v-9m0-9v9"},null,-1)]))):(l==null?void 0:l.accessLevel)==="confidential"?(r(),u("svg",dl,e[25]||(e[25]=[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"},null,-1)]))):(r(),u("svg",cl,e[26]||(e[26]=[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"},null,-1)]))),t("span",ml,h(He(l==null?void 0:l.accessLevel)),1)])):y("",!0)]),author:m(({row:l})=>[l?(r(),u("div",vl,[t("div",pl,h((l==null?void 0:l.authorName)||"Unknown Author"),1),t("div",gl,h(p(l==null?void 0:l.createdAt)),1)])):y("",!0)]),expiration:m(({row:l})=>[l?(r(),u("div",fl,[l!=null&&l.expirationDate?(r(),u("div",{key:0,class:ze(Oe(l==null?void 0:l.expirationDate))},h(p(l==null?void 0:l.expirationDate)),3)):(r(),u("span",yl,"No expiration"))])):y("",!0)]),actions:m(({row:l})=>[l?(r(),u("div",hl,[d(s(_),{variant:"ghost",size:"xs",onClick:pe(x=>Se(l),["stop"]),title:"View Document"},{default:m(()=>e[27]||(e[27]=[t("svg",{class:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})],-1)])),_:2,__:[27]},1032,["onClick"]),d(s(_),{variant:"ghost",size:"xs",onClick:pe(x=>we(l),["stop"]),title:"Edit Document"},{default:m(()=>e[28]||(e[28]=[t("svg",{class:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})],-1)])),_:2,__:[28]},1032,["onClick"]),d(s(_),{variant:"ghost",size:"xs",onClick:pe(x=>ot(l),["stop"]),title:"Download Document"},{default:m(()=>e[29]||(e[29]=[t("svg",{class:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 10v6m0 0l-3-3m3 3l3-3M3 17V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z"})],-1)])),_:2,__:[29]},1032,["onClick"])])):y("",!0)]),_:1},8,["data","loading","pagination"])]),d(s(Be),{modelValue:A.value,"onUpdate:modelValue":e[15]||(e[15]=l=>A.value=l),size:"xl",onCancel:Te},{header:m(()=>[t("div",xl,[t("h3",bl,h(M.value?"Edit Document":"Create Document"),1),t("div",kl,[M.value&&a.hasUnsavedChanges?(r(),u("span",Dl," Auto-saving... ")):y("",!0),k.value!=="basic"?(r(),u("span",Cl,h(Xe())+"% complete ",1)):y("",!0)])])]),footer:m(()=>[t("div",Nl,[t("div",Hl,[s(R)||s(N)?(r(),u("div",Ol,[s(R)?(r(),u("svg",ql,e[45]||(e[45]=[t("path",{"fill-rule":"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z","clip-rule":"evenodd"},null,-1)]))):(r(),u("svg",Jl,e[46]||(e[46]=[t("path",{"fill-rule":"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z","clip-rule":"evenodd"},null,-1)]))),s(R)?(r(),u("span",Wl,"Auto-saving...")):s(N)?(r(),u("span",Xl,"Last saved "+h(De.value),1)):y("",!0)])):y("",!0),k.value!=="basic"?(r(),W(s(_),{key:1,variant:"outline",size:"sm",onClick:Ge},{default:m(()=>e[47]||(e[47]=[C(" ← Previous ",-1)])),_:1,__:[47]})):y("",!0)]),t("div",Kl,[d(s(_),{variant:"outline",onClick:Te},{default:m(()=>e[48]||(e[48]=[C(" Cancel ",-1)])),_:1,__:[48]}),k.value!=="approval"?(r(),W(s(_),{key:0,variant:"primary",onClick:Ke},{default:m(()=>e[49]||(e[49]=[C(" Next ",-1)])),_:1,__:[49]})):(r(),W(s(_),{key:1,variant:"primary",loading:G.value,onClick:at},{default:m(()=>[C(h(M.value?"Update Document":"Create Document"),1)]),_:1},8,["loading"]))])])]),default:m(()=>[d(s(Pe),{visible:O.value,"saved-data-info":q.value,onRestore:me,onDismiss:Ce},null,8,["visible","saved-data-info"]),d(s(Me),{modelValue:k.value,"onUpdate:modelValue":e[5]||(e[5]=l=>k.value=l),tabs:E,class:"mb-6"},null,8,["modelValue"]),k.value==="basic"?(r(),u("div",Tl,[t("div",_l,[d(s(Z),{modelValue:i.value.title,"onUpdate:modelValue":e[6]||(e[6]=l=>i.value.title=l),label:"Document Title",placeholder:"Enter document title",required:"",onInput:w},null,8,["modelValue"]),d(s(B),{modelValue:i.value.type,"onUpdate:modelValue":[e[7]||(e[7]=l=>i.value.type=l),w],label:"Document Type",options:xe.value,placeholder:"Select document type",required:""},null,8,["modelValue","options"])]),t("div",Vl,[d(s(B),{modelValue:i.value.status,"onUpdate:modelValue":[e[8]||(e[8]=l=>i.value.status=l),w],label:"Status",options:se.value,placeholder:"Select status",required:""},null,8,["modelValue","options"]),d(s(B),{modelValue:i.value.accessLevel,"onUpdate:modelValue":[e[9]||(e[9]=l=>i.value.accessLevel=l),w],label:"Access Level",options:ue.value,placeholder:"Select access level",required:""},null,8,["modelValue","options"])]),t("div",wl,[d(s(Z),{modelValue:i.value.expirationDate,"onUpdate:modelValue":e[10]||(e[10]=l=>i.value.expirationDate=l),label:"Expiration Date",type:"date",onInput:w},null,8,["modelValue"]),d(s(B),{modelValue:i.value.departmentId,"onUpdate:modelValue":[e[11]||(e[11]=l=>i.value.departmentId=l),w],label:"Department",options:oe.value,placeholder:"Select department"},null,8,["modelValue","options"])]),t("div",null,[e[30]||(e[30]=t("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Description",-1)),je(t("textarea",{"onUpdate:modelValue":e[12]||(e[12]=l=>i.value.description=l),placeholder:"Brief description of the document...",rows:"3",class:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm",onInput:w},null,544),[[gt,i.value.description]])]),t("div",null,[e[32]||(e[32]=t("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Tags",-1)),d(s(Z),{modelValue:$.value,"onUpdate:modelValue":e[13]||(e[13]=l=>$.value=l),placeholder:"Add tags (comma separated)",onInput:Ye},null,8,["modelValue"]),i.value.tags&&i.value.tags.length>0?(r(),u("div",Fl,[(r(!0),u(ge,null,fe(i.value.tags,(l,x)=>(r(),u("span",{key:x,class:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800"},[C(h(l)+" ",1),t("button",{type:"button",class:"ml-1.5 inline-flex items-center justify-center w-4 h-4 rounded-full hover:bg-blue-200",onClick:re=>Ze(x)},e[31]||(e[31]=[t("svg",{class:"w-2 h-2",stroke:"currentColor",fill:"none",viewBox:"0 0 8 8"},[t("path",{"stroke-linecap":"round",d:"m1 1 6 6m0-6-6 6"})],-1)]),8,Sl)]))),128))])):y("",!0)])])):y("",!0),k.value==="file"?(r(),u("div",Il,[t("div",null,[e[38]||(e[38]=t("label",{class:"block text-sm font-medium text-gray-700 mb-2"}," Document File ",-1)),e[39]||(e[39]=t("p",{class:"text-sm text-gray-500 mb-3"}," Upload the main document file (PDF, Word, etc.) ",-1)),t("div",Ll,[e[34]||(e[34]=t("svg",{class:"mx-auto h-12 w-12 text-gray-400",stroke:"currentColor",fill:"none",viewBox:"0 0 48 48"},[t("path",{d:"M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)),t("div",Ul,[t("label",Al,[e[33]||(e[33]=t("span",{class:"mt-2 block text-sm font-medium text-gray-900"}," Drop file here or click to upload ",-1)),t("input",{type:"file",class:"sr-only",accept:".pdf,.doc,.docx,.txt,.rtf",onChange:Qe},null,32)])]),e[35]||(e[35]=t("p",{class:"mt-2 text-xs text-gray-500"}," PDF, DOC, DOCX, TXT, RTF up to 100MB ",-1))]),i.value.file?(r(),u("div",Ml,[t("div",$l,[t("div",Rl,[e[36]||(e[36]=t("svg",{class:"w-5 h-5 text-gray-400 mr-3",fill:"currentColor",viewBox:"0 0 20 20"},[t("path",{"fill-rule":"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4zm2 6a1 1 0 011-1h6a1 1 0 110 2H7a1 1 0 01-1-1zm1 3a1 1 0 100 2h6a1 1 0 100-2H7z","clip-rule":"evenodd"})],-1)),t("div",null,[t("span",zl,h(i.value.file.name),1),t("div",jl,h(o(i.value.file.size)),1)])]),d(s(_),{variant:"ghost",size:"sm",onClick:et,class:"text-red-600 hover:text-red-800"},{default:m(()=>e[37]||(e[37]=[t("svg",{class:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})],-1)])),_:1,__:[37]})])])):y("",!0)])])):y("",!0),k.value==="approval"?(r(),u("div",El,[t("div",null,[e[40]||(e[40]=t("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Approval Required",-1)),d(s(Ct),{modelValue:i.value.requiresApproval,"onUpdate:modelValue":e[14]||(e[14]=l=>i.value.requiresApproval=l),label:"This document requires approval before publishing",onChange:w},null,8,["modelValue"])]),i.value.requiresApproval?(r(),u("div",Bl,[t("div",null,[e[43]||(e[43]=t("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Approvers",-1)),e[44]||(e[44]=t("p",{class:"text-sm text-gray-500 mb-3"}," Add users who need to approve this document ",-1)),t("div",Pl,[(r(!0),u(ge,null,fe(i.value.approvers,(l,x)=>(r(),u("div",{key:x,class:"flex items-center space-x-2"},[d(s(B),{modelValue:l.userId,"onUpdate:modelValue":[re=>l.userId=re,w],placeholder:"Select approver",options:be.value,class:"flex-1"},null,8,["modelValue","onUpdate:modelValue","options"]),d(s(B),{modelValue:l.role,"onUpdate:modelValue":[re=>l.role=re,w],placeholder:"Role",options:ce,class:"w-32"},null,8,["modelValue","onUpdate:modelValue"]),d(s(_),{variant:"ghost",size:"sm",onClick:re=>lt(x),class:"text-red-600"},{default:m(()=>e[41]||(e[41]=[t("svg",{class:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})],-1)])),_:2,__:[41]},1032,["onClick"])]))),128))]),d(s(_),{variant:"outline",size:"sm",onClick:tt,class:"mt-2"},{default:m(()=>e[42]||(e[42]=[t("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})],-1),C(" Add Approver ",-1)])),_:1,__:[42]})])])):y("",!0)])):y("",!0)]),_:1},8,["modelValue"]),d(ll,{open:P.value,onClose:e[16]||(e[16]=l=>P.value=!1),onDocumentCreated:Je},null,8,["open"])]),_:1}))}};export{da as default};