// packages/editor/src/components/provider/use-upload-save-lock.js
import { useSelect, useDispatch } from "@wordpress/data";
import { useEffect } from "@wordpress/element";
import { store as uploadStore } from "@wordpress/upload-media";
import { store as editorStore } from "../../store/index.mjs";
var LOCK_NAME = "upload-in-progress";
function useUploadSaveLock() {
  const isUploading = useSelect(
    (select) => select(uploadStore).isUploading(),
    []
  );
  const {
    lockPostSaving,
    unlockPostSaving,
    lockPostAutosaving,
    unlockPostAutosaving
  } = useDispatch(editorStore);
  useEffect(() => {
    if (isUploading) {
      lockPostSaving(LOCK_NAME);
      lockPostAutosaving(LOCK_NAME);
    } else {
      unlockPostSaving(LOCK_NAME);
      unlockPostAutosaving(LOCK_NAME);
    }
    return () => {
      unlockPostSaving(LOCK_NAME);
      unlockPostAutosaving(LOCK_NAME);
    };
  }, [
    isUploading,
    lockPostSaving,
    unlockPostSaving,
    lockPostAutosaving,
    unlockPostAutosaving
  ]);
}
export {
  useUploadSaveLock as default
};
//# sourceMappingURL=use-upload-save-lock.mjs.map
