1import{u as Ae,b as Ce,r,j as s,L as Ee,S as Le,i as ce,B as w,ac as Me,f as Ie,K as de,y as T,h as De,a0 as Be,ad as Oe,R as Re,a2 as Ge,a3 as We,s as A}from"./index-CysU2Jg9.js";import{P as Ze}from"./PageHeader-tcsahsuR.js";import{I as $e}from"./input-UNMuvhAA.js";import{L as j}from"./label-CLsWIlGF.js";import{M as H}from"./multi-select-BYDYgPJX.js";import{C as he}from"./calendar-CQCZlNur.js";import{P as me,a as ue,b as ge}from"./popover-BAh12zBB.js";import{S as ze}from"./switch-COWD1z9F.js";import{A as He}from"./arrow-left-DtRFkuOL.js";import{F as qe,f as fe}from"./format-DEp8I5i1.js";import{C as xe}from"./calendar-1a5dmTGo.js";import"./checkbox-BpTkFBno.js";import"./check-CMDL-7uT.js";import"./startOfMonth-CefLwR_S.js";import"./subDays-D3OfSCfl.js";import"./chevron-left-DZiAb83u.js";import"./chevron-right-C4GdRsTP.js";const Ue={"show-post":"Show Post","station-post":"Station Post","show-podcast":"Show Post","station-podcast":"Station Post"},pe="wp-cat:",ve="wp-tag:",Xe="__none__",C=S=>S.length===1&&S[0]===Xe,ms=()=>{const S=Ae("header_all_posts"),[u,q]=Ce(),[y,U]=r.useState([]),[E,be]=r.useState({}),[v,we]=r.useState([]),[X,je]=r.useState([]),[K,Se]=r.useState({}),[_e,Ne]=r.useState(!0),L=48,[M,V]=r.useState(L),I=u.get("type"),P=e=>{const o=u.get(e);return o?o.split(",").filter(Boolean):[]},Y=e=>{const o=u.get(e);if(!o)return;const a=new Date(o);return isNaN(a.getTime())?void 0:a},[g,J]=r.useState(u.get("q")??""),[l,D]=r.useState(P("shows")),[h,Q]=r.useState(P("types").length>0?P("types"):I&&I!=="all"?[I]:[]),[i,ee]=r.useState(u.get("archives")==="1"),[b,se]=r.useState(u.get("podcasts")==="1"),[m,te]=r.useState(P("tags")),[n,B]=r.useState(Y("from")),[c,O]=r.useState(Y("to"));r.useEffect(()=>{const e=new URLSearchParams;g&&e.set("q",g),l.length&&e.set("shows",l.join(",")),h.length&&e.set("types",h.join(",")),i&&e.set("archives","1"),b&&e.set("podcasts","1"),m.length&&e.set("tags",m.join(",")),n&&e.set("from",n.toISOString().slice(0,10)),c&&e.set("to",c.toISOString().slice(0,10)),q(e,{replace:!0})},[g,l,h,i,b,m,n,c,q]),r.useEffect(()=>{(async()=>{const a=async t=>A.rpc("get_public_posts_list",{_limit:1e3,_offset:t*1e3}),[d,W,Z]=await Promise.all([a(0),A.from("shows").select("id, name, slug, archived, vacant, image_url").order("name"),A.from("post_tags").select("id, name, slug").order("name")]);d.error&&console.error("Failed to load posts",d.error),W.error&&console.error("Failed to load shows for All Posts filters",W.error),Z.error&&console.error("Failed to load post tags",Z.error);const oe=W.data??[],le={};oe.forEach(t=>{le[t.id]={name:t.name,slug:t.slug,archived:t.archived,image_url:t.image_url??null}}),be(le),we(oe.filter(t=>!t.vacant).map(t=>({id:t.id,name:t.name,archived:t.archived})));const ie=Z.data??[];je(ie);let _=d.data??[];U(_),Ne(!1);let $=_.length<1e3,N=1;for(;!$&&N<40;){const t=[N,N+1,N+2],F=await Promise.all(t.map(x=>a(x)));for(const x of F){if(x.error){console.error("Failed to load posts page",x.error),$=!0;break}const p=x.data??[];_=_.concat(p),p.length<1e3&&($=!0)}U(_),N+=t.length}const ne=ie.filter(t=>!t.slug.startsWith(pe)&&!t.slug.startsWith(ve)).map(t=>t.id);if(ne.length===0)return;const k={},z=1e3;for(let t=0;t<1e5;t+=z){const{data:F,error:x}=await A.from("post_tag_assignments").select("post_id, tag_id").in("tag_id",ne).range(t,t+z-1);if(x){console.error("Failed to load post tag assignments",x);break}for(const p of F??[])k[p.post_id]||(k[p.post_id]=new Set),k[p.post_id].add(p.tag_id);if((F??[]).length<z)break}Se(k)})()},[]);const ye=r.useMemo(()=>X.filter(e=>!e.slug.startsWith(pe)&&!e.slug.startsWith(ve)),[X]),R=r.useMemo(()=>new Set(v.filter(e=>e.archived).map(e=>e.id)),[v]),G=e=>e.archived||e.show_id&&R.has(e.show_id)?"archived":"published",ae=e=>e.has_audio,Pe=g!==""||l.length>0||h.length>0||i||b||m.length>0||n!==void 0||c!==void 0,ke=()=>{J(""),D([]),Q([]),ee(!1),se(!1),te([]),B(void 0),O(void 0)};r.useEffect(()=>{if(l.length===0||C(l)||v.length===0)return;const e=new Set(v.filter(a=>i?a.archived:!a.archived).map(a=>a.id)),o=l.filter(a=>e.has(a));o.length!==l.length&&D(o)},[i,v,l]);const f=r.useMemo(()=>y.filter(e=>{if(C(l)||C(h)||C(m))return!1;const o=G(e);if(i){if(o!=="archived")return!1}else if(o==="archived")return!1;if(l.length>0&&(!e.show_id||!l.includes(e.show_id))||h.length>0&&!h.includes(e.post_type)||b&&!ae(e))return!1;if(m.length>
10){const a=K[e.id];if(!a||!m.some(d=>a.has(d)))return!1}if(n){const a=new Date(e.created_at),d=new Date(n);if(d.setHours(0,0,0,0),a<d)return!1}if(c){const a=new Date(e.created_at),d=new Date(c);if(d.setHours(23,59,59,999),a>d)return!1}if(g){const a=g.toLowerCase();if(!e.title.toLowerCase().includes(a)&&!(e.excerpt??"").toLowerCase().includes(a))return!1}return!0}),[y,K,R,g,l,h,i,b,m,n,c]),re=r.useMemo(()=>y.filter(e=>G(e)==="archived"===i).length,[y,R,i]);r.useEffect(()=>{V(L)},[f]);const Fe=e=>`/post/${e.slug}`,Te=e=>"bg-primary/10 text-primary";return s.jsxs(Ee,{children:[s.jsx(Le,{title:"All Posts - 88.3 Southern FM",description:"Latest news, interviews and stories from 88.3 Southern FM and Bayside Melbourne.",path:"/posts"}),s.jsx(Ze,{title:"All Posts",description:"Browse posts, podcasts, and community news from Southern FM.",backgroundImage:S.src,backgroundImageSrcSet:S.srcSet}),s.jsxs("div",{className:"page-content w-full py-10",children:[s.jsxs(ce,{to:"/",className:"inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground mb-6",children:[s.jsx(He,{className:"h-4 w-4"})," Back to Home"]}),s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[260px_1fr] gap-6",children:[s.jsxs("aside",{className:"bg-card border border-border rounded-xl p-4 space-y-3 lg:sticky lg:top-24 lg:self-start lg:max-h-[calc(100vh-7rem)] lg:overflow-y-auto",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(qe,{className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"text-sm font-medium text-foreground",children:"Filters"})]}),Pe&&s.jsxs(w,{variant:"ghost",size:"sm",onClick:ke,className:"h-7 text-xs px-2",children:[s.jsx(Me,{className:"h-3 w-3 mr-1"})," Clear"]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"relative",children:[s.jsx(Ie,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx($e,{placeholder:"Search title or excerptâ¦",value:g,onChange:e=>J(e.target.value),className:"pl-8 h-9 text-sm"})]}),s.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 p-3 space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs(j,{htmlFor:"only-podcasts",className:"text-xs font-medium text-foreground cursor-pointer flex items-center gap-1.5",children:[s.jsx(de,{className:"h-3.5 w-3.5"})," Podcasts only"]}),s.jsx(ze,{id:"only-podcasts",checked:b,onCheckedChange:se})]}),s.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:"Only show posts that have audio attached."})]}),s.jsxs("div",{children:[s.jsx(j,{className:"text-xs text-muted-foreground mb-1 block",children:"Shows"}),s.jsx(H,{options:v.filter(e=>i?e.archived:!e.archived).map(e=>({value:e.id,label:e.name})),value:l,onChange:D,allLabel:i?"All Archived Shows":"All Shows",placeholder:"Shows",searchable:!0,searchPlaceholder:"Search showsâ¦"})]}),s.jsxs("div",{children:[s.jsx(j,{className:"text-xs text-muted-foreground mb-1 block",children:"Type"}),s.jsx(H,{options:[{value:"show-post",label:"Show Post"},{value:"station-post",label:"Station Post"},{value:"normal",label:"Uncategorised"},{value:"__archives__",label:"From the Archives"}],value:[...h,...i?["__archives__"]:[]],onChange:e=>{ee(e.includes("__archives__")),Q(e.filter(o=>o!=="__archives__"))},allLabel:"All Types",placeholder:"Types"})]}),s.jsxs("div",{children:[s.jsx(j,{className:"text-xs text-muted-foreground mb-1 block",children:"Tags"}),s.jsx(H,{options:ye.map(e=>({value:e.id,label:e.name})),value:m,onChange:te,allLabel:"All Tags",placeholder:"Tags"})]}),s.jsxs("div",{children:[s.jsx(j,{className:"text-xs text-muted-foreground mb-1 block",children:"From date"}),s.jsxs(me,{children:[s.jsx(ue,{asChild:!0,children:s.jsxs(w,{variant:"ghost",className:T("h-9 w-full text-sm justify-start font-normal px-3 border border-input bg-background hover:bg-muted/50 data-[state=open]:border-foreground
1/40",!n&&"text-muted-foreground"),children:[s.jsx(xe,{className:"h-3.5 w-3.5 mr-1.5"}),n?fe(n,"d MMM yyyy"):"From date"]})}),s.jsxs(ge,{className:"w-auto p-0",align:"start",children:[s.jsx(he,{mode:"single",selected:n,onSelect:B,initialFocus:!0,className:T("p-3 pointer-events-auto")}),n&&s.jsx("div",{className:"p-2 border-t border-border",children:s.jsx(w,{variant:"ghost",size:"sm",onClick:()=>B(void 0),className:"w-full h-7 text-xs",children:"Clear"})})]})]})]}),s.jsxs("div",{children:[s.jsx(j,{className:"text-xs text-muted-foreground mb-1 block",children:"To date"}),s.jsxs(me,{children:[s.jsx(ue,{asChild:!0,children:s.jsxs(w,{variant:"ghost",className:T("h-9 w-full text-sm justify-start font-normal px-3 border border-input bg-background hover:bg-muted/50 data-[state=open]:border-foreground/40",!c&&"text-muted-foreground"),children:[s.jsx(xe,{className:"h-3.5 w-3.5 mr-1.5"}),c?fe(c,"d MMM yyyy"):"To date"]})}),s.jsxs(ge,{className:"w-auto p-0",align:"start",children:[s.jsx(he,{mode:"single",selected:c,onSelect:O,initialFocus:!0,className:T("p-3 pointer-events-auto")}),c&&s.jsx("div",{className:"p-2 border-t border-border",children:s.jsx(w,{variant:"ghost",size:"sm",onClick:()=>O(void 0),className:"w-full h-7 text-xs",children:"Clear"})})]})]})]})]}),s.jsxs("p",{className:"text-xs text-muted-foreground pt-2 border-t border-border",children:["Showing ",f.length," of ",re," post",re!==1?"s":""]})]}),s.jsx("div",{className:"min-w-0",children:_e?s.jsx("div",{className:"flex justify-center py-10",children:s.jsx(De,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):f.length===0?s.jsx("p",{className:"text-center text-muted-foreground py-10",children:"No posts found."}):s.jsxs(s.Fragment,{children:[s.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[f.length," post",f.length!==1?"s":""]}),s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-
15",children:f.slice(0,M).map(e=>{const o=Be(e.featured_image,e.show_id?E[e.show_id]:null,e.id);return s.jsxs(ce,{to:Fe(e),state:{from:`/posts${u.toString()?`?${u.toString()}`:""}`,fromLabel:"Back to All Posts"},className:"bg-card rounded-2xl border border-border hover:border-primary/30 hover:shadow-md transition-all overflow-hidden group block",children:[o.kind==="image"?s.jsx("div",{className:"h-32 overflow-hidden",children:s.jsx("img",{src:o.src,alt:"",className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-300",style:e.featured_image?Oe(e.featured_image_position):void 0})}):s.jsx("div",{className:"h-32 flex items-center justify-center",style:{background:o.background},children:s.jsx(Re,{className:"h-10 w-10 text-white/40"})}),s.jsxs("div",{className:"p-5",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2 flex-wrap",children:[s.jsx("span",{className:`text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded-full ${Te(e.post_type)}`,children:Ue[e.post_type]??"Post"}),ae(e)&&s.jsxs("span",{className:"text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded-full bg-secondary/10 text-secondary flex items-center gap-0.5",children:[s.jsx(de,{className:"h-3 w-3"}),"Podcast"]}),G(e)==="archived"&&s.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded-full bg-amber-500/10 text-amber-700 dark:text-amber-400 border border-amber-500/20",children:"From the Archives"}),e.is_featured&&s.jsxs("span",{className:"text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded-full bg-amber-100 text-amber-700 flex items-center gap-0.5",children:[s.jsx(Ge,{className:"h-3 w-3"}),"Featured"]}),e.show_id&&E[e.show_id]&&s.jsxs("span",{className:"text-xs text-muted-foreground",children:["· ",E[e.show_id].name]})]}),s.jsx("h3",{className:"font-semibold text-foreground mb-1 group-hover:text-primary transition-colors",children:e.title}),(()=>{const a=We(e.excerpt,e.preview,180);return a&&s.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:a})})(),s.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:new Date(e.created_at).toLocaleDateString("en-AU",{year:"numeric",month:"long",day:"numeric"})})]})]},e.id)})}),f.length>M&&s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-8",children:[s.jsx(w,{variant:"outline",onClick:()=>V(e=>e+L),children:"Load more posts"}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing ",M," of ",f.length]})]})]})})]})]})]})};export{ms 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.