export const getFileUrlByDimensions = (files, width = Infinity, height = Infinity) => {
  if (!files?.length) {
    return '';
  }

  const sortedBySize = files.slice().sort((a, b) => a.height - b.height);

  let matchedFile = sortedBySize[sortedBySize.length - 1];

  if (width !== Infinity && height !== Infinity) {
    const file = sortedBySize.find((item) => item.height >= height && item.width >= width);

    if (file) {
      matchedFile = file;
    }
  }

  return matchedFile.file;
};

export default {};
