// packages/block-library/src/gallery/use-get-new-images.js
import { useMemo, useState } from "@wordpress/element";
function useGetNewImages(images, imageData) {
  const [currentImages, setCurrentImages] = useState([]);
  return useMemo(() => getNewImages(), [images, imageData]);
  function getNewImages() {
    let imagesUpdated = false;
    const newCurrentImages = currentImages.filter(
      (currentImg) => images.find((img) => {
        return currentImg.clientId === img.clientId;
      })
    );
    if (newCurrentImages.length < currentImages.length) {
      imagesUpdated = true;
    }
    images.forEach((image) => {
      if (image.fromSavedContent && !newCurrentImages.find(
        (currentImage) => currentImage.id === image.id
      )) {
        imagesUpdated = true;
        newCurrentImages.push(image);
      }
    });
    const newImages = images.filter(
      (image) => !newCurrentImages.find(
        (currentImage) => image.clientId && currentImage.clientId === image.clientId
      ) && imageData?.find((img) => img.id === image.id) && !image.fromSavedContent
    );
    if (imagesUpdated || newImages?.length > 0) {
      setCurrentImages([...newCurrentImages, ...newImages]);
    }
    return newImages.length > 0 ? newImages : null;
  }
}
export {
  useGetNewImages as default
};
//# sourceMappingURL=use-get-new-images.js.map
