"use client";
'use strict';

const jsxRuntime = require('react/jsx-runtime');
const context = require('@btst/stack/context');
const dateFns = require('date-fns');
const blogHooks = require('../../hooks/blog-hooks.cjs');
const emptyList = require('../shared/empty-list.cjs');
const markdownContent = require('../shared/markdown-content.cjs');
const pageHeader = require('../shared/page-header.cjs');
const pageWrapper = require('../shared/page-wrapper.cjs');
const defaults = require('../shared/defaults.cjs');
const index = require('../../localization/index.cjs');
const postNavigation = require('../shared/post-navigation.cjs');
const recentPostsCarousel = require('../shared/recent-posts-carousel.cjs');
const badge = require('../../../../../../../ui/src/components/badge.cjs');
const useRouteLifecycle = require('../../../../../../../ui/src/hooks/use-route-lifecycle.cjs');
const onThisPage = require('../shared/on-this-page.cjs');

function PostPage({ slug }) {
  const overrides = context.usePluginOverrides("blog", {
    Image: defaults.DefaultImage,
    localization: index.BLOG_LOCALIZATION
  });
  const { Image, localization } = overrides;
  useRouteLifecycle.useRouteLifecycle({
    routeName: "post",
    context: {
      path: `/blog/${slug}`,
      params: { slug },
      isSSR: typeof window === "undefined"
    },
    overrides,
    beforeRenderHook: (overrides2, context) => {
      if (overrides2.onBeforePostPageRendered) {
        return overrides2.onBeforePostPageRendered(slug, context);
      }
      return true;
    }
  });
  const { post } = blogHooks.useSuspensePost(slug ?? "");
  const { previousPost, nextPost, ref } = blogHooks.useNextPreviousPosts(
    post?.createdAt ?? /* @__PURE__ */ new Date(),
    {
      enabled: !!post
    }
  );
  const { recentPosts, ref: recentPostsRef } = blogHooks.useRecentPosts({
    limit: 5,
    excludeSlug: slug,
    enabled: !!post
  });
  if (!slug || !post) {
    return /* @__PURE__ */ jsxRuntime.jsx(pageWrapper.PageWrapper, { children: /* @__PURE__ */ jsxRuntime.jsx(emptyList.EmptyList, { message: localization.BLOG_PAGE_NOT_FOUND_DESCRIPTION }) });
  }
  return /* @__PURE__ */ jsxRuntime.jsx(pageWrapper.PageWrapper, { className: "gap-0 px-4 lg:px-2 py-0 pb-18", testId: "post-page", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start w-full", children: [
    /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-44 shrink-0 hidden xl:flex mr-auto" }),
    /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center flex-1 mx-auto w-full max-w-4xl min-w-0", children: [
      /* @__PURE__ */ jsxRuntime.jsx(onThisPage.OnThisPageSelect, { markdown: post.content }),
      /* @__PURE__ */ jsxRuntime.jsx(
        pageHeader.PageHeader,
        {
          title: post.title,
          description: post.excerpt,
          childrenTop: /* @__PURE__ */ jsxRuntime.jsx(PostHeaderTop, { post })
        }
      ),
      post.image && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2 my-6 aspect-video w-full relative", children: /* @__PURE__ */ jsxRuntime.jsx(
        Image,
        {
          src: post.image,
          alt: post.title,
          className: "object-cover transition-transform duration-200"
        }
      ) }),
      /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full px-3", children: /* @__PURE__ */ jsxRuntime.jsx(markdownContent.MarkdownContent, { markdown: post.content }) }),
      /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4 w-full", children: [
        /* @__PURE__ */ jsxRuntime.jsx(
          postNavigation.PostNavigation,
          {
            previousPost,
            nextPost,
            ref
          }
        ),
        /* @__PURE__ */ jsxRuntime.jsx(recentPostsCarousel.RecentPostsCarousel, { posts: recentPosts, ref: recentPostsRef })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntime.jsx(onThisPage.OnThisPage, { markdown: post.content })
  ] }) });
}
function PostHeaderTop({ post }) {
  const { Link } = context.usePluginOverrides("blog", {
    Link: defaults.DefaultLink
  });
  const basePath = context.useBasePath();
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row items-center justify-center gap-2 flex-wrap mt-8", children: [
    /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-light text-muted-foreground text-sm", children: dateFns.formatDate(post.createdAt, "MMMM d, yyyy") }),
    post.tags && post.tags.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: post.tags.map((tag) => /* @__PURE__ */ jsxRuntime.jsx(Link, { href: `${basePath}/blog/tag/${tag.slug}`, children: /* @__PURE__ */ jsxRuntime.jsx(badge.Badge, { variant: "secondary", className: "text-xs", children: tag.name }) }, tag.id)) })
  ] });
}

exports.PostPage = PostPage;
