"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.BlockModeToggle = BlockModeToggle;
exports.default = void 0;
var _i18n = require("@wordpress/i18n");
var _components = require("@wordpress/components");
var _blocks = require("@wordpress/blocks");
var _data = require("@wordpress/data");
var _compose = require("@wordpress/compose");
var _store = require("../../store");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

const noop = () => {};
function BlockModeToggle({
  blockType,
  mode,
  onToggleMode,
  small = false,
  isCodeEditingEnabled = true
}) {
  if (!blockType || !(0, _blocks.hasBlockSupport)(blockType, 'html', true) || !isCodeEditingEnabled) {
    return null;
  }
  const label = mode === 'visual' ? (0, _i18n.__)('Edit as HTML') : (0, _i18n.__)('Edit visually');
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuItem, {
    onClick: onToggleMode,
    children: !small && label
  });
}
var _default = exports.default = (0, _compose.compose)([(0, _data.withSelect)((select, {
  clientId
}) => {
  const {
    getBlock,
    getBlockMode,
    getSettings
  } = select(_store.store);
  const block = getBlock(clientId);
  const isCodeEditingEnabled = getSettings().codeEditingEnabled;
  return {
    mode: getBlockMode(clientId),
    blockType: block ? (0, _blocks.getBlockType)(block.name) : null,
    isCodeEditingEnabled
  };
}), (0, _data.withDispatch)((dispatch, {
  onToggle = noop,
  clientId
}) => ({
  onToggleMode() {
    dispatch(_store.store).toggleBlockMode(clientId);
    onToggle();
  }
}))])(BlockModeToggle);
//# sourceMappingURL=block-mode-toggle.js.map