import{j as e}from"./query-vendor-CZu0EHPe.js";import{L as S,R as C,r as j,k as R}from"./react-vendor-0bvDbF03.js";import{b as $,p as L,B as _,S as B,q as N,U as I}from"./index-CwGgW-mc.js";import{p as P}from"./purify.es-D9RiKzGB.js";import{C as v}from"./card-MP0DL603.js";import{S as T}from"./skeleton-CuroRPkC.js";import{I as E}from"./image-BCh_IMMb.js";import{R as W}from"./rotate-ccw-WJG_6zgW.js";import{S as A}from"./ShareCard-CASs-O6e.js";import{b as D}from"./useBlogData-BtUkmVHs.js";import{B as F}from"./BreadcrumbNavigation-BdjsMZvM.js";import{u as w}from"./i18n-vendor-Cl4-lKeC.js";import{A as z}from"./arrow-left-CCKC67jh.js";import{C as O}from"./calendar-BIaMnTJn.js";import{C as q}from"./clock-CoodSkBk.js";import"./supabase-vendor-CNV44oIa.js";import"./helmet-vendor-NlTFkN97.js";const k=["https://storysparkle.org","http://storysparkle.org","https://www.storysparkle.org","http://www.storysparkle.org"],H=s=>{if(!s)return null;if(s.startsWith("/"))return s;for(const n of k)if(s.startsWith(n)){const r=s.slice(n.length);return r.startsWith("/")?r:`/${r||""}`||"/"}return null},y=s=>!s||!s.includes("StorySparkle")?s:s.split(/(StorySparkle)/g).map((r,t)=>r==="StorySparkle"?e.jsx(L,{variant:"inline"},t):e.jsx(C.Fragment,{children:r},t)),G=({src:s,alt:n,width:r,height:t,caption:l})=>{const[a,g]=j.useState(!0),[u,d]=j.useState(!1),[o,c]=j.useState(0),h=2,x=j.useCallback(()=>{g(!1),d(!1)},[]),m=j.useCallback(()=>{g(!1),d(!0)},[]),p=j.useCallback(()=>{if(o<h){c(b=>b+1),g(!0),d(!1);const i=new Image;i.onload=x,i.onerror=m,i.src=`${s}?t=${Date.now()}`}},[s,o,h,x,m]);if(u)return e.jsxs("figure",{className:"mb-6 flex flex-col items-center",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center bg-muted rounded-lg p-8 min-h-[200px]",children:[e.jsx(E,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4 text-center",children:"Image failed to load"}),o<h&&e.jsxs(_,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[e.jsx(W,{className:"h-4 w-4"}),"Retry (",o+1,"/",h+1,")"]})]}),l&&e.jsx("figcaption",{className:"text-sm text-muted-foreground mt-2 text-center italic",children:l})]});const f=r&&r!=="auto"||t&&t!=="auto";return e.jsxs("figure",{className:"mb-6 flex flex-col items-center",children:[e.jsxs("div",{className:"relative w-full",style:f?void 0:{aspectRatio:"16 / 9",maxWidth:"100%"},children:[a&&e.jsx(T,{className:"absolute inset-0 rounded-lg w-full h-full"}),e.jsx("img",{src:o>0?`${s}?t=${Date.now()}`:s,alt:n,width:f?void 0:1200,height:f?void 0:675,loading:"lazy",decoding:"async",onLoad:x,onError:m,className:`rounded-lg shadow-md transition-opacity ${a?"opacity-0":"opacity-100"}`,style:{width:r&&r!=="auto"?r:"100%",height:t&&t!=="auto"?t:"auto",aspectRatio:f?void 0:"16 / 9",objectFit:"cover",maxWidth:"100%"}})]}),l&&e.jsx("figcaption",{className:"text-sm text-muted-foreground mt-2 text-center italic",children:l})]})},U=({content:s})=>{const{getLocalizedPath:n}=$(),r=(t,l)=>{switch(t.type){case"paragraph":return e.jsx("p",{className:"mb-4 leading-relaxed",children:y(t.data.text||"")},l);case"heading":const a=`h${t.data.level||2}`;return e.jsx(a,{className:`font-bold mb-4 ${t.data.level===1?"text-3xl":t.data.level===2?"text-2xl":t.data.level===3?"text-xl":"text-lg"}`,children:y(t.data.text||"")},l);case"image":return e.jsx(G,{src:t.data.url,alt:t.data.alt||"",width:t.data.width,height:t.data.height,caption:t.data.caption},l);case"youtube":return e.jsxs("div",{className:"mb-6",children:[e.jsx("div",{className:"aspect-video",children:e.jsx("iframe",{src:`https://www.youtube.com/embed/${t.data.videoId}`,title:t.data.title||"YouTube video",allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,className:"w-full h-full rounded-lg"})}),t.data.title&&e.jsx("p",{className:"text-sm text-muted-foreground mt-2 text-center",children:t.data.title})]},l);case"quote":return e.jsxs(v,{className:"border-l-4 border-nature-coral bg-nature-yellow/10 p-6 mb-6",children:[e.jsxs("blockquote",{className:"text-lg italic",children:['"',t.data.text,'"']}),t.data.author&&e.jsxs("cite",{className:"block text-sm text-muted-foreground mt-2",children:["— ",t.data.author]})]},l);case"list":const g=t.data.style==="ordered"?"ol":"ul";return e.jsx(g,{className:`mb-4 ml-6 ${t.data.style==="ordered"?"list-decimal":"list-disc"}`,children:t.data.items.map((u,d)=>e.jsx("li",{className:"mb-1",children:u},d))},l);case"rich-text":return e.jsx("div",{className:"mb-4 leading-relaxed",dangerouslySetInnerHTML:{__html:P.sanitize(t.data.html||"",{ALLOWED_TAGS:["b","i","u","br","p","a","strong","em","h1","h2","h3","h4","ul","ol","li","span","div","blockquote","img"],ALLOWED_ATTR:["href","target","rel","class","style","src","alt","width","height","loading","decoding"]})}},l);case"button":{const u=t.data.label||"Click here",d=t.data.url||"",o=t.data.variant||"primary",c=t.data.align||"center",h=o==="primary"?"bg-nature-coral text-white hover:bg-nature-coral/90":o==="secondary"?"bg-nature-green text-white hover:bg-nature-green/90":o==="outline"?"border-2 border-nature-coral text-nature-coral bg-transparent hover:bg-nature-coral/10":"bg-transparent text-nature-coral hover:bg-nature-coral/10",x=c==="left"?"justify-start":c==="right"?"justify-end":"justify-center",m=`inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-semibold uppercase tracking-wide h-11 px-8 transition-all duration-300 hover:scale-[1.02] active:scale-[0.98] ${h}`,p=H(d);return e.jsx("div",{className:`mb-6 flex ${x}`,children:p?e.jsx(S,{to:n(p),className:m,children:u}):e.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:m,children:u})},l)}case"link":return e.jsx(v,{className:"p-4 mb-6 border border-nature-green/20",children:e.jsxs("a",{href:t.data.url,target:"_blank",rel:"noopener noreferrer",className:"block hover:bg-nature-green/5 transition-colors rounded",children:[e.jsx("h4",{className:"font-semibold text-nature-green mb-1",children:t.data.title}),t.data.description&&e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:t.data.description}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.data.url})]})},l);default:return null}};return e.jsx("div",{className:"prose prose-lg max-w-none",children:s.blocks.map((t,l)=>r(t,l))})},M=s=>!s||!s.includes("StorySparkle")?s:s.split(/(StorySparkle)/g).map((r,t)=>r==="StorySparkle"?e.jsx(L,{variant:"inline"},t):e.jsx(C.Fragment,{children:r},t)),de=()=>{const{slug:s}=R(),{t:n}=w("blog"),{t:r}=w("newsletter"),{t}=w("navbar"),{getLocalizedPath:l}=$(),{post:a,loading:g,error:u}=D(s||""),d=typeof window<"u"&&window.location.pathname.includes("/blog/newsletter/"),o=a?.categories?.some(i=>i?.slug==="newsletter")??!1,c=d||o,h=c?r("title"):"Blog",x=c?"/blog/newsletter":"/blog",m=c?`/blog/newsletter/${a?.slug}`:`/blog/${a?.slug}`,p=c?r("backToNewsletter"):n("backToBlog");if(g)return e.jsx("div",{className:"min-h-screen bg-gradient-to-b from-teal-100 via-yellow-200 to-red-300",children:e.jsx("div",{className:"container mx-auto px-4 py-8",children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-1/4 mb-6"}),e.jsx("div",{className:"h-12 bg-gray-200 rounded w-3/4 mb-4"}),e.jsx("div",{className:"aspect-[16/9] bg-gray-200 rounded mb-6 w-full"}),e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((i,b)=>e.jsx("div",{className:"h-4 bg-gray-200 rounded"},b))})]})})});if(u||!a)return e.jsx("div",{className:"min-h-screen bg-gradient-to-b from-teal-100 via-yellow-200 to-red-300",children:e.jsxs("div",{className:"container mx-auto px-4 py-8 text-center",children:[e.jsx("h1",{className:"text-2xl font-bold mb-4",children:"Post Not Found"}),e.jsx(S,{to:l(x),children:e.jsxs(_,{children:[e.jsx(z,{className:"mr-2 h-4 w-4"}),p]})})]})});const f=a.published_at?new Date(a.published_at).toLocaleDateString():"";return e.jsxs("div",{className:c?"min-h-screen bg-gradient-to-b from-amber-50 via-white to-amber-50/40":"min-h-screen bg-gradient-to-b from-teal-100 via-yellow-200 to-red-300",children:[e.jsx(B,{title:a.seo_title||`${a.title} | StorySparkle Blog`,description:a.seo_description||a.excerpt,canonical:l(m),ogImage:a.featured_image}),e.jsxs("article",{className:"container mx-auto px-4 py-8",children:[e.jsx(F,{items:[{name:t("home"),path:"/"},{name:t("blog"),path:"/blog"},...c?[{name:h,path:"/blog/newsletter"}]:[],{name:a.title,path:m}]}),e.jsxs("header",{className:"mb-8",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 mb-4",children:[a.categories?.map(i=>e.jsx(N,{variant:"outline",style:{borderColor:i.color},children:i.name},i.id)),a.is_featured&&e.jsx(N,{className:"bg-nature-coral",children:"Featured"})]}),e.jsx("h1",{className:"text-4xl font-bold mb-6",children:M(a.title)}),a.featured_image&&e.jsx("img",{src:a.featured_image,alt:a.title,width:1200,height:675,fetchPriority:"high",decoding:"async",className:"rounded-xl shadow-md mb-8 w-full object-cover",style:{aspectRatio:"16 / 9",height:"auto"}}),e.jsxs("div",{className:"flex flex-wrap items-center gap-6 text-sm text-muted-foreground mb-6",children:[a.author?.username&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-4 w-4"}),n("byAuthor",{author:a.author.username})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{className:"h-4 w-4"}),n("publishedOn",{date:f})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4"}),n("readingTime",{minutes:a.reading_time_minutes})]})]})]}),e.jsx("div",{className:"max-w-4xl mx-auto",children:e.jsx(U,{content:a.content})}),e.jsx("footer",{className:"mt-12 pt-8 border-t",children:e.jsxs("div",{className:"flex flex-col lg:flex-row justify-between items-start lg:items-center gap-4",children:[e.jsx(A,{heading:n("sharing.title"),subheading:n("sharing.description"),title:a.title,description:a.excerpt,url:`${window.location.origin}${l(`/blog/${a.slug}`)}`}),a.tags&&a.tags.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold mb-2",children:n("tags")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:a.tags.map((i,b)=>e.jsx(N,{variant:"secondary",children:i},b))})]})]})})]})]})};export{de as default};
//# sourceMappingURL=BlogPostPage-CMsY5OqT.js.map