import { CloudLocation , CloudLocationOption , GeoLocation } from '../model/location' ; /**
 * Returns the localized place name, or the data center ID if the location is
 * unknown.
 */ export function getShortName ( cloudLocation , localize ) { if ( ! cloudLocation ) { return '' ; } if ( ! cloudLocation . location ) { return cloudLocation . id ; } return localize ( `geo-${ cloudLocation . location . id . toLowerCase ( ) }` ) ; } /**
 * Returns the localized country name, or "" if the country is unknown or
 * unnecessary.
 */ export function localizeCountry ( geoLocation , language ) { if ( ! geoLocation ) { return '' ; } const displayName = new ( Intl as any ) . DisplayNames ( [ language ] , { type : 'region' } ) ; return displayName . of ( geoLocation . countryCode ) ; } /**
 * Given an array of cloud location options, this function returns an array
 * containing one representative option for each GeoLocation.  Available
 * options are preferred within each location.  Available options with unknown
 * GeoLocation (e.g. newly added zones) are placed at the end of the array.
 */ export function filterOptions < T extends CloudLocationOption > ( options ) { const map = new Map < string , T > ( ) ; const unmappedOptions = [ ] ; options . forEach ( option => { const geoLocation = option . cloudLocation . location ; if ( geoLocation ) { if ( option . available || ! map . has ( geoLocation . id ) ) { map . set ( geoLocation . id , option ) ; } } else if ( option . available ) { unmappedOptions . push ( option ) ; } } ) ; return [ ... map . values ( ) , ... unmappedOptions ] ; }