1import{j as e,r as x,p as P,x as I}from"./react-BRYQa-6H.js";import{C as A,a as L,e as D,k as F,X as V,b as C,a4 as k,d as S,F as Y,i as q,U as z,h as R,g as B,x as J,J as K,H as M,al as H,L as Q,_ as X,$ as G,a0 as W,a1 as Z,a2 as ee,I as se}from"./index-CrUUd797.js";import{f as O}from"./fetchAllRecords-azAIpwTN.js";import{C as ae}from"./checkbox-Do2ahkgw.js";import{L as te}from"./label-BWLbbdBR.js";import{S as re}from"./scroll-area-Bet5bEmz.js";import{F as le}from"./filter-BdBTadl7.js";import{S as ne}from"./sliders-horizontal-FvpePzAY.js";import"./supabase-_6OsXGUr.js";import"./radix-BIG4jduS.js";import"./query-3VBTQ5aw.js";const U=({filters:c,onFiltersChange:j,counts:f,loading:m})=>{const v=(h,d)=>{const p=c[h],g=p.includes(d)?p.filter(y=>y!==d):[...p,d];j({...c,[h]:g})},w=()=>{j({years:[],authors:[],keywords:[],volumes:[],issues:[]})},a=()=>Object.values(c).reduce((h,d)=>h+d.length,0),o=(h,d,p,g=10)=>{const[y,E]=x.useState(!1),N=Object.entries(p).sort((u,b)=>b[1]-u[1]),r=y?N:N.slice(0,g);return N.length===0?null:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"font-semibold text-sm text-foreground flex items-center justify-between",children:[h,c[d].length>0&&e.jsx(S,{variant:"secondary",className:"text-xs",children:c[d].length})]}),e.jsx("div",{className:"space-y-2",children:r.map(([u,b])=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ae,{id:`${d}-${u}`,checked:c[d].includes(u),onCheckedChange:()=>v(d,u)}),e.jsx(te,{htmlFor:`${d}-${u}`,className:"flex-1 text-sm cursor-pointer hover:text-primary transition-colors",children:e.jsxs("span",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate",children:u}),e.jsx(S,{variant:"outline",className:"ml-2 text-xs shrink-0",children:b})]})})]},u))}),N.length>g&&e.jsx(F,{variant:"ghost",size:"sm",onClick:()=>E(!y),className:"text-xs",children:y?"Show less":`Show ${N.length-g} more`})]})};return e.jsxs(A,{className:"h-full",children:[e.jsx(L,{className:"pb-3",children:e.jsxs(D,{className:"text-lg flex items-center justify-between",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(le,{className:"h-4 w-4"}),"Filters"]}),a()>0&&e.jsxs(F,{variant:"ghost",size:"sm",onClick:w,className:"text-xs",children:[e.jsx(V,{className:"h-3 w-3 mr-1"}),"Clear all"]})]})}),e.jsx(C,{children:e.jsx(re,{className:"h-[calc(100vh-16rem)]",children:e.jsx("div",{className:"space-y-6 pr-4",children:m?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading filters..."}):e.jsxs(e.Fragment,{children:[o("Publication Year","years",f.years),e.jsx(k,{}),o("Authors","authors",f.authors,8),e.jsx(k,{}),o("Keywords","keywords",f.keywords,8),e.jsx(k,{}),o("Volume","volumes",f.volumes),e.jsx(k,{}),o("Issue","issues",f.issues)]})})})})]})},oe=({articles:c,loading:j,searchQuery:f,totalCount:m})=>{const v=P();if(j)return e.jsx("div",{className:"space-y-4",children:[1,2,3].map(a=>e.jsxs(A,{className:"animate-pulse",children:[e.jsx(L,{children:e.jsx("div",{className:"h-6 bg-muted rounded w-3/4"})}),e.jsx(C,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 bg-muted rounded"}),e.jsx("div",{className:"h-4 bg-muted rounded w-5/6"})]})})]},a))});if(c.length===0)return e.jsx(A,{children:e.jsx(C,{className:"pt-6",children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Y,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No articles found"}),e.jsx("p",{className:"text-muted-foreground",children:f?`No results match your search "${f}"`:"Try adjusting your filters to see more results"})]})})});const w=a=>!a||a.length===0?"Unknown authors":a.slice(0,3).map(o=>typeof o=="string"?o:o.givenNames&&o.surname?`${o.givenNames} ${o.surname}`:o.surname||o.givenNames||"Unknown").join(", ")+(a.length>3?" et al.":"");return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("h2",{className:"text-2xl font-bold",children:[m," ",m===1?"Article":"Articles"," Found"]})}),c.map(a=>e.jsxs(A,{className:"cursor-pointer transition-all hover:shadow-lg hover:border-primary/50",onClick:()=>v(q(a)),children:[e.jsxs(L,{children:[e.jsx(D,{className:"text-xl hover:text-primary transition-colors",children:a.title}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-sm text-muted-foreground mt-2",children:[a.authors&&a.authors.length>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(z,{className:"h-3 w-3"}),w(a.authors)]}),a.published_date&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(R,{className:"h-3 w-3"}),new Date(a.published_date).getFullYear()]}),a.metadata?.volume&&e.jsxs(S,{variant:"outline",className:"text-xs",children:["Vol ",a.metadata.volume,a.metadata.issue&&`, Issue ${a.metadata.issue}`]})]})]}),e.jsxs(C,{children:[e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-3 mb-3",children:B(a.abstract)||"No abstract available"}),a.keywords&&a.keywords.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.keywords.slice(0,5).map((o,h)=>e.jsx(S,{variant:"secondary",className:"text-xs",children:o},h)),a.keywords.length>5&&e.jsxs(S,{variant:"secondary",className:"text-xs",children:["+",a.keywords.length-5," more"]})]})]})]},a.id))]})},ye=()=>{const[c,j]=I(),{settings:f}=J(),[m,v]=x.useState(c.get("q")||""),[w,a]=x.useState([]),[o,h]=x.useState(!1),[d,p]=x.useState(0),[g,y]=x.useState({years:{},authors:{},keywords:{},volumes:{},issues:{}}
1),[E,N]=x.useState(!1),[r,u]=x.useState(()=>({years:c.getAll("year"),authors:c.getAll("author"),keywords:c.getAll("keyword"),volumes:c.getAll("volume"),issues:c.getAll("issue")}));x.useEffect(()=>{const n=new URLSearchParams;m&&n.set("q",m),r.years.forEach(s=>n.append("year",s)),r.authors.forEach(s=>n.append("author",s)),r.keywords.forEach(s=>n.append("keyword",s)),r.volumes.forEach(s=>n.append("volume",s)),r.issues.forEach(s=>n.append("issue",s)),j(n,{replace:!0})},[r,m,j]),x.useEffect(()=>{b()},[]),x.useEffect(()=>{_()},[r,m]);const b=async()=>{try{const n=await O("published_date, authors, keywords, metadata"),s={years:{},authors:{},keywords:{},volumes:{},issues:{}};n.forEach(t=>{if(t.published_date){const i=new Date(t.published_date).getFullYear().toString();s.years[i]=(s.years[i]||0)+1}t.authors&&Array.isArray(t.authors)&&t.authors.forEach(i=>{const $=typeof i=="string"?i:i.surname||i.givenNames||null;$&&(s.authors[$]=(s.authors[$]||0)+1)}),t.keywords&&Array.isArray(t.keywords)&&t.keywords.forEach(i=>{i&&(s.keywords[i]=(s.keywords[i]||0)+1)});const l=t.metadata;if(l?.volume){const i=l.volume.toString();s.volumes[i]=(s.volumes[i]||0)+1}if(l?.issue){const i=l.issue.toString();s.issues[i]=(s.issues[i]||0)+1}}),y(s)}catch(n){console.error("Error fetching facet counts:",n)}},_=async()=>{h(!0);try{let n=await O();if(m){const t=m.toLowerCase();n=n.filter(l=>l.title?.toLowerCase().includes(t)||l.abstract?.toLowerCase().includes(t))}let s=n;r.years.length>0&&(s=s.filter(t=>{const l=t.published_date?new Date(t.published_date).getFullYear().toString():null;return l&&r.years.includes(l)})),r.authors.length>0&&(s=s.filter(t=>!t.authors||!Array.isArray(t.authors)?!1:t.authors.some(l=>{const i=typeof l=="string"?l:l.surname||l.givenNames;return r.authors.includes(i)}))),r.keywords.length>0&&(s=s.filter(t=>!t.keywords||!Array.isArray(t.keywords)?!1:t.keywords.some(l=>r.keywords.includes(l)))),r.volumes.length>0&&(s=s.filter(t=>{const l=t.metadata;return l?.volume&&r.volumes.includes(l.volume.toString())})),r.issues.length>0&&(s=s.filter(t=>{const l=t.metadata;return l?.issue&&r.issues.includes(l.issue.toString())})),a(s),p(s.length)}catch(n){console.error("Error fetching articles:",n)}finally{h(!1)}},T=()=>{_()};return e.jsxs("div",{className:"min-h-screen flex flex-col bg-background",children:[e.jsxs(K,{children:[e.jsxs("title",{children:["Search Articles | ",f?.journal_name||"Journal"]}),e.jsx("meta",{name:"description",content:"Search and filter scientific articles by year, author, keywords, and more"})]}),e.jsx(M,{}),e.jsx("div",{className:"bg-gradient-to-br from-primary/10 via-secondary/5 to-background py-8 border-b border-border",children:e.jsxs("div",{className:"container mx-auto px-4",children:[e.jsx("h1",{className:"text-4xl font-bold mb-4 text-foreground",children:"Search Articles"}),e.jsxs("div",{className:"flex gap-2 max-w-2xl",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(H,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(Q,{placeholder:"Search by title or abstract...",value:m,onChange:n=>v(n.target.value),onKeyDown:n=>n.key==="Enter"&&T(),className:"pl-10"})]}),e.jsxs(F,{onClick:T,children:[e.jsx(H,{className:"h-4 w-4 mr-2"}),"Search"]})]})]})}),e.jsx("main",{className:"flex-1 container mx-auto px-4 py-8",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-6",children:[e.jsx("aside",{className:"hidden lg:block lg:col-span-1",children:e.jsx("div",{className:"sticky top-24",children:e.jsx(U,{filters:r,onFiltersChange:u,counts:g,loading:o})})}),e.jsx("div",{className:"lg:hidden mb-4",children:e.jsxs(X,{open:E,onOpenChange:N,children:[e.jsx(G,{asChild:!0,children:e.jsxs(F,{variant:"outline",className:"w-full",children:[e.jsx(ne,{className:"h-4 w-4 mr-2"}),"Filters",Object.values(r).flat().length>0&&e.jsx("span",{className:"ml-2 bg-primary text-primary-foreground rounded-full px-2 py-0.5 text-xs",children:Object.values(r).flat().length})]})}),e.jsxs(W,{side:"left",className:"w-full sm:max-w-md overflow-y-auto",children:[e.jsx(Z,{children:e.jsx(ee,{children:"Filters"})}),e.jsx("div",{className:"mt-6",children:e.jsx(U,{filters:r,onFiltersChange:u,counts:g,loading:o})})]})]})}),e.jsx("div",{className:"lg:col-span-3",children:e.jsx(oe,{articles:w,loading:o,searchQuery:m,totalCount:d})})]})}),e.jsx(se,{})]})};export{ye 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.