import { AfterContentInit , AfterViewInit , ChangeDetectionStrategy , ChangeDetectorRef , Component , EventEmitter , } from '@angular/core' ; import { IOption } from 'ng-select' ; import { Observable } from 'rxjs' ; import { FilterOption } from '../../../models/filter-option' ; import { AchievementsState } from '../../../models/mainwindow/achievements-state' ; import { GenericPreferencesUpdateEvent } from '../../../services/mainwindow/store/events/generic-preferences-update-event' ; import { MainWindowStoreEvent } from '../../../services/mainwindow/store/events/main-window-store-event' ; import { OverwolfService } from '../../../services/overwolf.service' ; import { AppUiStoreFacadeService } from '../../../services/ui-store/app-ui-store-facade.service' ; import { AbstractSubscriptionComponent } from '../../abstract-subscription.component' ; @ Component ( { selector : 'achievements-completed-filter-dropdown' , styleUrls : [ `../../../../css/global/filters.scss` , `../../../../css/component/app-section.component.scss` , `../../../../css/component/filter-dropdown.component.scss` , ] , template : `
		<filter-dropdown
			*ngIf="filter$ | async as value"
			class="achievements-completed-filter-dropdown"
			[options]="options"
			[filter]="value.filter"
			[placeholder]="value.placeholder"
			[visible]="value.visible"
			(onOptionSelected)="onSelected($event)"
		></filter-dropdown>
	` , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class AchievementsCompletedFilterDropdownComponent extends AbstractSubscriptionComponent implements AfterContentInit , AfterViewInit { filters : readonly FilterOption [ ] ; options : readonly IOption [ ] ; filter$ : Observable < { filter : string ; placeholder : string ; visible : boolean ; } > ; private stateUpdater : EventEmitter < MainWindowStoreEvent > ; constructor ( private readonly ow , protected readonly store , protected readonly cdr ) { super ( store , cdr ) ; } ngAfterContentInit ( ) { this . options = AchievementsState . FILTERS . map ( ( option ) => ( { label : option . label , value : option . value , } ) ) ; this . filter$ = this . store . listen$ ( ( [ main , nav , prefs ] ) => prefs . achievementsCompletedActiveFilter ) . pipe ( this . mapData ( ( [ filter ] ) => ( { filter : filter , placeholder : this . options . find ( ( option ) => option . value === filter ) ?. label , visible : true , } ) ) ) ; } ngAfterViewInit ( ) { this . stateUpdater = this . ow . getMainWindow ( ) . mainWindowStoreUpdater ; } onSelected ( option ) { this . stateUpdater . next ( new GenericPreferencesUpdateEvent ( ( prefs ) => ( { ... prefs , achievementsCompletedActiveFilter : option . value as any , } ) ) ) ; } }