import { AfterContentInit , ChangeDetectionStrategy , ChangeDetectorRef , Component } from '@angular/core' ; import { IOption } from 'ng-select' ; import { Observable } from 'rxjs' ; import { CardsFacadeService } from '../../../services/cards-facade.service' ; import { GenericPreferencesUpdateEvent } from '../../../services/mainwindow/store/events/generic-preferences-update-event' ; import { AppUiStoreFacadeService } from '../../../services/ui-store/app-ui-store-facade.service' ; import { AbstractSubscriptionComponent } from '../../abstract-subscription.component' ; @ Component ( { selector : 'replays-bg-hero-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"
			[options]="options"
			[filter]="value.filter"
			[placeholder]="value.placeholder"
			[visible]="value.visible"
			(onOptionSelected)="onSelected($event)"
		></filter-dropdown>
	` , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class ReplaysBgHeroFilterDropdownComponent extends AbstractSubscriptionComponent implements AfterContentInit { options : readonly IOption [ ] ; filter$ : Observable < { filter : string ; placeholder : string ; visible : boolean ; } > ; constructor ( private readonly allCards , protected readonly store , protected readonly cdr ) { super ( store , cdr ) ; const collator = new Intl . Collator ( 'en-US' ) ; this . options = [ { value : null , label : 'All heroes' , } as IOption , ... this . allCards . getCards ( ) . filter ( ( card ) => card . battlegroundsHero ) . map ( ( card ) => ( { label : card . name , value : card . id , } as IOption ) ) . sort ( ( a , b ) => collator . compare ( a . label , b . label ) ) , ] as readonly IOption [ ] ; } ngAfterContentInit ( ) { this . filter$ = this . store . listen$ ( ( [ main , nav , prefs ] ) => prefs . replaysActiveBgHeroFilter , ( [ main , nav , prefs ] ) => prefs . replaysActiveGameModeFilter ) . pipe ( this . mapData ( ( [ filter , gameModeFilter ] ) => ( { filter : filter , placeholder : this . options . find ( ( option ) => option . value === filter ) ?. label , visible : [ 'battlegrounds' ] . includes ( gameModeFilter ) , } ) ) ) ; } onSelected ( option ) { this . store . send ( new GenericPreferencesUpdateEvent ( ( prefs ) => ( { ... prefs , replaysActiveBgHeroFilter : option . value } ) ) ) ; } }