import { RefreshableView } from '../common/refreshableview' ; import { TreeButton } from './treebutton' ; import { TreeModel } from './treemodel' ; import { TreeNavigator } from './treenavigator' ; export class TreeButtons implements RefreshableView { private buttonsEl_ : HTMLElement ; private treeModel_ : TreeModel ; private buttons_ : TreeButton [ ] ; constructor ( buttonsEl , treeModel ) { this . buttonsEl_ = buttonsEl ; this . treeModel_ = treeModel ; this . buttons_ = [ ] ; } refresh ( ) { let isModelEmpty = this . treeModel_ . isEmpty ( ) ; this . buttonsEl_ . classList . toggle ( 'hidden' , isModelEmpty ) ; this . buttons_ . forEach ( b => { const enabled = b . isEnabled ( ) ; b . buttonEl . classList . toggle ( 'disabled' , ! enabled ) ; b . buttonEl . classList . toggle ( 'selectable' , enabled ) ; } ) ; } addButton ( treeButton ) { treeButton . buttonEl . onclick = ( ) => treeButton . handleClick ( ) ; this . buttons_ . push ( treeButton ) ; return this ; } addNavigationButtons ( leftButtonEl , rightButtonEl , treeNavigator ) { return this . addButton ( { buttonEl : leftButtonEl , handleClick : ( ) => treeNavigator . selectLeft ( ) , isEnabled : ( ) => this . treeModel_ . hasPreviousPgn ( ) } ) . addButton ( { buttonEl : rightButtonEl , handleClick : ( ) => treeNavigator . selectRight ( ) , isEnabled : ( ) => this . treeModel_ . hasNextPgn ( ) } ) ; } }