import { AfterContentInit , ChangeDetectionStrategy , ChangeDetectorRef , Component , ElementRef , Renderer2 , } from '@angular/core' ; import { SceneMode } from '@firestone-hs/reference-data' ; 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 : 'bgs-battle-simulation-widget-wrapper' , styleUrls : [ '../../../css/component/overlays/decktracker-player-widget-wrapper.component.scss' ] , template : `
		<bgs-simulation-overlay
			class="widget"
			*ngIf="showWidget$ | async"
			cdkDrag
			(cdkDragStarted)="startDragging()"
			(cdkDragReleased)="stopDragging()"
			(cdkDragEnded)="dragEnded($event)"
		></bgs-simulation-overlay>
	` , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class BgsBattleSimulationWidgetWrapperComponent extends AbstractWidgetWrapperComponent implements AfterContentInit { protected defaultPositionLeftProvider = ( gameWidth , gameHeight ) => gameWidth / 2 - 200 ; protected defaultPositionTopProvider = ( gameWidth , gameHeight ) => 0 ; protected positionUpdater = ( left , top ) => this . prefs . updateBgsSimulationWidgetPosition ( left , top ) ; protected positionExtractor = async ( prefs ) => prefs . bgsSimulationWidgetPosition ; protected getRect = ( ) => this . el . nativeElement . querySelector ( '.widget' ) ?. getBoundingClientRect ( ) ; protected isWidgetVisible = ( ) => this . visible ; 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 . listen$ ( ( [ main , nav , prefs ] ) => main . currentScene , ( [ main , nav , prefs ] ) => prefs . bgsEnableBattleSimulationOverlay && prefs . bgsEnableSimulation && prefs . bgsFullToggle ) , this . store . listenBattlegrounds$ ( ( [ state , prefs ] ) => state ?. inGame , ( [ state , prefs ] ) => ! ! state ?. currentGame , ( [ state , prefs ] ) => state ?. currentGame ?. gameEnded ) ) . pipe ( this . mapData ( ( [ [ currentScene , displayFromPrefs ] , [ inGame , isCurrentGame , gameEnded ] ] ) => { return inGame && isCurrentGame && ! gameEnded && displayFromPrefs && currentScene === SceneMode . GAMEPLAY ; } ) ) ; this . showWidget$ . pipe ( distinctUntilChanged ( ) , takeUntil ( this . destroyed$ ) ) . subscribe ( ( show ) => { this . visible = show ; this . reposition ( ) ; } ) ; } }