// packages/block-editor/src/hooks/content-lock-ui.js
import { ToolbarButton } from "@wordpress/components";
import { useDispatch, useSelect } from "@wordpress/data";
import { __ } from "@wordpress/i18n";
import { useCallback } from "@wordpress/element";
import { store as blockEditorStore } from "../store";
import { BlockControls } from "../components";
import { unlock } from "../lock-unlock";
import { jsx } from "react/jsx-runtime";
function ContentLockControlsPure({ clientId }) {
  const { templateLock, isLockedByParent, isEditingContentOnlySection } = useSelect(
    (select) => {
      const {
        getContentLockingParent,
        getTemplateLock,
        getEditedContentOnlySection
      } = unlock(select(blockEditorStore));
      return {
        templateLock: getTemplateLock(clientId),
        isLockedByParent: !!getContentLockingParent(clientId),
        isEditingContentOnlySection: getEditedContentOnlySection() === clientId
      };
    },
    [clientId]
  );
  const { stopEditingContentOnlySection } = unlock(
    useDispatch(blockEditorStore)
  );
  const isContentLocked = !isLockedByParent && templateLock === "contentOnly";
  const stopEditingAsBlockCallback = useCallback(() => {
    stopEditingContentOnlySection();
  }, [stopEditingContentOnlySection]);
  if (window?.__experimentalContentOnlyPatternInsertion || !isContentLocked && !isEditingContentOnlySection) {
    return null;
  }
  return isEditingContentOnlySection && /* @__PURE__ */ jsx(BlockControls, { group: "other", children: /* @__PURE__ */ jsx(ToolbarButton, { onClick: stopEditingAsBlockCallback, children: __("Done") }) });
}
var content_lock_ui_default = {
  edit: ContentLockControlsPure,
  hasSupport() {
    return true;
  }
};
export {
  content_lock_ui_default as default
};
//# sourceMappingURL=content-lock-ui.js.map
