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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.VariationsPanel = VariationsPanel;
exports.useBlockVariations = useBlockVariations;
var _blocks = require("@wordpress/blocks");
var _blockEditor = require("@wordpress/block-editor");
var _data = require("@wordpress/data");
var _components = require("@wordpress/components");
var _navigationButton = require("../navigation-button");
var _lockUnlock = require("../../../lock-unlock");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

const {
  useGlobalStyle
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);

// Only core block styles (source === block) or block styles with a matching
// theme.json style variation will be configurable via Global Styles.
function getFilteredBlockStyles(blockStyles, variations) {
  return blockStyles?.filter(style => style.source === 'block' || variations.includes(style.name));
}
function useBlockVariations(name) {
  const blockStyles = (0, _data.useSelect)(select => {
    const {
      getBlockStyles
    } = select(_blocks.store);
    return getBlockStyles(name);
  }, [name]);
  const [variations] = useGlobalStyle('variations', name);
  const variationNames = Object.keys(variations !== null && variations !== void 0 ? variations : {});
  return getFilteredBlockStyles(blockStyles, variationNames);
}
function VariationsPanel({
  name
}) {
  const coreBlockStyles = useBlockVariations(name);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalItemGroup, {
    isBordered: true,
    isSeparated: true,
    children: coreBlockStyles.map((style, index) => {
      if (style?.isDefault) {
        return null;
      }
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_navigationButton.NavigationButtonAsItem, {
        path: '/blocks/' + encodeURIComponent(name) + '/variations/' + encodeURIComponent(style.name),
        children: style.label
      }, index);
    })
  });
}
//# sourceMappingURL=variations-panel.js.map