import * as apid from '../../../api' ; import { Genre , SubGenre } from '../lib/event' ; /**
 * Genre Util
 */ namespace GenreUtil { export const GENRE_MAX_NUM = 15 ; export interface GenreListItem { text : string ; value : apid . ProgramGenreLv1 ; } export interface SubGenreListItem { text : string ; value : apid . ProgramGenreLv2 ; } return export const getGenreListItems = ( ) : GenreListItem [ ] => { const items = [ ] ; for ( let i = 0 ; i <= GENRE_MAX_NUM ; i ++ ) { items . push ( { text : ( Genre as any ) [ i ] , value : i , } ) ; } return items ; } ; param lv1 return export const getSubGenreListItems = ( lv1 ) : SubGenreListItem [ ] => { const items = [ ] ; for ( let i = 0 ; i <= GENRE_MAX_NUM ; i ++ ) { const text = ( SubGenre as any ) [ lv1 ] [ i ] ; if ( text . length === 0 ) { continue ; } items . push ( { text : text , value : i , } ) ; } return items ; } ; return export const getGenre = ( lv1 ) : string | null => { if ( typeof ( Genre as any ) [ lv1 ] === 'undefined' ) { return null ; } return ( Genre as any ) [ lv1 ] ; } ; return export const getSubGenre = ( lv1 , lv2 ? ) : string | null => { if ( typeof ( Genre as any ) [ lv1 ] === 'undefined' || typeof lv2 === 'undefined' || typeof ( SubGenre as any ) [ lv1 ] [ lv2 ] === 'undefined' ) { return null ; } return ( SubGenre as any ) [ lv1 ] [ lv2 ] ; } ; param lv1 param lv2 return export const getGenres = ( lv1 , lv2 ? ) : string | null => { const genre = GenreUtil . getGenre ( lv1 ) ; const subGenre = GenreUtil . getSubGenre ( lv1 , lv2 ) ; return genre === null ? null : subGenre === null ? genre : `${ genre } / ${ subGenre }` ; } ; } export default GenreUtil ;