import{r as o,d as f,j as e,H as g,g as u,w as j,a2 as _,V as N,f as b}from"./vendor-laZsiqLO.js";import{G as v}from"./GuestLayout-Bncnlxxo.js";import{P as y}from"./PostCard-S-gB25Ls.js";import{S as w}from"./separator-DMopkgTA.js";import{B as k}from"./button-B8f8jW4H.js";import{u as S}from"./useTranslation-BW0o-tkY.js";import"./SiteLogo-DML5Oulk.js";import"./dropdown-menu-CpMN0BZ0.js";import"./utils-RgT4yCq8.js";import"./input-CT5MkJwj.js";import"./sheet-Cp4V1hdh.js";import"./useFlashMessages-CQoLOBuv.js";import"./AdSlot-HY9FvbmL.js";import"./RightSidebarFooter-BO77c1r9.js";import"./avatar-1RNhlzAH.js";import"./badge-CJ9RzXvO.js";import"./card-BKDXjfy_.js";function O({tag:n,initialPosts:m}){const{t:s}=S(),[l,h]=o.useState(m.data||[]),[r,i]=o.useState(m.next_page_url),[a,x]=o.useState(!1),c=o.useRef(null);o.useEffect(()=>{if(!c.current)return;const t=new IntersectionObserver(d=>{d[0].isIntersecting&&r&&!a&&p()},{threshold:1});return t.observe(c.current),()=>t.disconnect()},[r,a]);const p=async()=>{if(!(!r||a)){x(!0);try{const t=await f.get(r,{headers:{Accept:"application/json"}});t.data&&Array.isArray(t.data.data)?(h(d=>[...d,...t.data.data]),i(t.data.next_page_url)):i(null)}catch(t){console.error("Failed to load more posts:",t),i(null)}finally{x(!1)}}};return e.jsxs(v,{children:[e.jsx(g,{title:`${s("_tag","Tag")}: ${n}`}),e.jsx("div",{className:"bg-background min-h-screen pb-20",children:e.jsxs("div",{className:"container mx-auto px-4 sm:px-6 lg:px-8 py-8 max-w-[1280px]",children:[e.jsxs("nav",{className:"flex items-center text-sm text-muted-foreground mb-6 font-medium",children:[e.jsx(u,{href:"/",className:"hover:text-primary hover:underline transition-colors",children:s("_home","Home")}),e.jsx(j,{className:"w-4 h-4 mx-2 text-gray-400 rtl:rotate-180"}),e.jsxs("span",{className:"font-bold text-foreground",children:[s("_tag","Tag"),": ",n]})]}),e.jsxs("div",{className:"mb-8",children:[e.jsxs("h1",{className:"text-4xl font-extrabold tracking-tight capitalize flex items-center gap-3",children:[e.jsx(_,{className:"w-10 h-10 text-primary"})," ",n]}),e.jsxs("p",{className:"text-muted-foreground mt-2 text-lg",children:[s("_discover_articles","Discover articles related to the tag"),' "',n,'".']})]}),e.jsx(w,{className:"my-8"}),l.length>0?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6",children:l.map(t=>e.jsx(y,{post:t},t.id))}):e.jsxs("div",{className:"text-center py-20 bg-muted/30 rounded-lg border border-dashed flex flex-col items-center",children:[e.jsx(N,{className:"w-12 h-12 text-muted-foreground/50 mb-4"}),e.jsx("h3",{className:"text-xl font-bold text-muted-foreground",children:s("_no_posts_found","No posts found for this tag.")}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s("_check_back_later","Check back later for updates.")}),e.jsx(k,{asChild:!0,className:"mt-6",variant:"outline",children:e.jsx(u,{href:"/",children:s("_back_home","Back Home")})})]}),e.jsxs("div",{ref:c,className:"py-10 text-center",children:[a&&e.jsxs("div",{className:"flex justify-center items-center gap-2 text-muted-foreground",children:[e.jsx(b,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("_loading_more","Loading more...")})]}),!a&&!r&&l.length>0&&e.jsx("p",{className:"text-sm text-muted-foreground italic",children:s("_end_of_list","You've reached the end.")})]})]})})]})}export{O as default};
