"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 { TagsList } from '../shared/tags-list.mjs';
import { 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 HomePage({ published }) {
  const overrides = usePluginOverrides("blog", {
    localization: BLOG_LOCALIZATION
  });
  const { localization } = overrides;
  useRouteLifecycle({
    routeName: published ? "posts" : "drafts",
    context: {
      path: published ? "/blog" : "/blog/drafts",
      isSSR: typeof window === "undefined",
      published
    },
    overrides,
    beforeRenderHook: (overrides2, context) => {
      if (published && overrides2.onBeforePostsPageRendered) {
        return overrides2.onBeforePostsPageRendered(context);
      }
      if (!published && overrides2.onBeforeDraftsPageRendered) {
        return overrides2.onBeforeDraftsPageRendered(context);
      }
      return true;
    }
  });
  return /* @__PURE__ */ jsxs(PageWrapper, { testId: published ? "home-page" : "drafts-home-page", children: [
    /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center gap-3", children: /* @__PURE__ */ jsx(
      PageHeader,
      {
        title: published ? localization.BLOG_LIST_TITLE : localization.BLOG_LIST_DRAFTS_TITLE,
        childrenBottom: /* @__PURE__ */ jsx(TagsList, {})
      }
    ) }),
    /* @__PURE__ */ jsx(Content, { published })
  ] });
}
function Content({ published }) {
  const { posts, loadMore, hasMore, isLoadingMore } = useSuspensePosts({
    published
  });
  return /* @__PURE__ */ jsx(
    PostsList,
    {
      posts,
      onLoadMore: loadMore,
      hasMore,
      isLoadingMore
    }
  );
}

export { HomePage };
