1import{r as _,ak as k,s as T,j as e,I as g,a1 as M,g as v,u as O,w as R}from"./index-CLtGP32Z.js";import{u as I}from"./useMutation-BvxM86re.js";import{o as B,s as d,a as w,n as N,b as Q,u as Y,t as H}from"./types-BMHrb74q.js";import{s as J,t as q,F as K,a as n,b as l,c as i,d as o,e as c,T as D,D as L}from"./DeleteConfirmDialog-DE-kX4hh.js";import{d as E,u as U}from"./index-mC58iiqr.js";import{D as V,a as z,b as $,c as G,d as W}from"./dialog-x1Gc4z_6.js";import{S as X}from"./switch-BuJuE40j.js";import{S as Z,a as ee,b as se,c as re,d as y}from"./select-Bq2l4yDN.js";import{F as ae}from"./FileUpload-DldFs2sY.js";import{T as te,a as ne,b as A,c as C,d as le,e as b}from"./table-VQ_0MYAS.js";import"./label-C5P13FKO.js";import"./badge-BKvD35-V.js";import"./alert-dialog-nG4Kb3iB.js";import"./index-PT8koDjQ.js";import"./index-DAJOau0q.js";import"./index-CMZ90543.js";const ie=B({title:d().min(1,"Title is required"),authors:w(d()).min(1,"At least one author is required"),year:N().min(1900).max(new Date().getFullYear()+10),journal:d().optional(),publication_type:d().min(1,"Publication type is required"),doi:d().optional(),abstract:d().optional(),research_area:w(d()).default([]),tags:w(d()).default([]),citations:N().min(0).default(0),is_featured:Q().default(!1),pdf_url:d().optional()}),oe=({open:F,onOpenChange:u,publication:r})=>{const[m,h]=_.useState(null),p=k(),a=Y({resolver:H(ie),defaultValues:{title:"",authors:[],year:new Date().getFullYear(),journal:"",publication_type:"",doi:"",abstract:"",research_area:[],tags:[],citations:0,is_featured:!1,pdf_url:""}});_.useEffect(()=>{r?a.reset({title:r.title,authors:r.authors,year:r.year,journal:r.journal||"",publication_type:r.publication_type,doi:r.doi||"",abstract:r.abstract||"",research_area:r.research_area||[],tags:r.tags||[],citations:r.citations,is_featured:r.is_featured,pdf_url:r.pdf_url||""}):(a.reset(),h(null))},[r,a,F]);const x=I({mutationFn:async s=>{let t=s.pdf_url;m&&(r!=null&&r.pdf_url&&await E(r.pdf_url,"publication-pdfs"),t=await U({bucket:"publication-pdfs",file:m}));const j=J(s.title),P={title:s.title,authors:s.authors,year:s.year,publication_type:s.publication_type,slug:j,pdf_url:t,journal:s.journal||null,doi:s.doi||null,abstract:s.abstract||null,research_area:s.research_area,tags:s.tags,citations:s.citations,is_featured:s.is_featured};if(r){const{error:f}=await T.from("publications").update(P).eq("id",r.id);if(f)throw f}else{const{error:f}=await T.from("publications").insert([P]);if(f)throw f}},onSuccess:()=>{p.invalidateQueries({queryKey:["publications"]}),q({title:"Success",description:`Publication ${r?"updated":"created"} successfully`}),u(!1),a.reset(),h(null)},onError:s=>{q({title:"Error",description:s.message,variant:"destructive"})}}),S=s=>{x.mutate(s)};return e.jsx(V,{open:F,onOpenChange:u,children:e.jsxs(z,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsx($,{children:e.jsxs(G,{children:[r?"Edit":"Add"," Publication"]})}),e.jsx(K,{...a,children:e.jsxs("form",{onSubmit:a.handleSubmit(S),className:"space-y-4",children:[e.jsx(n,{control:a.control,name:"title",render:({field:s})=>e.jsxs(l,{children:[e.jsx(i,{children:"Title *"}),e.jsx(o,{children:e.jsx(g,{...s})}),e.jsx(c,{})]})}),e.jsx(n,{control:a.control,name:"authors",render:({field:s})=>e.jsxs(l,{children:[e.jsx(i,{children:"Authors *"}),e.jsx(o,{children:e.jsx(D,{value:s.value,onChange:s.onChange,placeholder:"Add author name..."})}),e.jsx(c,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(n,{control:a.control,name:"year",render:({field:s})=>e.jsxs(l,{children:[e.jsx(i,{children:"Year *"}),e.jsx(o,{children:e.jsx(g,{...s,type:"number",onChange:t=>s.onChange(parseInt(t.target.value))})}),e.jsx(c,{})]})}),e.jsx(n,{control:a.control,name:"publication_type",render:({field:s})=>e.jsxs(l,{children:[e.jsx(i,{children:"Type *"}),e.jsxs(Z,{onValueChange:s.onChange,value:s.value,children:[e.jsx(o,{children:e.jsx(ee,{children:e.jsx(se,{placeholder:"Select type"})})}),e.jsxs(re,{children:[e.jsx(y,{value:"Journal Article",children:"Journal Article"}),e.jsx(y,{value:"Conference Paper",children:"Conference Paper"}),e.jsx(y,{value:"Book Chapter",children:"Book Chapter"}),e.jsx(y,{value:"Technical Report",children:"Technical Report"}),e.jsx(y,{value:"Preprint",children:"Preprint"})]})]}),e.jsx(c,{})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(n,{control:a.control,name:"journal",render:({field:s})=>e.jsxs(l,{children:[e.jsx(i,{children:"Journal/Conference"}),e.jsx(o,{children:e.jsx(g,{...s})}),e.jsx(c,{})]})}),e.jsx(n,{control:a.control,name:"doi",render:({field:s})=>e.jsxs(l,{children:[e.jsx(i,{children:"DOI"}),e.jsx(o,{children:e.jsx(g,{...s,placeholder:"10.1234/example"})}),e.jsx(c,{})]})})]}),e.jsx(n,{control:a.control,name:"abstract",render:({field:s})=>e.jsxs(l,{children:[e.jsx(i,{children:"Abstract"}),e.jsx(o,{children:e.jsx(M,{...s,rows:4})}),e.jsx(c,{})]})}),e.jsx(n,{control:a.control,name:"research_area",render:({field:s})=>e.jsxs(l,{children:[e.jsx(i,{children:"Research Areas"}),e.jsx(o,{children:e.jsx(D,{value:s.value,onChange:s.onChange,placeholder:"Add research area..."})}),e.jsx(c,{})]})}),e.jsx(n,{control:a.control,name:"tags",render:({field:s})=>e.jsxs(l,{children:[e.jsx(i,{children:"Tags"}),e.jsx(o,{children:e.jsx(D,{value:s.value,onChange:s.onChange})}),e.jsx(c,{})]})}),e.jsx(n,{control:a.control,name:"pdf_url",render:({field:s})=>e.jsxs(l,{children:[e.jsx(i,{children:"PDF File"}),e.jsx(o,{children:e.jsx(ae,{value:s.value,onChange:s.onChange,onFileSelect:h})}),e.jsx(c,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(n,{control:a.control,name:"citations",render:({field:s})=>e.jsxs(l,{children:[e.jsx(i,{children:"Citations"}),e.jsx(o,{children:e.jsx(g,{...s,type:"number",onChange:t=>s.onChange(parseInt(t.target.value)||0)})}),e.jsx(c,{})]})}),e.jsx(n,{control:a.control,name:"is_featured",render:({field:s})=>e.jsxs(l,{className:"flex items-center justify-between space-y-0 pt-8",children:[e.jsx(i,{children:"Featured Publication"}),e.jsx(o,{children:e.jsx(X,{checked:s.value,onCheckedChange:s.onChange})})]})})]}),e.jsxs(W,{children:[e.jsx(v,{type:"button",variant:"outline",onClick:()=>u(!1),children:"Cancel"}),e.jsx(v,{type:"submit",disabled:x.isPending,children:x.isPending?"Saving...":r?"Update":"Create"})]})]})})]})})},Te=()=>{const[F,u]=_.useState(!1),[r,m]=_.useState(!1),[h,p]=_.useState(null),a=k(),{data:x,isLoading:S}=O({queryKey:["admin-publications"],queryFn:async()=>{const{data:t,error:j}=await T.from("publications").select("*").order("year",{ascending:!1});if(j)throw j;return t}}),s=I({mutationFn:async t=>{t.pdf_url&&await E(t.pdf_url,"publication-pdfs");const{error:j}=await T.from("publications").delete().eq("id",t.id);if(j)throw j},onSuccess:()=>{a.invalidateQueries({queryKey:["publications"]}),R.success("Publication deleted successfully"),m(!1)}});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Publications"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"Manage your research publications"})]}),e.jsx(v,{onClick:()=>{p(null),u(!0)},children:"Add Publication"})]}),S?e.jsx("div",{children:"Loading..."}):e.jsx("div",{className:"border rounded-lg",children:e.jsxs(te,{children:[e.jsx(ne,{children:e.jsxs(A,{children:[e.jsx(C,{children:"Title"}),e.jsx(C,{children:"Year"}),e.jsx(C,{children:"Type"}),e.jsx(C,{children:"Citations"}),e.jsx(C,{children:"Actions"})]})}),e.jsx(le,{children:x==null?void 0:x.map(t=>e.jsxs(A,{children:[e.jsx(b,{className:"font-medium",children:t.title}),e.jsx(b,{children:t.year}),e.jsx(b,{children:t.publication_type}),e.jsx(b,{children:t.citations}),e.jsx(b,{children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{variant:"outline",size:"sm",onClick:()=>{p(t),u(!0)},children:"Edit"}),e.jsx(v,{variant:"destructive",size:"sm",onClick:()=>{p(t),m(!0)},children:"Delete"})]})})]},t.id))})]})}),e.jsx(oe,{open:F,onOpenChange:u,publication:h}),e.jsx(L,{open:r,onOpenChange:m,onConfirm:()=>h&&s.mutate(h)})]})};export{Te 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.