"use client";
import { jsxs, jsx } from 'react/jsx-runtime';
import { PageHeader } from '../shared/page-header.mjs';
import { PageWrapper } from '../shared/page-wrapper.mjs';
import { PostsList } from '../shared/posts-list.mjs';
import { EmptyList } from '../shared/empty-list.mjs';
import { useTags, useSuspensePosts } from '../../hooks/blog-hooks.mjs';
import { BLOG_LOCALIZATION } from '../../localization/index.mjs';
import { usePluginOverrides } from '@btst/stack/context';
import { useRouteLifecycle } from '../../../../../../../ui/src/hooks/use-route-lifecycle.mjs';

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

export { TagPage };
