// packages/block-editor/src/components/inserter/media-tab/media-panel.js
import { Spinner, SearchControl } from "@wordpress/components";
import { __ } from "@wordpress/i18n";
import { useDebouncedInput } from "@wordpress/compose";
import MediaList from "./media-list";
import { useMediaResults } from "./hooks";
import InserterNoResults from "../no-results";
import { jsx, jsxs } from "react/jsx-runtime";
var INITIAL_MEDIA_ITEMS_PER_PAGE = 10;
function MediaCategoryPanel({ rootClientId, onInsert, category }) {
  const [search, setSearch, debouncedSearch] = useDebouncedInput();
  const { mediaList, isLoading } = useMediaResults(category, {
    per_page: !!debouncedSearch ? 20 : INITIAL_MEDIA_ITEMS_PER_PAGE,
    search: debouncedSearch
  });
  const baseCssClass = "block-editor-inserter__media-panel";
  const searchLabel = category.labels.search_items || __("Search");
  return /* @__PURE__ */ jsxs("div", { className: baseCssClass, children: [
    /* @__PURE__ */ jsx(
      SearchControl,
      {
        __nextHasNoMarginBottom: true,
        className: `${baseCssClass}-search`,
        onChange: setSearch,
        value: search,
        label: searchLabel,
        placeholder: searchLabel
      }
    ),
    isLoading && /* @__PURE__ */ jsx("div", { className: `${baseCssClass}-spinner`, children: /* @__PURE__ */ jsx(Spinner, {}) }),
    !isLoading && !mediaList?.length && /* @__PURE__ */ jsx(InserterNoResults, {}),
    !isLoading && !!mediaList?.length && /* @__PURE__ */ jsx(
      MediaList,
      {
        rootClientId,
        onClick: onInsert,
        mediaList,
        category
      }
    )
  ] });
}
export {
  MediaCategoryPanel
};
//# sourceMappingURL=media-panel.js.map
