// packages/block-editor/src/components/block-list-appender/index.js
import clsx from "clsx";
import { useSelect } from "@wordpress/data";
import { getDefaultBlockName } from "@wordpress/blocks";
import DefaultBlockAppender from "../default-block-appender";
import ButtonBlockAppender from "../button-block-appender";
import { store as blockEditorStore } from "../../store";
import { jsx } from "react/jsx-runtime";
function DefaultAppender({ rootClientId }) {
  const canInsertDefaultBlock = useSelect(
    (select) => select(blockEditorStore).canInsertBlockType(
      getDefaultBlockName(),
      rootClientId
    )
  );
  if (canInsertDefaultBlock) {
    return /* @__PURE__ */ jsx(DefaultBlockAppender, { rootClientId });
  }
  return /* @__PURE__ */ jsx(
    ButtonBlockAppender,
    {
      rootClientId,
      className: "block-list-appender__toggle"
    }
  );
}
function BlockListAppender({
  rootClientId,
  CustomAppender,
  className,
  tagName: TagName = "div"
}) {
  const isDragOver = useSelect(
    (select) => {
      const {
        getBlockInsertionPoint,
        isBlockInsertionPointVisible,
        getBlockCount
      } = select(blockEditorStore);
      const insertionPoint = getBlockInsertionPoint();
      return isBlockInsertionPointVisible() && rootClientId === insertionPoint?.rootClientId && getBlockCount(rootClientId) === 0;
    },
    [rootClientId]
  );
  return /* @__PURE__ */ jsx(
    TagName,
    {
      tabIndex: -1,
      className: clsx("block-list-appender wp-block", className, {
        "is-drag-over": isDragOver
      }),
      contentEditable: false,
      "data-block": true,
      children: CustomAppender ? /* @__PURE__ */ jsx(CustomAppender, {}) : /* @__PURE__ */ jsx(DefaultAppender, { rootClientId })
    }
  );
}
export {
  BlockListAppender as default
};
//# sourceMappingURL=index.js.map
