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

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _i18n = require("@wordpress/i18n");
var _components = require("@wordpress/components");
var _blockEditor = require("@wordpress/block-editor");
var _editor = require("@wordpress/editor");
var _element = require("@wordpress/element");
var _context = _interopRequireWildcard(require("./font-library-modal/context"));
var _fontLibraryModal = _interopRequireDefault(require("./font-library-modal"));
var _fontFamilyItem = _interopRequireDefault(require("./font-family-item"));
var _subtitle = _interopRequireDefault(require("./subtitle"));
var _utils = require("./utils");
var _lockUnlock = require("../../lock-unlock");
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

const {
  GlobalStylesContext
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
const {
  mergeBaseAndUserConfigs
} = (0, _lockUnlock.unlock)(_editor.privateApis);
function Typesets() {
  const {
    modalTabOpen,
    setModalTabOpen
  } = (0, _element.useContext)(_context.FontLibraryContext);
  const {
    base
  } = (0, _element.useContext)(GlobalStylesContext);
  const {
    user: userConfig
  } = (0, _element.useContext)(GlobalStylesContext);
  const config = mergeBaseAndUserConfigs(base, userConfig);
  const allFontFamilies = (0, _utils.getFontFamilies)(config);
  const hasFonts = allFontFamilies.filter(font => font !== null).length > 0;
  return hasFonts && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [!!modalTabOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontLibraryModal.default, {
      onRequestClose: () => setModalTabOpen(null),
      defaultTabId: modalTabOpen
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
      spacing: 2,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalHStack, {
        justify: "space-between",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_subtitle.default, {
          level: 3,
          children: (0, _i18n.__)('Fonts')
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalItemGroup, {
        isBordered: true,
        isSeparated: true,
        children: allFontFamilies.map(font => font && /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontFamilyItem.default, {
          font: font
        }, font.slug))
      })]
    })]
  });
}
var _default = ({
  ...props
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_context.default, {
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Typesets, {
    ...props
  })
});
exports.default = _default;
//# sourceMappingURL=typeset.js.map