"use client";
'use strict';

const jsxRuntime = require('react/jsx-runtime');
const pageHeader = require('../shared/page-header.cjs');
const pageWrapper = require('../shared/page-wrapper.cjs');
const postsList = require('../shared/posts-list.cjs');
const emptyList = require('../shared/empty-list.cjs');
const blogHooks = require('../../hooks/blog-hooks.cjs');
const index = require('../../localization/index.cjs');
const context = require('@btst/stack/context');
const useRouteLifecycle = require('../../../../../../../ui/src/hooks/use-route-lifecycle.cjs');

function TagPage({ tagSlug }) {
  const overrides = context.usePluginOverrides("blog", {
    localization: index.BLOG_LOCALIZATION
  });
  const { localization } = overrides;
  useRouteLifecycle.useRouteLifecycle({
    routeName: "tag",
    context: {
      path: `/blog/tag/${tagSlug}`,
      params: { tagSlug },
      isSSR: typeof window === "undefined"
    },
    overrides
  });
  const { tags } = blogHooks.useTags();
  const tag = tags?.find((t) => t.slug === tagSlug);
  if (!tag) {
    return /* @__PURE__ */ jsxRuntime.jsxs(pageWrapper.PageWrapper, { testId: "tag-page", children: [
      /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(pageHeader.PageHeader, { title: localization.BLOG_TAG_NOT_FOUND }) }),
      /* @__PURE__ */ jsxRuntime.jsx(emptyList.EmptyList, { message: localization.BLOG_TAG_NOT_FOUND_DESCRIPTION })
    ] });
  }
  return /* @__PURE__ */ jsxRuntime.jsxs(pageWrapper.PageWrapper, { testId: "tag-page", children: [
    /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
      pageHeader.PageHeader,
      {
        title: `${localization.BLOG_TAG_PAGE_TITLE.replace("{tag}", tag.name)}`,
        description: localization.BLOG_TAG_PAGE_DESCRIPTION
      }
    ) }),
    /* @__PURE__ */ jsxRuntime.jsx(Content, { tagSlug })
  ] });
}
function Content({ tagSlug }) {
  const { posts, loadMore, hasMore, isLoadingMore } = blogHooks.useSuspensePosts({
    published: true,
    tagSlug
  });
  return /* @__PURE__ */ jsxRuntime.jsx(
    postsList.PostsList,
    {
      posts,
      onLoadMore: loadMore,
      hasMore,
      isLoadingMore
    }
  );
}

exports.TagPage = TagPage;
