1import{j as e,m as ue,A as he}from"./framer-BTOcKtpn.js";import{r as l}from"./react-vendor--ed5SCj-.js";import{o as xe,s as M,a as z,L as ge,S as pe,j as be,v as fe,I as E,B as d,z as L,y as Q,w as je,x as ve,X as W,V as Ne,W as we}from"./index-iu0F3uZx.js";import{S as j,a as v,b as N,c as w,d as u}from"./select-DLBOWvpP.js";import{P as Se,a as Ce,b as ye}from"./popover-D7D6bS5D.js";import{S as q,a as ke,b as Te,c as Pe,d as Ae,e as Me}from"./sheet-xnG6texp.js";import{B as Le}from"./JsonLd-DA_xkPn5.js";import{N as Oe}from"./newspaper-C4_RVEKY.js";import{S as $e}from"./sliders-horizontal-Bb-qGmZS.js";import{A as Z}from"./arrow-up-down-M4EhHn3H.js";import"./three-CGs2wkeH.js";import"./charts-odX-eC80.js";import"./radix-CN45mtlN.js";import"./query-C2hvSuIi.js";import"./supabase-oh74pAzG.js";import"./forms-CsLt0cZg.js";const J=[{value:"date-desc",label:"Newest first"},{value:"date-asc",label:"Oldest first"},{value:"title-asc",label:"Title A-Z"},{value:"title-desc",label:"Title Z-A"},{value:"popular",label:"Most popular"}],R=["Medium","LinkedIn","Dev.to","Hashnode","YouTube","Internal","Other"];function Ue(){const[c,U]=l.useState([]),[X,S]=l.useState(!0),[o,g]=l.useState("all"),[i,p]=l.useState("all"),[r,C]=l.useState([]),[O,G]=l.useState(!1),[m,y]=l.useState(""),[K,$]=l.useState(!1),[h,D]=l.useState("date-desc"),[ee,se]=l.useState(null),[te,_]=l.useState(!1),[b,k]=l.useState(1),T=12,ae=xe(),le=s=>{se(s),_(!0)};l.useEffect(()=>{const s=async()=>{S(!0);const{data:t,error:n}=await M.from("blog_posts").select("*").eq("status","Published").order("published_at",{ascending:!1});if(n){console.error("Error fetching blog posts:",n),S(!1);return}t&&U(t),S(!1)};s();const a=M.channel("blog-posts-changes").on("postgres_changes",{event:"*",schema:"public",table:"blog_posts"},()=>{s()}).subscribe();return()=>{M.removeChannel(a)}},[]);const B=l.useMemo(()=>[...new Set(c.flatMap(s=>s.topics||[]))].sort(),[c]),I=l.useMemo(()=>[...new Set(c.map(s=>z(new Date(s.published_at),"yyyy")))].sort((s,a)=>a.localeCompare(s)),[c]),P=s=>{C(a=>a.includes(s)?a.filter(t=>t!==s):[...a,s])},re=s=>{C(a=>a.filter(t=>t!==s))},A=()=>{g("all"),p("all"),C([]),y("")},Y=o!=="all"||i!=="all"||r.length>0||m.length>0,F=(o!=="all"?1:0)+(i!=="all"?1:0)+r.length,x=l.useMemo(()=>{const s=m.toLowerCase().trim();return[...c.filter(t=>{const n=z(new Date(t.published_at),"yyyy"),oe=o==="all"||t.source===o,ie=i==="all"||n===i,ce=r.length===0||r.some(me=>{var H;return(H=t.topics)==null?void 0:H.includes(me)}),de=s===""||t.title.toLowerCase().includes(s)||t.excerpt.toLowerCase().includes(s);return oe&&ie&&ce&&de})].sort((t,n)=>{switch(h){case"date-desc":return new Date(n.published_at).getTime()-new Date(t.published_at).getTime();case"date-asc":return new Date(t.published_at).getTime()-new Date(n.published_at).getTime();case"title-asc":return t.title.localeCompare(n.title);case"title-desc":return n.title.localeCompare(t.title);case"popular":return(n.views_count||0)-(t.views_count||0);default:return 0}})},[c,o,i,r,m,h]);l.useEffect(()=>{k(1)},[o,i,r,m,h]);const f=Math.ceil(x.length/T),V=(b-1)*T,ne=x.slice(V,V+T);return e.jsxs(ge,{children:[e.jsx(pe,{title:"Blog | Shadab Hussain",description:"Articles and insights by Shadab Hussain on AI, Machine Learning, Quantum Computing and emerging technologies.",path:"/blog",renderH1:!0}),e.jsx(Le,{posts:c}),e.jsx("div",{className:"pt-24 pb-16 md:pb-24 px-5 md:px-6",children:e.jsxs("div",{className:"container mx-auto max-w-6xl",children:[e.jsx(be,{title:"Blog & Articles",subtitle:"Insights on AI, Machine Learning, Quantum Computing, and emerging technologies",icon:Oe,align:"center"}),X?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(fe,{className:"h-12 w-12 text-brand-blue animate-spin"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4 mb-8",children:[ae?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(q,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search articles...",value:m,onChange:s=>y(s.target.value),className:"pl-9 bg-background border-border"})]}),e.jsxs(ke,{open:K,onOpenChange:$,children:[e.jsx(Te,{asChild:!0,children:e.jsxs(d,{variant:"outline",size:"icon","aria-label":"Open filters",className:"relative bg-background border-border shrink-0",children:[e.jsx($e,{className:"h-4 w-4"}),F>0&&e.jsx("span",{className:"absolute -top-1.5 -right-1.5 bg-brand-blue text-white text-xs w-5 h-5 rounded-full flex items-center justify-center font-medium",children:F})]})}),e.jsxs(Pe,{side:"bottom",className:"h-[80vh] rounded-t-2xl",children:[e.jsx(Ae,{className:"mb-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Me,{children:"Filters"}),Y&&e.jsx(d,{variant:"ghost",size:"sm",onClick:A,children:"Clear all"})]})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground mb-3",children:"Source"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:()=>g("all"),className:`px-4 py-2 rounded-full text-sm font-medium transition-all ${o==="all"?"bg-brand-blue text-white":"bg-muted/50 text-muted-foreground hover:bg-muted"}`,children:"All"}),R.map(s=>e.jsx("button",{onClick:()=>g(s),className:`px-4 py-2 rounded-full text-sm font-medium transition-all ${o===s?"bg-brand-blue text-white":"bg-muted/50 text-muted-foreground hover:bg-muted"}`,children:s},s))]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground mb-3",children:"Year"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:()=>p("all"),className:`px-4 py-2 rounded-full text-sm font-medium transition-all ${i==="all"?"bg-brand-blue text-white":"bg-muted/50 text-muted-foreground hover:bg-muted"}`,children:"All"}),I.map(s=>e.jsx("button",{onClick:()=>p(s),className:`px-4 py-2 rounded-full text-sm font-medium transition-all ${i===s?"bg-brand-blue text-white":"bg-muted/50 text-muted-foreground hover:bg-muted"}`,children:s},s))]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground mb-3",children:"Topics"}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto overscroll-contain pr-2",onWheelCapture:s=>s.stopPropagation(),children:e.jsx("div",{className:"flex flex-wrap gap-2",children:B.map(s=>{const a=L(s),t=r.includes(s);return e.jsxs("button",{onClick:()=>P(s),className:`px-4 py-2 rounded-full text-sm font-medium transition-all border ${t?`${a.bg} ${a.text} ${a.border}`:"bg-muted/50 text-muted-foreground border-transparent hover:bg-muted"}`,children:[t&&e.jsx(Q,{className:"inline-block w-3 h-3 mr-1"}),s]},s)})})})]})]}),e.jsx("div",{className:"mt-8",children:e.jsxs(d,{className:"w-full bg-brand-blue hover:bg-brand-blue/90 text-white",onClick:()=>$(!1),children:["Show ",x.length," results"]})})]})]}),e.jsxs(j,{value:h,onValueChange:s=>D(s),children:[e.jsxs(v,{className:"w-[130px] bg-background border-border",children:[e.jsx(Z,{className:"h-4 w-4 mr-1"}),e.jsx(N,{placeholder:"Sort"})]}),e.jsx(w,{className:"bg-background border-border",children:J.map(s=>e.jsx(u,{value:s.value,children:s.label},s.value))})]})]}):e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(q,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search articles...",value:m,onChange:s=>y(s.target.value),className:"pl-9 bg-background border-border"})]}),e.jsxs(j,{value:o,onValueChange:g,children:[e.jsx(v,{className:"flex-1 min-w-[110px] bg-background border-border",children:e.jsx(N,{placeholder:"Source"})}),e.jsxs(w,{className:"bg-background border-border",children:[e.jsx(u,{value:"all",children:"All Sources"}),R.map(s=>e.jsx(u,{value:s,children:s},s))]})]}),e.jsxs(j,{value:i,onValueChange:p,children:[e.jsx(v,{className:"flex-1 min-w-[100px] bg-background border-border",children:e.jsx(N,{placeholder:"Year"})}),e.jsxs(w,{className:"bg-background border-border",children:[e.jsx(u,{value:"all",children:"All Years"}),I.map(s=>e.jsx(u,{value:s,children:s},s))]})]}),e.jsxs(Se,{open:O,onOpenChange:G,children:[e.jsx(Ce,{asChild:!0,children:e.jsxs(d,{variant:"outline",role:"combobox","aria-expanded":O,className:"flex-1 min-w-[110px] justify-between bg-background border-border text-muted-foreground hover:text-foreground",children:[r.length>0?`${r.length}
1 selected`:"Topics",e.jsx(je,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(ye,{className:"w-[200px] p-2 bg-background border-border z-50",align:"start",children:e.jsx("div",{className:"max-h-[300px] overflow-y-auto overscroll-contain pr-2",onWheelCapture:s=>s.stopPropagation(),children:e.jsx("div",{className:"space-y-1",children:B.map(s=>{const a=L(s),t=r.includes(s);return e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md hover:bg-muted/50 cursor-pointer",onClick:()=>P(s),children:[e.jsx(ve,{checked:t,onCheckedChange:()=>P(s),className:"pointer-events-none"}),e.jsx("span",{className:`text-sm font-medium ${a.text}`,children:s}),t&&e.jsx(Q,{className:"ml-auto h-4 w-4 text-brand-blue"})]},s)})})})})]}),e.jsxs(j,{value:h,onValueChange:s=>D(s),children:[e.jsxs(v,{className:"flex-1 min-w-[110px] bg-background border-border",children:[e.jsx(Z,{className:"h-4 w-4 mr-1"}),e.jsx(N,{placeholder:"Sort"})]}),e.jsx(w,{className:"bg-background border-border",children:J.map(s=>e.jsx(u,{value:s.value,children:s.label},s.value))})]}),Y&&e.jsxs(d,{variant:"ghost",size:"sm",onClick:A,className:"text-muted-foreground hover:text-foreground shrink-0",children:[e.jsx(W,{className:"w-4 h-4 mr-1"}),"Clear"]})]}),r.length>0&&e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:r.map(s=>{const a=L(s);return e.jsxs(ue.span,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.8},className:`inline-flex items-center gap-1 px-3 py-1.5 rounded-full text-xs font-medium border ${a.bg} ${a.text} ${a.border}`,children:[s,e.jsx("button",{onClick:()=>re(s),className:"ml-1 hover:opacity-70 transition-opacity",children:e.jsx(W,{className:"h-3 w-3"})})]},s)})}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Showing ",e.jsx("span",{className:"font-semibold text-foreground",children:x.length})," of"," ",e.jsx("span",{className:"font-semibold text-foreground",children:c.length})," articles"]})]}),x.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"No articles found matching your criteria."}),e.jsx(d,{variant:"outline",onClick:A,children:"Clear filters"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:e.jsx(he,{mode:"popLayout",children:ne.map(s=>e.jsx(Ne,{post:s,onViewDetails:le},s.id))})}),f>1&&e.jsxs("div",{className:"flex justify-center items-center gap-4 mt-8",children:[e.jsx(d,{variant:"outline",onClick:()=>{k(s=>Math.max(1,s-1)),window.scrollTo({top:0,behavior:"smooth"})},disabled:b===1,children:"Previous"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",b," of ",f]}),e.jsx(d,{variant:"outline",onClick:()=>{k(s=>Math.min(f,s+1)),window.scrollTo({top:0,behavior:"smooth"})},disabled:b===f,children:"Next"})]})]}),e.jsx(we,{post:ee,open:te,onOpenChange:_})]})]})})]})}export{Ue 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.