const SIZE_ORDER = {
  large: ['large', 'medium', 'small'],
  medium: ['medium', 'small', 'large'],
  small: ['small', 'medium', 'large'],
  thumbnail: ['thumbnail', 'small', 'medium', 'large'],
}

export const formatKuveti = (kuveti, preferred = 'large') => {
  if (!kuveti) {
    return null
  }

  const order = SIZE_ORDER[preferred] ?? SIZE_ORDER.large
  for (const size of order) {
    if (kuveti.formats?.[size]) {
      return kuveti.formats[size]
    }
  }

  return kuveti
}
