import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { computeReadingTime } from '@actuate-media/cms-core/page-sections';
function formatDate(value) {
    if (!value)
        return '';
    const d = new Date(value);
    if (Number.isNaN(d.getTime()))
        return '';
    return d.toLocaleDateString(undefined, { year: 'numeric', month: 'long', day: 'numeric' });
}
/**
 * Renders a post's header region from the template's design config plus the
 * post's own field values. Uses the same fixed website palette as the
 * section renderers (see sections/parts.tsx) so the editor canvas and the
 * public preview match.
 */
export function PostHeader({ config, context }) {
    const title = context.title || 'Untitled post';
    const date = config.showDate ? formatDate(context.publishDate) : '';
    const overlay = config.layout === 'overlay' && config.showFeaturedImage && context.featuredImageUrl;
    const align = config.layout === 'centered' ? 'text-center mx-auto items-center' : 'text-left';
    const meta = (_jsxs("div", { className: `mt-4 flex flex-wrap gap-x-3 gap-y-1 text-sm ${config.layout === 'centered' ? 'justify-center' : ''} ${overlay ? 'text-white/80' : 'text-zinc-500'}`, children: [config.showCategory && context.category && (_jsx("span", { className: "font-medium text-violet-500", children: context.category })), config.showAuthor && _jsx("span", { children: context.author?.name || 'Author name' }), date && _jsx("span", { children: date }), config.showReadingTime && _jsxs("span", { children: [computeReadingTime(context.body), " min read"] })] }));
    if (overlay) {
        return (_jsxs("header", { className: "relative", children: [_jsx("img", { src: context.featuredImageUrl, alt: "", className: "h-[360px] w-full object-cover" }), _jsx("div", { className: "absolute inset-0 bg-linear-to-t from-black/70 to-black/10", "aria-hidden": true }), _jsx("div", { className: "absolute inset-x-0 bottom-0 px-6 pb-8", children: _jsxs("div", { className: `mx-auto flex max-w-3xl flex-col ${align}`, children: [_jsx("h1", { className: "text-3xl font-semibold tracking-tight text-white sm:text-4xl", children: title }), config.showExcerpt && context.excerpt && (_jsx("p", { className: "mt-3 max-w-2xl text-lg text-white/90", children: context.excerpt })), meta] }) })] }));
    }
    return (_jsxs("header", { className: "bg-white px-6 pt-12 pb-2", children: [_jsxs("div", { className: `flex max-w-3xl flex-col ${align} ${config.layout === 'centered' ? 'mx-auto' : ''}`, children: [_jsx("h1", { className: "text-3xl font-semibold tracking-tight text-zinc-900 sm:text-4xl", children: title }), config.showExcerpt && context.excerpt && (_jsx("p", { className: "mt-3 max-w-2xl text-lg text-zinc-600", children: context.excerpt })), meta] }), config.showFeaturedImage && context.featuredImageUrl && (_jsx("div", { className: "mx-auto mt-8 max-w-4xl", children: _jsx("img", { src: context.featuredImageUrl, alt: "", className: "aspect-video w-full rounded-xl object-cover" }) }))] }));
}
//# sourceMappingURL=PostHeader.js.map