// packages/block-library/src/gallery/use-image-sizes.js
import { useMemo } from "@wordpress/element";
function useImageSizes(images, isSelected, getSettings) {
  return useMemo(() => getImageSizing(), [images, isSelected]);
  function getImageSizing() {
    if (!images || images.length === 0) {
      return;
    }
    const { imageSizes } = getSettings();
    let resizedImages = {};
    if (isSelected) {
      resizedImages = images.reduce((currentResizedImages, img) => {
        if (!img.id) {
          return currentResizedImages;
        }
        const sizes = imageSizes.reduce((currentSizes, size) => {
          const defaultUrl = img.sizes?.[size.slug]?.url;
          const mediaDetailsUrl = img.media_details?.sizes?.[size.slug]?.source_url;
          return {
            ...currentSizes,
            [size.slug]: defaultUrl || mediaDetailsUrl
          };
        }, {});
        return {
          ...currentResizedImages,
          [parseInt(img.id, 10)]: sizes
        };
      }, {});
    }
    const resizedImageSizes = Object.values(resizedImages);
    return imageSizes.filter(
      ({ slug }) => resizedImageSizes.some((sizes) => sizes[slug])
    ).map(({ name, slug }) => ({ value: slug, label: name }));
  }
}
export {
  useImageSizes as default
};
//# sourceMappingURL=use-image-sizes.js.map
