// packages/block-editor/src/components/block-card/index.js
import clsx from "clsx";
import {
  Button,
  Icon,
  __experimentalText as Text,
  __experimentalVStack as VStack,
  privateApis as componentsPrivateApis
} from "@wordpress/components";
import { useDispatch, useSelect } from "@wordpress/data";
import deprecated from "@wordpress/deprecated";
import { __, isRTL } from "@wordpress/i18n";
import {
  chevronLeft,
  chevronRight,
  arrowRight,
  arrowLeft
} from "@wordpress/icons";
import { unlock } from "../../lock-unlock";
import { store as blockEditorStore } from "../../store";
import BlockIcon from "../block-icon";
import { jsx, jsxs } from "react/jsx-runtime";
var { Badge } = unlock(componentsPrivateApis);
function OptionalParentSelectButton({ children, onClick }) {
  if (!onClick) {
    return children;
  }
  return /* @__PURE__ */ jsx(
    Button,
    {
      __next40pxDefaultSize: true,
      className: "block-editor-block-card__parent-select-button",
      onClick,
      children
    }
  );
}
function BlockCard({
  title,
  icon,
  description,
  blockType,
  className,
  name,
  allowParentNavigation,
  parentClientId,
  isChild,
  children,
  clientId
}) {
  if (blockType) {
    deprecated("`blockType` property in `BlockCard component`", {
      since: "5.7",
      alternative: "`title, icon and description` properties"
    });
    ({ title, icon, description } = blockType);
  }
  const parentNavBlockClientId = useSelect(
    (select) => {
      if (parentClientId || isChild || !allowParentNavigation) {
        return;
      }
      const { getBlockParentsByBlockName } = select(blockEditorStore);
      return getBlockParentsByBlockName(
        clientId,
        "core/navigation",
        true
      )[0];
    },
    [clientId, allowParentNavigation, isChild, parentClientId]
  );
  const { selectBlock } = useDispatch(blockEditorStore);
  const TitleElement = parentClientId ? "div" : "h2";
  return /* @__PURE__ */ jsxs(
    "div",
    {
      className: clsx(
        "block-editor-block-card",
        {
          "is-parent": parentClientId,
          "is-child": isChild
        },
        className
      ),
      children: [
        parentNavBlockClientId && // This is only used by the Navigation block for now. It's not ideal having Navigation block specific code here.
        /* @__PURE__ */ jsx(
          Button,
          {
            onClick: () => selectBlock(parentNavBlockClientId),
            label: parentNavBlockClientId ? __("Go to parent Navigation block") : (
              // TODO - improve copy, not sure that we should use the term 'section'
              __("Go to parent section")
            ),
            style: (
              // TODO: This style override is also used in ToolsPanelHeader.
              // It should be supported out-of-the-box by Button.
              { minWidth: 24, padding: 0 }
            ),
            icon: isRTL() ? chevronRight : chevronLeft,
            size: "small"
          }
        ),
        isChild && /* @__PURE__ */ jsx("span", { className: "block-editor-block-card__child-indicator-icon", children: /* @__PURE__ */ jsx(Icon, { icon: isRTL() ? arrowLeft : arrowRight }) }),
        /* @__PURE__ */ jsxs(
          OptionalParentSelectButton,
          {
            onClick: parentClientId ? () => {
              selectBlock(parentClientId);
            } : void 0,
            children: [
              /* @__PURE__ */ jsx(BlockIcon, { icon, showColors: true }),
              /* @__PURE__ */ jsxs(VStack, { spacing: 1, children: [
                /* @__PURE__ */ jsxs(TitleElement, { className: "block-editor-block-card__title", children: [
                  /* @__PURE__ */ jsx("span", { className: "block-editor-block-card__name", children: !!name?.length ? name : title }),
                  !parentClientId && !isChild && !!name?.length && /* @__PURE__ */ jsx(Badge, { children: title })
                ] }),
                !parentClientId && !isChild && description && /* @__PURE__ */ jsx(Text, { className: "block-editor-block-card__description", children: description }),
                children
              ] })
            ]
          }
        )
      ]
    }
  );
}
var block_card_default = BlockCard;
export {
  block_card_default as default
};
//# sourceMappingURL=index.js.map
