import { orderBy , reject } from 'lodash' ; import { TOPICS } from 'src/components/config' ; export const QUERY_SEPARATOR = '+' ; export function transformTopicRefinements ( items ) { items . map ( ( item ) => { item . label = TOPICS [ item . label ] || item . label ; return item ; } ) ; return orderBy ( reject ( items , ( item ) => item . label === '' ) , [ 'count' , 'name' ] , [ 'desc' , 'desc' ] ) ; } interface Item { attribute : string ; items : { [ key ] : string ; } [ ] ; } export function transformCountryRefinements ( items ) { return orderBy ( items , [ 'count' , 'name' ] , [ 'desc' , 'desc' ] ) ; } export function transformCurrentRefinements ( items ) { if ( ! items . length ) { return [ ] ; } const topics = items . find ( ( item ) => item . attribute === 'topics' ) ; if ( topics ) { topics . items . map ( ( item ) => { item . label = TOPICS [ item . label ] || item . label ; return item ; } ) ; } return ( items || [ ] ) . filter ( ( item ) => item . attribute !== 'online' && item . attribute !== 'offersSignLanguageOrCC' ) ; } export function getFirstTopic ( topics ) { if ( topics . length > 1 && topics [ 0 ] === 'general' ) { return topics [ 1 ] ; } return topics [ 0 ] ; } export function paramsFromUrl ( urlQueryString , paramKey ) { if ( ! urlQueryString [ paramKey ] ) { return null ; } return urlQueryString [ paramKey ] ?. split ( QUERY_SEPARATOR ) ; } export const dateToTime = ( date ) => Math . round ( date . getTime ( ) / 1000 ) ;