import { ScreenState } from '@ulangi/ulangi-common/enums' ; import { ObservableCategorySelectorScreen , Observer , } from '@ulangi/ulangi-observable' ; import { boundClass } from 'autobind-decorator' ; import { NavigatorDelegate } from '../navigator/NavigatorDelegate' ; import { CategoryFormDelegate } from './CategoryFormDelegate' ; @ boundClass export class CategorySelectorScreenDelegate { private observer : Observer ; private observableScreen : ObservableCategorySelectorScreen ; private categoryFormDelegate : CategoryFormDelegate ; private navigatorDelegate : NavigatorDelegate ; private onSelect : ( categoryName : string ) => void ; public constructor ( observer , observableScreen , categoryFormDelegate , navigatorDelegate , onSelect ) { this . observer = observer ; this . observableScreen = observableScreen ; this . categoryFormDelegate = categoryFormDelegate ; this . navigatorDelegate = navigatorDelegate ; this . onSelect = onSelect ; } public handleInputChange ( searchInput ) { this . observableScreen . categoryFormState . searchInput = searchInput ; } public selectCategory ( categoryName ) { this . navigatorDelegate . dismissScreen ( ) ; this . observer . when ( ( ) : boolean => this . observableScreen . screenState === ScreenState . UNMOUNTED , ( ) : void => { this . onSelect ( categoryName ) ; } ) ; } public prepareAndFetchCategorySuggestions ( ) { this . categoryFormDelegate . prepareAndFetchSuggestions ( this . observableScreen . categoryFormState . searchInput ) ; } public fetchCategorySuggestions ( ) { this . categoryFormDelegate . fetchSuggestions ( ) ; } public clearFetchCategorySuggestions ( ) { this . categoryFormDelegate . clearFetchSuggestions ( ) ; } public clear ( ) { this . categoryFormDelegate . clear ( ) ; } public autoRefreshCategorySuggestionsOnInputChange ( debounceTime ) { this . categoryFormDelegate . autoRefreshCategorySuggestionsOnInputChange ( debounceTime ) ; } }