import{j as e}from"./query-DJMphkOq.js";import{a as o,a5 as I,o as v,p as E,A as w}from"./icons-B6XnNDpJ.js";import{u as G,B as D,a as O}from"./index-BaQQEgxi.js";import{c as $}from"./react-vendor-wls9bBVT.js";import"./supabase-BiHzSKx7.js";const i={blue:"bg-blue-100 dark:bg-blue-900/40 text-blue-700 dark:text-blue-300",red:"bg-red-100 dark:bg-red-900/40 text-red-700 dark:text-red-300",indigo:"bg-indigo-100 dark:bg-indigo-900/40 text-indigo-700 dark:text-indigo-300",gray:"bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300",green:"bg-green-100 dark:bg-green-900/40 text-green-700 dark:text-green-300",orange:"bg-orange-100 dark:bg-orange-900/40 text-orange-700 dark:text-orange-300",purple:"bg-purple-100 dark:bg-purple-900/40 text-purple-700 dark:text-purple-300",cyan:"bg-cyan-100 dark:bg-cyan-900/40 text-cyan-700 dark:text-cyan-300"},j=[i.blue,i.indigo,i.green,i.orange,i.purple,i.cyan];function z(l){const s=(l||"").replace(/<[^>]+>/g,"");return Math.max(1,Math.round(s.trim().split(/\s+/).length/200))}function M(){var f;const{t:l,lang:s}=G(),k=$(),[g,N]=o.useState([]),[C,_]=o.useState([]),[T,S]=o.useState(!0),[n,B]=o.useState("all");o.useEffect(()=>{Promise.all([D.filter({status:"published"},"-created_date"),O.filter({is_active:!0},"sort_order")]).then(([a,r])=>{N(a),_(r),S(!1)})},[]);const b={en:{"IT Tips":"IT Tips","Cyber Security":"Cyber Security","Business IT":"Business IT",News:"News","How-To":"How-To"},cy:{"IT Tips":"Awgrymiadau TG","Cyber Security":"Seiberddiogelwch","Business IT":"TG Busnes",News:"Newyddion","How-To":"Sut i..."}},u=[...new Set(g.map(a=>a.category).filter(Boolean))],L=[{key:"all",label:s==="cy"?l("cat_all"):"All"},...u.map(a=>({key:a,label:(s==="cy"?b.cy[a]:b.en[a])||a}))],d=a=>s==="cy"&&a.title_cy?a.title_cy:a.title,c=a=>s==="cy"&&a.excerpt_cy?a.excerpt_cy:a.excerpt,x=n==="all"?g:g.filter(a=>a.category===n),t=x[0],h=x.slice(1),y=(a,r)=>{r&&(r.shiftKey||r.ctrlKey||r.metaKey)||a.slug&&(k(`/blog/${a.slug}`),window.scrollTo({top:0,behavior:"instant"}))},p=a=>{const r=C.find(A=>A.name===a);if(r)return i[r.color]||i.blue;const m=u.indexOf(a);return j[m%j.length]||i.blue};return e.jsxs("div",{className:"bg-white dark:bg-gray-950 min-h-screen",children:[e.jsxs("section",{className:"relative bg-gradient-to-br from-gray-900 via-gray-900 to-blue-950 overflow-hidden h-[420px] flex items-center",children:[e.jsx("div",{className:"absolute inset-0 opacity-5",style:{backgroundImage:"radial-gradient(circle at 2px 2px, white 1px, transparent 0)",backgroundSize:"32px 32px"}}),e.jsxs("div",{className:"absolute right-0 top-0 bottom-0 w-1/2 hidden md:block overflow-hidden",children:[e.jsx("img",{src:"https://images.unsplash.com/photo-1504711434969-e33886168f5c?w=900&h=480&q=75&auto=format&fit=crop&fm=webp",alt:s==="cy"?"Blog TG CefniTech — awgrymiadau a chanllawiau":"CefniTech IT blog — tips and guides",loading:"eager",fetchpriority:"high",width:"900",height:"480",className:"w-full h-full object-cover opacity-20"}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-r from-gray-900 via-gray-900/40 to-transparent"})]}),e.jsx("div",{className:"relative max-w-6xl mx-auto px-6 py-20 w-full",children:e.jsxs("div",{className:"max-w-xl",children:[e.jsx("p",{className:"text-blue-400 text-xs font-bold uppercase tracking-widest mb-4 flex items-center gap-2",children:l("blog_label")}),e.jsx("h1",{className:"text-4xl md:text-5xl font-black text-white tracking-tight leading-[1.1] mb-5",children:l("blog_h1")}),e.jsx("p",{className:"text-gray-300 leading-relaxed max-w-md",children:l("blog_sub")})]})})]}),e.jsx("div",{className:"sticky top-16 z-30 bg-white/90 dark:bg-gray-900/90 backdrop-blur-md border-b border-gray-100 dark:border-gray-800 shadow-sm",children:e.jsx("div",{className:"max-w-6xl mx-auto px-6 py-3 flex gap-2 overflow-x-auto",role:"tablist","aria-label":"Filter blog posts by category",children:L.map(a=>e.jsx("button",{onClick:()=>B(a.key),role:"tab","aria-selected":n===a.key,className:`px-4 py-2 rounded-full text-xs font-bold whitespace-nowrap transition-all ${n===a.key?"bg-blue-600 text-white shadow-md":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:a.label},a.key))})}),e.jsx("div",{className:"max-w-6xl mx-auto px-6 py-10",children:T?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[1,2,3,4,5,6].map(a=>e.jsx("div",{className:"bg-gray-100 dark:bg-gray-800 rounded-2xl h-72 animate-pulse"},a))}):x.length===0?e.jsxs("div",{className:"text-center py-24",children:[e.jsx(I,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-400 text-lg font-semibold",children:l("blog_empty")})]}):e.jsxs(e.Fragment,{children:[t&&e.jsxs("div",{onClick:a=>y(t,a),className:"group relative bg-white dark:bg-gray-800 rounded-2xl overflow-hidden border border-gray-100 dark:border-gray-700 hover:shadow-2xl transition-all duration-300 cursor-pointer mb-8 md:flex",children:[e.jsxs("div",{className:"relative overflow-hidden md:w-1/2 h-56 md:h-auto shrink-0",children:[t.cover_image?e.jsx("img",{src:t.cover_image,alt:`Cover image for: ${d(t)}`,loading:"lazy",className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-700"}):e.jsx("div",{className:"w-full h-full bg-gradient-to-br from-blue-700 to-indigo-900 flex items-center justify-center min-h-56",children:e.jsx("span",{className:"text-blue-200 text-8xl font-black opacity-20",children:(f=t.title)==null?void 0:f[0]})}),e.jsx("div",{className:"absolute top-4 left-4",children:e.jsx("span",{className:`text-xs font-bold px-3 py-1.5 rounded-full ${p(t.category)}`,children:t.category})})]}),e.jsxs("div",{className:"p-8 flex flex-col justify-center md:w-1/2",children:[e.jsx("span",{className:"text-xs font-bold text-blue-600 dark:text-blue-400 uppercase tracking-widest mb-3",children:s==="cy"?"Erthygl Ddiweddaraf":"Latest Article"}),e.jsx("h2",{className:"text-2xl md:text-3xl font-black text-gray-900 dark:text-white mb-3 leading-tight group-hover:text-blue-600 dark:group-hover:text-blue-400 transition-colors",children:d(t)}),c(t)&&e.jsx("p",{className:"text-gray-500 dark:text-gray-400 leading-relaxed mb-6 line-clamp-3 text-sm",children:c(t)}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-gray-400 dark:text-gray-500",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(v,{className:"w-3.5 h-3.5"}),new Date(t.created_date).toLocaleDateString(s==="cy"?"cy-GB":"en-GB",{day:"numeric",month:"long",year:"numeric"})]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(E,{className:"w-3.5 h-3.5"}),z(t.content)," ",s==="cy"?"mun":"min read"]})]}),e.jsxs("span",{className:"text-blue-600 dark:text-blue-400 font-bold flex items-center gap-1 group-hover:gap-2 transition-all",children:[l("blog_read")," ",e.jsx(w,{className:"w-3.5 h-3.5"})]})]})]})]}),h.length>0&&e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6",children:h.map(a=>{var r;return e.jsxs("div",{onClick:m=>y(a,m),className:"group bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-2xl overflow-hidden hover:shadow-xl hover:-translate-y-1 transition-all duration-300 cursor-pointer flex flex-col",children:[e.jsxs("div",{className:"relative overflow-hidden h-48 shrink-0",children:[a.cover_image?e.jsx("img",{src:a.cover_image,alt:d(a),loading:"lazy",className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-500"}):e.jsx("div",{className:"w-full h-full bg-gradient-to-br from-blue-700 to-indigo-900 flex items-center justify-center",children:e.jsx("span",{className:"text-blue-200 text-6xl font-black opacity-20",children:(r=a.title)==null?void 0:r[0]})}),e.jsx("div",{className:"absolute top-3 left-3",children:e.jsx("span",{className:`text-xs font-bold px-2.5 py-1 rounded-full ${p(a.category)}`,children:a.category})})]}),e.jsxs("div",{className:"p-5 flex flex-col flex-1",children:[e.jsx("h3",{className:"font-bold text-gray-900 dark:text-white mb-2 group-hover:text-blue-600 dark:group-hover:text-blue-400 transition-colors leading-snug line-clamp-2 text-base",children:d(a)}),c(a)&&e.jsx("p",{className:"text-gray-500 dark:text-gray-400 text-sm leading-relaxed line-clamp-2 mb-4",children:c(a)}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-gray-400 dark:text-gray-500 mt-auto pt-4 border-t border-gray-100 dark:border-gray-700",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(v,{className:"w-3 h-3"}),new Date(a.created_date).toLocaleDateString(s==="cy"?"cy-GB":"en-GB",{day:"numeric",month:"short",year:"numeric"})]}),e.jsxs("span",{className:"text-blue-600 dark:text-blue-400 font-bold flex items-center gap-1 group-hover:gap-2 transition-all",children:[l("blog_read")," ",e.jsx(w,{className:"w-3 h-3"})]})]})]})]},a.id)})})]})})]})}export{M as default};