"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DefaultBlockAppender = DefaultBlockAppender;
exports.default = void 0;
var _reactNative = require("react-native");
var _i18n = require("@wordpress/i18n");
var _blockEditor = require("@wordpress/block-editor");
var _compose = require("@wordpress/compose");
var _htmlEntities = require("@wordpress/html-entities");
var _data = require("@wordpress/data");
var _blocks = require("@wordpress/blocks");
var _insertionPoint = _interopRequireDefault(require("../block-list/insertion-point"));
var _style = _interopRequireDefault(require("./style.scss"));
var _store = require("../../store");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * External dependencies
 */

/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

const hitSlop = {
  top: 22,
  bottom: 22,
  left: 22,
  right: 22
};
const noop = () => {};
function DefaultBlockAppender({
  baseGlobalStyles,
  isLocked,
  isVisible,
  onAppend,
  placeholder,
  containerStyle,
  showSeparator
}) {
  if (isLocked || !isVisible) {
    return null;
  }
  const blockGlobalStyles = baseGlobalStyles?.blocks?.['core/paragraph'];
  const {
    fontSize,
    lineHeight
  } = blockGlobalStyles?.typography || {};
  const textStyles = blockGlobalStyles?.typography ? {
    ...(fontSize && {
      fontSize
    }),
    ...(lineHeight && {
      lineHeight
    })
  } : undefined;
  const value = typeof placeholder === 'string' ? (0, _htmlEntities.decodeEntities)(placeholder) : (0, _i18n.__)('Start writing…');
  const appenderStyles = [_style.default.blockHolder, showSeparator && containerStyle];
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
    onPress: onAppend,
    hitSlop: hitSlop,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: appenderStyles,
      pointerEvents: "box-only",
      children: showSeparator ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_insertionPoint.default, {}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.RichText, {
        placeholder: value,
        onChange: noop,
        tagName: "p",
        style: textStyles
      })
    })
  });
}
var _default = exports.default = (0, _compose.compose)((0, _data.withSelect)((select, ownProps) => {
  const {
    getBlockCount,
    getBlockName,
    getSettings,
    isBlockValid,
    getTemplateLock
  } = select(_store.store);
  const isEmpty = !getBlockCount(ownProps.rootClientId);
  const isLastBlockDefault = getBlockName(ownProps.lastBlockClientId) === (0, _blocks.getDefaultBlockName)();
  const isLastBlockValid = isBlockValid(ownProps.lastBlockClientId);
  const globalStylesBaseStyles = getSettings()?.__experimentalGlobalStylesBaseStyles;
  return {
    baseGlobalStyles: globalStylesBaseStyles,
    isVisible: isEmpty || !isLastBlockDefault || !isLastBlockValid,
    isLocked: !!getTemplateLock(ownProps.rootClientId)
  };
}), (0, _data.withDispatch)((dispatch, ownProps) => {
  const {
    insertDefaultBlock,
    startTyping
  } = dispatch(_store.store);
  return {
    onAppend() {
      const {
        rootClientId
      } = ownProps;
      insertDefaultBlock(undefined, rootClientId);
      startTyping();
    }
  };
}))(DefaultBlockAppender);
//# sourceMappingURL=index.native.js.map