'use strict';

const jsxRuntime = require('react/jsx-runtime');
const context = require('@btst/stack/context');
const button = require('../../../../../../../ui/src/components/button.cjs');
const emptyList = require('./empty-list.cjs');
const searchInput = require('./search-input.cjs');
const postCard = require('./post-card.cjs');
const index = require('../../localization/index.cjs');

function PostsList({
  posts,
  onLoadMore,
  hasMore,
  isLoadingMore
}) {
  const { localization } = context.usePluginOverrides("blog", {
    localization: index.BLOG_LOCALIZATION
  });
  const { PostCard } = context.usePluginOverrides("blog");
  const PostCardComponent = PostCard || postCard.PostCard;
  if (posts.length === 0) {
    return /* @__PURE__ */ jsxRuntime.jsx(emptyList.EmptyList, { message: localization.BLOG_LIST_EMPTY });
  }
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full space-y-6", children: [
    /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center pb-6", children: /* @__PURE__ */ jsxRuntime.jsx(
      searchInput.SearchInput,
      {
        placeholder: localization.BLOG_LIST_SEARCH_PLACEHOLDER,
        buttonText: localization.BLOG_LIST_SEARCH_BUTTON,
        emptyMessage: localization.BLOG_LIST_SEARCH_EMPTY
      }
    ) }),
    /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3", children: posts.map((post) => /* @__PURE__ */ jsxRuntime.jsx(PostCardComponent, { post }, post.id)) }),
    onLoadMore && hasMore && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
      button.Button,
      {
        onClick: onLoadMore,
        disabled: isLoadingMore,
        variant: "outline",
        size: "lg",
        children: isLoadingMore ? localization.BLOG_LIST_LOADING_MORE : localization.BLOG_LIST_LOAD_MORE
      }
    ) })
  ] });
}

exports.PostsList = PostsList;
