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

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PostTaxonomies = PostTaxonomies;
exports.default = void 0;
var _element = require("@wordpress/element");
var _data = require("@wordpress/data");
var _coreData = require("@wordpress/core-data");
var _hierarchicalTermSelector = _interopRequireDefault(require("./hierarchical-term-selector"));
var _flatTermSelector = _interopRequireDefault(require("./flat-term-selector"));
var _store = require("../../store");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

const identity = x => x;
function PostTaxonomies({
  taxonomyWrapper = identity
}) {
  const {
    postType,
    taxonomies
  } = (0, _data.useSelect)(select => {
    return {
      postType: select(_store.store).getCurrentPostType(),
      taxonomies: select(_coreData.store).getTaxonomies({
        per_page: -1
      })
    };
  }, []);
  const visibleTaxonomies = (taxonomies !== null && taxonomies !== void 0 ? taxonomies : []).filter(taxonomy =>
  // In some circumstances .visibility can end up as undefined so optional chaining operator required.
  // https://github.com/WordPress/gutenberg/issues/40326
  taxonomy.types.includes(postType) && taxonomy.visibility?.show_ui);
  return visibleTaxonomies.map(taxonomy => {
    const TaxonomyComponent = taxonomy.hierarchical ? _hierarchicalTermSelector.default : _flatTermSelector.default;
    const taxonomyComponentProps = {
      slug: taxonomy.slug,
      ...(taxonomy.hierarchical ? {} : {
        __nextHasNoMarginBottom: true
      })
    };
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_element.Fragment, {
      children: taxonomyWrapper(/*#__PURE__*/(0, _jsxRuntime.jsx)(TaxonomyComponent, {
        ...taxonomyComponentProps
      }), taxonomy)
    }, `taxonomy-${taxonomy.slug}`);
  });
}

/**
 * Renders the taxonomies associated with a post.
 *
 * @param {Object}   props                 The component props.
 * @param {Function} props.taxonomyWrapper The wrapper function for each taxonomy component.
 *
 * @return {Array} An array of JSX elements representing the visible taxonomies.
 */
var _default = exports.default = PostTaxonomies;
//# sourceMappingURL=index.js.map