1import{r as l,j as e}from"./trpc-vendor-D2Kf180F.js";import{t as m}from"./index-BOfmHuP3.js";import{u as W}from"./useAuth-BRKkxC1p.js";import{L as E}from"./router-vendor-zEfGuAyR.js";import"./react-vendor-COd4auuD.js";const A="#EC6608",F=["Handbook","Form","Policy","Academic Calendar","Guide","Fees","Attendance","Enrolment","Legal"],L=["Birkbeck","Wrexham","Northampton","BIL-wide","N/A"],B={title:"",category:"Handbook",subGroup:"BIL-wide",academicYear:"",fileUrl:"",fileKey:"",isExternal:0,sortOrder:0};function I({initial:v,onSave:k,onCancel:C,saving:a}){const[i,u]=l.useState(v),[S,h]=l.useState(!1),n=(r,o)=>u(g=>({...g,[r]:o})),w=l.useRef(null),[s,j]=l.useState(!1),[d,c]=l.useState(""),D=m.documents.uploadFile.useMutation(),R=async r=>{const o=r.target.files?.[0];if(o){if(o.size>20*1024*1024){c("File must be under 20 MB");return}c(""),j(!0);try{const g=new FileReader;g.onload=async U=>{const f=(U.target?.result).split(",")[1],y=await D.mutateAsync({base64:f,filename:o.name,mimeType:o.type||"application/pdf"});n("fileUrl",y.url),n("fileKey",y.key),h(!0),j(!1)},g.readAsDataURL(o)}catch{c("Upload failed â please try again"),j(!1)}}},p={width:"100%",padding:"8px 10px",border:"1px solid #d1d5db",borderRadius:"4px",fontSize:"14px",boxSizing:"border-box"},x={display:"block",fontSize:"12px",fontWeight:600,color:"#374151",marginBottom:"4px",textTransform:"uppercase",letterSpacing:"0.5px"};return e.jsxs("div",{style:{display:"grid",gap:"14px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:x,children:"Document Title *"}),e.jsx("input",{style:p,value:i.title,onChange:r=>n("title",r.target.value),placeholder:"e.g. Programme Handbook â LLB Law (Birkbeck)",required:!0})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:x,children:"Category *"}),e.jsx("select",{style:p,value:i.category,onChange:r=>n("category",r.target.value),children:F.map(r=>e.jsx("option",{value:r,children:r},r))})]}),e.jsxs("div",{children:[e.jsx("label",{style:x,children:"Sub-group"}),e.jsx("select",{style:p,value:i.subGroup,onChange:r=>n("subGroup",r.target.value),children:L.map(r=>e.jsx("option",{value:r,children:r},r))})]})]}),e.jsxs("div",{children:[e.jsx("label",{style:x,children:"Academic Year (optional)"}),e.jsx("input",{style:p,value:i.academicYear,onChange:r=>n("academicYear",r.target.value),placeholder:"e.g. 2025-26"})]}),e.jsxs("div",{children:[e.jsx("label",{style:x,children:"File *"}),e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center",flexWrap:"wrap"},children:[e.jsx("button",{type:"button",onClick:()=>w.current?.click(),disabled:s,style:{padding:"8px 14px",background:s?"#9ca3af":A,color:"white",border:"none",borderRadius:"4px",fontSize:"13px",fontWeight:600,cursor:s?"not-allowed":"pointer"},children:s?"Uploadingâ¦":"Upload PDF / DOCX"}),e.jsx("input",{ref:w,type:"file",accept:".pdf,.doc,.docx",style:{display:"none"},onChange:R}),e.jsx("span",{style:{fontSize:"12px",color:"#6b7280"},children:"or"}),e.jsx("input",{style:{...p,flex:1,minWidth:"200px"},value:i.fileUrl,onChange:r=>{n("fileUrl",r.target.value),n("fileKey","")},placeholder:"Paste external URL (e.g. https://...)"})]}),d&&e.jsx("p",{style:{color:"#dc2626",fontSize:"12px",marginTop:"4px"},children:d}),i.fileUrl&&!s&&e.jsxs("p",{style:{fontSize:"12px",color:"#059669",marginTop:"4px"},children:["â ",i.fileUrl.startsWith("https://bil-website-assets.s3")?"File uploaded to storage":"External URL set"]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("input",{type:"checkbox",id:"isExternal",checked:i.isExternal===1,onChange:r=>n("isExternal",r.target.checked?1:0)}),e.jsx("label",{htmlFor:"isExternal",style:{fontSize:"13px",color:"#374151"},children:"External link (hosted outside BIL â e.g. UK Government site)"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("input",{type:"checkbox",id:"refreshDate",checked:S,onChange:r=>h(r.target.checked)}),e.jsx("label",{htmlFor:"refreshDate",style:{fontSize:"13px",color:"#374151"},children:'Refresh "last updated" date to today (tick when replacing a file)'})]}),e.jsxs("div",{children:[e.jsx("label",{style:x,children:"Sort Order"}),e.jsx("input",{style:{...p,width:"80px"},type:"number",value:i.sortOrder,onChange:r=>n("sortOrder",parseInt(r.target.value)||0)})]}),e.jsxs("div",{style:{display:"flex",gap:"10px",paddingTop:"4px"},children:[e.jsx("button",{onClick:()=>k(i,S),disabled:a||s||!i.title||!i.fileUrl,style:{padding:"10px 20px",background:a?"#9ca3af":A,color:"white",border:"none",borderRadius:"4px",fontSize:"14px",fontWeight:600,cursor:a?"not-allowed":"pointer"},children:a?"Savingâ¦":"Save Document"}),e.jsx("button",{onClick:C,style:{padding:"10px 20px",background:"transparent",color:"#374151",border:"1px solid #d1d5db",borderRadius:"4px",fontSize:"14px",cursor:"pointer"},children:"Cancel"})]})]})}function M(){const{user:v,loading:k}=W(),[C,a]=l.useState(!1),[i,u]=l.useState(null),[S,h]=l.useState(!1),[n,w]=l.useState("all"),[s,j]=l.useState(!1),{data:d=[],refetch:c}=m.documents.listAll.useQuery(),D=m.documents.create.useMutation(),R=m.documents.update.useMutation(),p=m.documents.ar
1chive.useMutation(),x=m.documents.delete.useMutation();if(k)return e.jsx("div",{style:{minHeight:"100vh",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx("p",{style:{color:"#6b7280"},children:"Loadingâ¦"})});if(!v||v.role!=="admin")return window.location.replace("/admin/login"),null;const r=async(t,z)=>{h(!0);try{await D.mutateAsync({title:t.title,category:t.category,subGroup:t.subGroup,academicYear:t.academicYear||void 0,fileUrl:t.fileUrl,fileKey:t.fileKey||void 0,isExternal:t.isExternal,sortOrder:t.sortOrder,lastUpdatedAt:z?new Date().toISOString():void 0}),await c(),a(!1)}finally{h(!1)}},o=async(t,z)=>{if(i){h(!0);try{await R.mutateAsync({id:i.id,title:t.title,category:t.category,subGroup:t.subGroup,academicYear:t.academicYear||null,fileUrl:t.fileUrl,fileKey:t.fileKey||null,isExternal:t.isExternal,sortOrder:t.sortOrder,refreshLastUpdated:z}),await c(),u(null)}finally{h(!1)}}},g=async t=>{confirm(`${t.isArchived?"Restore":"Archive"} "${t.title}"?`)&&(await p.mutateAsync({id:t.id}),await c())},U=async t=>{confirm(`Permanently delete "${t.title}"? This cannot be undone.`)&&(await x.mutateAsync({id:t.id}),await c())},f=d.filter(t=>!(!s&&t.isArchived||n!=="all"&&t.category!==n)),y=new Date;y.setFullYear(y.getFullYear()-1);const b=t=>new Date(t.lastUpdatedAt)<y;return e.jsxs("div",{style:{minHeight:"100vh",background:"#f9fafb",fontFamily:"var(--font-body, sans-serif)"},children:[e.jsxs("div",{style:{background:"#1f2937",padding:"16px 32px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"24px"},children:[e.jsx(E,{href:"/admin/news",style:{color:"rgba(255,255,255,0.6)",textDecoration:"none",fontSize:"13px"},children:"â News CMS"}),e.jsx("h1",{style:{color:"white",fontSize:"18px",fontWeight:700,margin:0},children:"Document Library"})]}),e.jsxs("div",{style:{display:"flex",gap:"12px",alignItems:"center"},children:[e.jsx(E,{href:"/",style:{color:"rgba(255,255,255,0.6)",textDecoration:"none",fontSize:"13px"},children:"â Back to site"}),e.jsx("button",{onClick:()=>{a(!0),u(null)},style:{padding:"8px 16px",background:A,color:"white",border:"none",borderRadius:"4px",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:"+ Add Document"})]})]}),e.jsxs("div",{style:{maxWidth:"1200px",margin:"0 auto",padding:"32px 24px"},children:[(C||i)&&e.jsxs("div",{style:{background:"white",border:"1px solid #e5e7eb",borderRadius:"8px",padding:"24px",marginBottom:"28px",boxShadow:"0 2px 8px rgba(0,0,0,0.06)"},children:[e.jsx("h2",{style:{fontSize:"16px",fontWeight:700,marginBottom:"20px",color:"#111827"},children:i?"Edit Document":"Add New Document"}),e.jsx(I,{initial:i?{title:i.title,category:i.category,subGroup:i.subGroup,academicYear:i.academicYear??"",fileUrl:i.fileUrl,fileKey:i.fileKey??"",isExternal:i.isExternal,sortOrder:i.sortOrder}:B,onSave:i?o:r,onCancel:()=>{a(!1),u(null)},saving:S})]}),e.jsxs("div",{style:{display:"flex",gap:"12px",alignItems:"center",marginBottom:"20px",flexWrap:"wrap"},children:[e.jsxs("select",{value:n,onChange:t=>w(t.target.value),style:{padding:"7px 12px",border:"1px solid #d1d5db",borderRadius:"4px",fontSize:"13px",background:"white"},children:[e.jsx("option",{value:"all",children:"All categories"}),F.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",color:"#374151",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:s,onChange:t=>j(t.target.checked)}),"Show archived"]}),e.jsxs("span",{style:{fontSize:"13px",color:"#6b7280",marginLeft:"auto"},children:[f.length," document",f.length!==1?"s":""]})]}),d.filter(t=>!t.isArchived&&b(t)).length>0&&e.jsxs("div",{style:{background:"#fef3c7",border:"1px solid #f59e0b",borderRadius:"8px",padding:"12px 16px",marginBottom:"20px",fontSize:"13px",color:"#92400e"},children:["â ï¸ ",e.jsxs("strong",{children:[d.filter(t=>!t.isArchived&&b(t)).length," document",d.filter(t=>!t.isArchived&&b(t)).length!==1?"s":""]})," ",d.filter(t=>!t.isArchived&&b(t)).length!==1?"have":"has"," not been updated in over 12 months and may need reviewing."]}),e.jsx("div",{style:{background:"white",border:"1px solid #e5e7eb",borderRadius:"8px",overflow:"hidden"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:"13px"},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"#f3f4f6",borderBottom:"1px solid #e5e7eb"},children:[e.jsx("th",{style:{padding:"10px 14px",textAlign:"left",fontWeight:600,color:"#374151"},children:"Title"}),e.jsx("th",{style:{padding:"10px 14px",textAlign:"left",fontWeight:600,color:"#374151"},children:"Category"}),e.jsx("th",{style:{padding:"10px 14px",textAlign:"left",fontWeight:600,color:"#374151"},children:"Sub-group"}),e.jsx("th",{style:{padding:"10px 14px",textAlign:"left",fontWeight:600,color:"#374151"},children:"Last Updated"}),e.jsx("th",{style:{padding:"10px 14px",textAlign:"left",fontWeight:600,color:"#374151"},children:"Status"}),e.jsx("th",{style:{padding:"10px 14px",textAlign:"right",fontWeight:600,color:"#374151"},children:"Actions"})]})}),e.jsx("tbody",{children:f.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,style:{padding:"32px",textAlign:"center",color:"#9ca3af"},children:"No documents found"})}):f.map(t=>e.jsxs("tr",{style:{borderBottom:"1px solid #f3f4f6",opacity:t.isArchived?.5:1,background:b(t)&&!t.isArchived?"#fffbeb":"white"},children:[e.jsxs("td",{style:{padding:"10px 14px",maxWidth:"320px"},children:[e.jsx("a",{href:t.fileUrl,target:"_blank",rel:"noopener noreferrer",style:{color:A,textDecoration:"none",fontWeight:500},children:t.title}),t.isExternal===1&&e.jsx("span",{style:{marginLeft:"6px",fontSize:"10px",background:"#e0f2fe",color:"#0369a1",padding:"1px 5px",borderRadius:"3px"},children:"external"}),b(t)&&!t.isArchived&&e.jsx("span",{style:{marginLeft:"6px",fontSize:"10px",background:"#fef3c7",color:"#92400e",padding:"1px 5px",borderRadius:"3px"},children:"stale"})]}),e.jsx("td",{style:{padding:"10px 14px",color:"#374151"},children:t.category}),e.jsx("td",{style:{padding:"10px 14px",color:"#6b7280"},children:t.subGroup}),e.jsx("td",{style:{padding:"10px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:new Date(t.lastUpdatedAt).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}),e.jsx("td",{style:{padding:"10px 14px"},children:e.jsx("span",{style:{fontSize:"11px",fontWeight:600,padding:"2px 7px",borderRadius:"4px",background:t.isArchived?"#f3f4f6":"#dcfce7",color:t.isArchived?"#6b7280":"#166534"},children:t.isArchived?"Archived":"Active"})}),e.jsxs("td",{style:{padding:"10px 14px",textAlign:"right",whiteSpace:"nowrap"},children:[e.jsx("button",{onClick:()=>u(t),style:{marginRight:"8px",fontSize:"12px",color:"#374151",background:"none",border:"1px solid #d1d5db",borderRadius:"4px",padding:"3px 8px",cursor:"pointer"},children:"Edit"}),e.jsx("button",{onClick:()=>g(t),style:{marginRight:"8px",fontSize:"12px",color:t.isArchived?"#059669":"#d97706",background:"none",border:"1px solid #d1d5db",borderRadius:"4px",padding:"3px 8px",cursor:"pointer"}
1,children:t.isArchived?"Restore":"Archive"}),e.jsx("button",{onClick:()=>U(t),style:{fontSize:"12px",color:"#dc2626",background:"none",border:"1px solid #fca5a5",borderRadius:"4px",padding:"3px 8px",cursor:"pointer"},children:"Delete"})]})]},t.id))})]})})]})]})}export{M 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.