"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 tagsList = require('../shared/tags-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 HomePage({ published }) {
  const overrides = context.usePluginOverrides("blog", {
    localization: index.BLOG_LOCALIZATION
  });
  const { localization } = overrides;
  useRouteLifecycle.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__ */ jsxRuntime.jsxs(pageWrapper.PageWrapper, { testId: published ? "home-page" : "drafts-home-page", children: [
    /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
      pageHeader.PageHeader,
      {
        title: published ? localization.BLOG_LIST_TITLE : localization.BLOG_LIST_DRAFTS_TITLE,
        childrenBottom: /* @__PURE__ */ jsxRuntime.jsx(tagsList.TagsList, {})
      }
    ) }),
    /* @__PURE__ */ jsxRuntime.jsx(Content, { published })
  ] });
}
function Content({ published }) {
  const { posts, loadMore, hasMore, isLoadingMore } = blogHooks.useSuspensePosts({
    published
  });
  return /* @__PURE__ */ jsxRuntime.jsx(
    postsList.PostsList,
    {
      posts,
      onLoadMore: loadMore,
      hasMore,
      isLoadingMore
    }
  );
}

exports.HomePage = HomePage;
