import { AfterContentInit , ChangeDetectionStrategy , ChangeDetectorRef , Component , ElementRef , Renderer2 , } from '@angular/core' ; import { combineLatest , Observable } from 'rxjs' ; import { distinctUntilChanged , takeUntil } from 'rxjs/operators' ; import { Preferences } from '../../models/preferences' ; import { OverwolfService } from '../../services/overwolf.service' ; import { PreferencesService } from '../../services/preferences.service' ; import { AppUiStoreFacadeService } from '../../services/ui-store/app-ui-store-facade.service' ; import { AbstractWidgetWrapperComponent } from './_widget-wrapper.component' ; @ Component ( { selector : 'mercs-opponent-team-widget-wrapper' , styleUrls : [ '../../../css/component/overlays/decktracker-player-widget-wrapper.component.scss' ] , template : `
		<mercenaries-opponent-team
			class="widget"
			*ngIf="showWidget$ | async"
			cdkDrag
			(cdkDragStarted)="startDragging()"
			(cdkDragReleased)="stopDragging()"
			(cdkDragEnded)="dragEnded($event)"
		></mercenaries-opponent-team>
	` , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class MercsOpponentTeamWidgetWrapperComponent extends AbstractWidgetWrapperComponent implements AfterContentInit { protected defaultPositionLeftProvider = ( gameWidth , gameHeight ) => 0 ; protected defaultPositionTopProvider = ( gameWidth , gameHeight ) => 50 ; protected positionUpdater = ( left , top ) => this . prefs . updateMercenariesTeamOpponentPosition ( left , top ) ; protected positionExtractor = async ( prefs ) => prefs . mercenariesOpponentTeamOverlayPosition ; protected getRect = ( ) => this . el . nativeElement . querySelector ( '.widget' ) ?. getBoundingClientRect ( ) ; protected isWidgetVisible = ( ) => this . visible ; protected bounds = { left : - 100 , right : - 100 , top : - 50 , bottom : - 50 , } ; private visible : boolean ; showWidget$ : Observable < boolean > ; constructor ( protected readonly ow , protected readonly el , protected readonly prefs , protected readonly renderer , protected readonly store , protected readonly cdr ) { super ( ow , el , prefs , renderer , store , cdr ) ; } ngAfterContentInit ( ) { this . showWidget$ = combineLatest ( this . store . listenPrefs$ ( ( prefs ) => prefs . mercenariesEnableOpponentTeamWidget ) , this . store . listenMercenaries$ ( ( [ state , prefs ] ) => state ?. opponentClosedManually , ( [ state , prefs ] ) => ! ! state ?. opponentTeam ?. mercenaries ?. length ) ) . pipe ( this . mapData ( ( [ [ displayFromPrefs ] , [ playerClosedManually , hasTeamMercs ] ] ) => { return displayFromPrefs && ! playerClosedManually && hasTeamMercs ; } ) ) ; this . showWidget$ . pipe ( distinctUntilChanged ( ) , takeUntil ( this . destroyed$ ) ) . subscribe ( ( show ) => { this . visible = show ; this . reposition ( ) ; } ) ; } }