// packages/block-editor/src/components/default-block-appender/index.js
import clsx from "clsx";
import { __ } from "@wordpress/i18n";
import { decodeEntities } from "@wordpress/html-entities";
import { useSelect, useDispatch } from "@wordpress/data";
import { ENTER, SPACE } from "@wordpress/keycodes";
import Inserter from "../inserter";
import { store as blockEditorStore } from "../../store";
import { jsx, jsxs } from "react/jsx-runtime";
var ZWNBSP = "\uFEFF";
function DefaultBlockAppender({ rootClientId }) {
  const { showPrompt, isLocked, placeholder, isManualGrid } = useSelect(
    (select) => {
      const {
        getBlockCount,
        getSettings,
        getTemplateLock,
        getBlockAttributes
      } = select(blockEditorStore);
      const isEmpty = !getBlockCount(rootClientId);
      const { bodyPlaceholder } = getSettings();
      return {
        showPrompt: isEmpty,
        isLocked: !!getTemplateLock(rootClientId),
        placeholder: bodyPlaceholder,
        isManualGrid: getBlockAttributes(rootClientId)?.layout?.isManualPlacement
      };
    },
    [rootClientId]
  );
  const { insertDefaultBlock, startTyping } = useDispatch(blockEditorStore);
  if (isLocked || isManualGrid) {
    return null;
  }
  const value = decodeEntities(placeholder) || __("Type / to choose a block");
  const onAppend = () => {
    insertDefaultBlock(void 0, rootClientId);
    startTyping();
  };
  return /* @__PURE__ */ jsxs(
    "div",
    {
      "data-root-client-id": rootClientId || "",
      className: clsx("block-editor-default-block-appender", {
        "has-visible-prompt": showPrompt
      }),
      children: [
        /* @__PURE__ */ jsx(
          "p",
          {
            tabIndex: "0",
            role: "button",
            "aria-label": __("Add default block"),
            className: "block-editor-default-block-appender__content",
            onKeyDown: (event) => {
              if (ENTER === event.keyCode || SPACE === event.keyCode) {
                onAppend();
              }
            },
            onClick: () => onAppend(),
            onFocus: () => {
              if (showPrompt) {
                onAppend();
              }
            },
            children: showPrompt ? value : ZWNBSP
          }
        ),
        /* @__PURE__ */ jsx(
          Inserter,
          {
            rootClientId,
            position: "bottom right",
            isAppender: true,
            __experimentalIsQuick: true
          }
        )
      ]
    }
  );
}
export {
  ZWNBSP,
  DefaultBlockAppender as default
};
//# sourceMappingURL=index.js.map
