import{j as e,C as L,h as k}from"./index-LezXLmi1.js";import{c as z,r as l,L as o}from"./react-vendor-CTc1fkrV.js";import{s as i}from"./supabase-D3Ol-udV.js";import{A as g}from"./arrow-left-Df-Esdjl.js";import{C as F}from"./calendar-DtvATCdd.js";import{C as E}from"./chevron-up-40IYNBnb.js";import{A as u}from"./arrow-right-BZG7bK-7.js";import"./supabase-vendor-DCVGAqLS.js";function Q(){const{slug:n}=z(),[t,f]=l.useState(null),[d,m]=l.useState([]),[b,j]=l.useState(!0),[c,y]=l.useState(null);l.useEffect(()=>{n&&(w(),window.scrollTo(0,0))},[n]),l.useEffect(()=>{t&&(P(),_())},[t]);const w=async()=>{try{const{data:s,error:a}=await i.from("blog_posts").select("*").eq("slug",n).eq("published",!0).maybeSingle();if(a)throw a;s&&(f(s),s.related_post_ids&&s.related_post_ids.length>0?N(s.related_post_ids):v(s.categories))}catch(s){console.error("Error fetching blog post:",s)}finally{j(!1)}},N=async s=>{try{const{data:a,error:r}=await i.from("blog_posts").select("id, title, slug, excerpt, featured_image").in("id",s).eq("published",!0).limit(4);if(r)throw r;a&&m(a)}catch(a){console.error("Error fetching related posts:",a)}},v=async s=>{if(!(!s||s.length===0))try{const{data:a,error:r}=await i.from("blog_posts").select("id, title, slug, excerpt, featured_image, categories").eq("published",!0).neq("slug",n).limit(10);if(r)throw r;if(a){const p=a.filter(R=>R.categories.some(C=>s.includes(C))).slice(0,4);m(p)}}catch(a){console.error("Error fetching related posts:",a)}},_=async()=>{if(t)try{await i.rpc("increment",{row_id:t.id,table_name:"blog_posts",column_name:"view_count"}).catch(()=>{i.from("blog_posts").update({view_count:t.view_count+1}).eq("id",t.id)})}catch(s){console.error("Error incrementing view count:",s)}},P=()=>{if(!t)return;document.title=t.meta_title||t.title;const s=document.querySelector('meta[name="description"]');s&&s.setAttribute("content",t.meta_description||t.excerpt)},q=s=>new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),A=s=>{const r=s.replace(/<[^>]*>/g,"").split(/\s+/).length;return Math.ceil(r/200)},S=s=>{y(c===s?null:s)},x=()=>t?{"@context":"https://schema.org","@type":"Article",headline:t.title,description:t.excerpt,image:t.featured_image,datePublished:t.published_date,dateModified:t.updated_at||t.published_date,author:{"@type":"Organization",name:"All Phase Construction USA",url:"https://allphaseusa.com"},publisher:{"@type":"Organization",name:"All Phase Construction USA",logo:{"@type":"ImageObject",url:"https://allphaseusa.com/allphase-logo-white.svg"}},mainEntityOfPage:{"@type":"WebPage","@id":`https://allphaseusa.com/blog/${t.slug}`},about:{"@type":"Thing",name:"Roofing"},mentions:[{"@type":"Place",name:"Broward County",address:{"@type":"PostalAddress",addressRegion:"FL"}},{"@type":"Place",name:"Palm Beach County",address:{"@type":"PostalAddress",addressRegion:"FL"}},{"@type":"Place",name:"Deerfield Beach",address:{"@type":"PostalAddress",addressLocality:"Deerfield Beach",addressRegion:"FL"}}]}:null,h=()=>!t||!t.faqs||t.faqs.length===0?null:{"@context":"https://schema.org","@type":"FAQPage",mainEntity:t.faqs.map(a=>({"@type":"Question",name:a.question,acceptedAnswer:{"@type":"Answer",text:a.answer}}))};return b?e.jsx("div",{className:"min-h-screen flex items-center justify-center pt-36",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"inline-block animate-spin rounded-full h-12 w-12 border-b-2 border-red-600"}),e.jsx("p",{className:"mt-4 text-gray-400",children:"Loading post..."})]})}):t?e.jsxs(e.Fragment,{children:[x()&&e.jsx("script",{type:"application/ld+json",dangerouslySetInnerHTML:{__html:JSON.stringify(x())}}),h()&&e.jsx("script",{type:"application/ld+json",dangerouslySetInnerHTML:{__html:JSON.stringify(h())}}),e.jsxs("article",{className:"pt-36",children:[e.jsx("div",{className:"bg-gradient-to-br from-black via-zinc-900 to-black text-white py-16",children:e.jsxs("div",{className:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8",children:[e.jsxs(o,{to:"/blog",className:"inline-flex items-center gap-2 text-gray-300 hover:text-white mb-6 transition-colors",children:[e.jsx(g,{className:"w-4 h-4"}),"Back to Blog"]}),t.categories.length>0&&e.jsx("div",{className:"mb-4",children:e.jsx("span",{className:"bg-red-600 text-white px-4 py-1.5 rounded-full text-sm font-medium",children:t.categories[0]})}),e.jsx("h1",{className:"text-4xl md:text-5xl font-bold mb-6 leading-tight",children:t.title}),e.jsxs("div",{className:"flex flex-wrap items-center gap-6 text-gray-300",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{className:"w-5 h-5"}),e.jsx("time",{dateTime:t.published_date,children:q(t.published_date)})]}),t.categories.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:"•"}),e.jsx("span",{children:t.categories[0]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{className:"w-5 h-5"}),e.jsxs("span",{children:[A(t.content)," min read"]})]})]})]})}),e.jsxs("div",{className:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-12",children:[e.jsx("div",{className:"mb-12",children:e.jsx("img",{src:t.featured_image,alt:t.title,loading:"lazy",decoding:"async",className:"w-full h-auto rounded-xl shadow-2xl"})}),e.jsx("div",{className:"prose prose-lg prose-invert max-w-none prose-headings:font-bold prose-a:no-underline hover:prose-a:underline prose-img:rounded-lg prose-img:shadow-lg",dangerouslySetInnerHTML:{__html:t.content}}),t.tags&&t.tags.length>0&&e.jsx("div",{className:"mt-12 pt-8 border-t border-zinc-800",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:t.tags.map((s,a)=>e.jsxs("span",{className:"bg-zinc-800 text-white px-3 py-1 rounded-full text-sm",children:["#",s]},a))})})]}),t.faqs&&t.faqs.length>0&&e.jsx("div",{className:"bg-zinc-900 py-16",children:e.jsxs("div",{className:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8",children:[e.jsx("h2",{className:"text-3xl font-bold text-white mb-8",children:"Frequently Asked Questions"}),e.jsx("div",{className:"space-y-4",children:t.faqs.map((s,a)=>e.jsxs("div",{className:"bg-zinc-800 rounded-lg shadow-md overflow-hidden",children:[e.jsxs("button",{onClick:()=>S(a),className:"w-full flex items-center justify-between p-6 text-left hover:bg-zinc-700 transition-colors",children:[e.jsx("span",{className:"font-semibold text-white pr-4",children:s.question}),c===a?e.jsx(E,{className:"w-5 h-5 text-red-600 flex-shrink-0"}):e.jsx(k,{className:"w-5 h-5 text-gray-400 flex-shrink-0"})]}),c===a&&e.jsx("div",{className:"px-6 pb-6",children:e.jsx("p",{className:"text-gray-300 leading-relaxed",children:s.answer})})]},a))})]})}),d.length>0&&e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-16",children:[e.jsx("h2",{className:"text-3xl font-bold text-white mb-8",children:"Related Articles"}),e.jsx("div",{className:"grid md:grid-cols-2 lg:grid-cols-4 gap-8",children:d.map(s=>e.jsxs(o,{to:`/blog/${s.slug}`,className:"bg-zinc-900 rounded-xl shadow-md overflow-hidden hover:shadow-xl transition-all group border border-zinc-800",children:[e.jsx("div",{className:"relative h-48 overflow-hidden",children:e.jsx("img",{src:s.featured_image,alt:s.title,loading:"lazy",decoding:"async",className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"})}),e.jsxs("div",{className:"p-6",children:[e.jsx("h3",{className:"text-lg font-bold text-white mb-2 group-hover:text-red-600 transition-colors line-clamp-2",children:s.title}),e.jsx("p",{className:"text-gray-400 text-sm line-clamp-2 mb-3",children:s.excerpt}),e.jsxs("div",{className:"flex items-center text-red-600 font-semibold text-sm",children:["Read More",e.jsx(u,{className:"w-4 h-4 ml-1"})]})]})]},s.id))})]}),e.jsx("div",{className:"bg-gradient-to-br from-red-600 to-red-700 text-white py-16",children:e.jsxs("div",{className:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 text-center",children:[e.jsx("h2",{className:"text-3xl md:text-4xl font-bold mb-6",children:"Ready to Start Your Roofing Project?"}),e.jsx("p",{className:"text-xl text-white mb-8",children:"Get a free consultation and estimate from South Florida's trusted roofing experts"}),e.jsx("div",{className:"flex flex-col sm:flex-row gap-4 justify-center",children:e.jsxs(o,{to:"/roof-cost-calculator",className:"bg-white text-red-600 px-8 py-4 rounded-lg font-bold hover:bg-gray-100 transition-all shadow-xl inline-flex items-center justify-center gap-2",children:["Request a Roofing Estimate",e.jsx(u,{className:"w-5 h-5"})]})})]})})]})]}):e.jsx("div",{className:"min-h-screen flex items-center justify-center pt-36",children:e.jsxs("div",{className:"text-center max-w-md",children:[e.jsx("h1",{className:"text-4xl font-bold text-white mb-4",children:"Post Not Found"}),e.jsx("p",{className:"text-gray-400 mb-8",children:"The blog post you're looking for doesn't exist or has been removed."}),e.jsxs(o,{to:"/blog",className:"inline-flex items-center gap-2 bg-red-600 text-white px-6 py-3 rounded-lg font-semibold hover:bg-red-700 transition-colors",children:[e.jsx(g,{className:"w-5 h-5"}),"Back to Blog"]})]})})}export{Q as default};