/* wp:polyfill */
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = MostUsedTerms;
var _components = require("@wordpress/components");
var _data = require("@wordpress/data");
var _coreData = require("@wordpress/core-data");
var _terms2 = require("../../utils/terms");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

const MIN_MOST_USED_TERMS = 3;
const DEFAULT_QUERY = {
  per_page: 10,
  orderby: 'count',
  order: 'desc',
  hide_empty: true,
  _fields: 'id,name,count',
  context: 'view'
};
function MostUsedTerms({
  onSelect,
  taxonomy
}) {
  const {
    _terms,
    showTerms
  } = (0, _data.useSelect)(select => {
    const mostUsedTerms = select(_coreData.store).getEntityRecords('taxonomy', taxonomy.slug, DEFAULT_QUERY);
    return {
      _terms: mostUsedTerms,
      showTerms: mostUsedTerms?.length >= MIN_MOST_USED_TERMS
    };
  }, [taxonomy.slug]);
  if (!showTerms) {
    return null;
  }
  const terms = (0, _terms2.unescapeTerms)(_terms);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: "editor-post-taxonomies__flat-term-most-used",
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.BaseControl.VisualLabel, {
      as: "h3",
      className: "editor-post-taxonomies__flat-term-most-used-label",
      children: taxonomy.labels.most_used
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
      role: "list",
      className: "editor-post-taxonomies__flat-term-most-used-list",
      children: terms.map(term => /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
          __next40pxDefaultSize: true,
          variant: "link",
          onClick: () => onSelect(term),
          children: term.name
        })
      }, term.id))
    })]
  });
}
//# sourceMappingURL=most-used-terms.js.map