import sortBy from 'lodash/sortBy'
import { ReferenceLanguages } from 'requests/getLanguages'

export const getSortedLangs = (langs: ReferenceLanguages): ReferenceLanguages => {
  const languagesSorted = sortBy(langs, ['name_en'])
  const engLocaleIndex = languagesSorted.findIndex((language) => language.iso_639_1 === 'en')
  const engLanguage = languagesSorted[engLocaleIndex]
  languagesSorted.splice(engLocaleIndex, 1)
  languagesSorted.unshift(engLanguage)
  return languagesSorted
}
