export interface INavbarProperty { property : string ; data : any [ ] ; updateTemplate : boolean ; updateSelected : boolean ; } export class NavbarProperty { data : any [ ] ; currentValue : any ; private readonly property : string ; constructor ( navbarProperty ) { this . data = navbarProperty . data ; this . currentValue = this . data [ 0 ] ; this . property = navbarProperty . property ; this . init ( ) ; } setValue ( i ) { this . currentValue = this . data [ i ] ; localStorage . setItem ( this . property , `${ i }` ) ; if ( this . updateTemplate ) { this . updateTemplate ( ) ; } if ( this . updateSelected ) { this . updateSelected ( i ) ; } } init ( ) { const currentValue = parseInt ( localStorage . getItem ( this . property ) as string ) ; if ( currentValue ) { this . setValue ( currentValue ) ; } else { localStorage . setItem ( this . property , '0' ) ; } } private updateTemplate ( ) { if ( this . currentValue ) { for ( const color of this . data ) { document . body . classList . remove ( color . className ) ; } document . body . classList . add ( this . currentValue . className ) ; } } private updateSelected ( i ) { if ( this . data [ i ] ) { this . data . forEach ( ( color ) => { color . selected = false ; } ) ; this . data [ i ] . selected = true ; } } }