import { AfterViewInit , ChangeDetectionStrategy , ChangeDetectorRef , Component , EventEmitter , Input , } from '@angular/core' ; import { BattleResultHistory } from '@firestone-hs/hs-replay-xml-parser/dist/public-api' ; import { BgsBattleSimulationUpdateEvent } from '@services/battlegrounds/store/events/bgs-battle-simulation-update-event' ; import { BgsSelectBattleEvent } from '@services/battlegrounds/store/events/bgs-select-battle-event' ; import { BattlegroundsStoreEvent } from '@services/battlegrounds/store/events/_battlegrounds-store-event' ; import { OverwolfService } from '@services/overwolf.service' ; import { BgsFaceOffWithSimulation } from '../../../models/battlegrounds/bgs-face-off-with-simulation' ; import { BgsBattleSimulationResetEvent } from '../../../services/battlegrounds/store/events/bgs-battle-simulation-reset-event' ; import { BattlegroundsMainWindowSelectBattleEvent } from '../../../services/mainwindow/store/events/battlegrounds/battlegrounds-main-window-select-battle-event' ; import { AppUiStoreFacadeService } from '../../../services/ui-store/app-ui-store-facade.service' ; import { AbstractSubscriptionComponent } from '../../abstract-subscription.component' ; @ Component ( { selector : 'bgs-battles-view' , styleUrls : [ `../../../../css/global/reset-styles.scss` , `../../../../css/global/scrollbar.scss` , `../../../../css/component/controls/controls.scss` , `../../../../css/component/controls/control-close.component.scss` , `../../../../css/component/battlegrounds/battles/bgs-battles-view.component.scss` , ] , template : `
		<div class="container">
			<div class="content empty-state" *ngIf="!faceOffs?.length">
				<i>
					<svg>
						<use xlink:href="assets/svg/sprite.svg#empty_state_tracker" />
					</svg>
				</i>
				<span class="title" [owTranslate]="'battlegrounds.sim.empty-state-title'"></span>
				<span class="subtitle" [owTranslate]="'battlegrounds.sim.empty-state-subtitle'"></span>
			</div>
			<ng-container>
				<div class="content" *ngIf="faceOffs?.length">
					<ng-container *ngIf="selectedFaceOff">
						<bgs-battle
							class="battle"
							[faceOff]="selectedFaceOff"
							[hideActualBattle]="false"
							[actualBattle]="actualBattle$ | async"
							[clickToChange]="true"
							[allowClickToAdd]="true"
							[closeOnMinion]="true"
							[fullScreenMode]="false"
							[showTavernTier]="true"
							[additionalClass]="'inline'"
							[simulationUpdater]="simulationUpdater"
							[simulationReset]="simulationReset"
						></bgs-battle>
						<button class="i-30 close-button" (mousedown)="closeBattle()">
							<svg class="svg-icon-fill">
								<use
									xmlns:xlink="https://www.w3.org/1999/xlink"
									xlink:href="assets/svg/sprite.svg#window-control_close"
								></use>
							</svg>
						</button>
						<div class="battles-header" [owTranslate]="'battlegrounds.sim.battles-header'"></div>
					</ng-container>
					<div class="battles-list" scrollable>
						<bgs-battle-recap
							*ngFor="let faceOff of faceOffs; trackBy: trackByFn"
							[faceOff]="faceOff"
							(click)="selectBattle(faceOff)"
							[ngClass]="{
								'highlighted': selectedFaceOff?.id && faceOff.id === selectedFaceOff.id
							}"
						></bgs-battle-recap>
					</div>
				</div>
			</ng-container>
			<div class="left">
				<div class="header" [owTranslate]="'battlegrounds.sim.turn-winrate-graph-title'"></div>
				<div class="left-info">
					<bgs-winrate-chart class="chart" [battleResultHistory]="battleResultHistory"></bgs-winrate-chart>
				</div>
			</div>
		</div>
	` , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class BgsBattlesViewComponent extends AbstractSubscriptionComponent implements AfterViewInit { simulationUpdater : ( currentFaceOff : BgsFaceOffWithSimulation , partialUpdate : BgsFaceOffWithSimulation ) => void ; simulationReset : ( faceOffId : string ) => void ; @ Input ( ) faceOffs : readonly BgsFaceOffWithSimulation [ ] ; @ Input ( ) selectedFaceOff : BgsFaceOffWithSimulation ; @ Input ( ) actualBattle : BgsFaceOffWithSimulation ; @ Input ( ) battleResultHistory : readonly BattleResultHistory [ ] ; @ Input ( ) set isMainWindow ( value ) { this . _isMainWindow = value ; this . ngAfterViewInit ( ) ; } private _isMainWindow : boolean ; private battlegroundsUpdater : EventEmitter < BattlegroundsStoreEvent > ; constructor ( private readonly ow , protected readonly store , protected readonly cdr ) { super ( store , cdr ) ; } async ngAfterViewInit ( ) { this . battlegroundsUpdater = ( await this . ow . getMainWindow ( ) ) . battlegroundsUpdater ; this . simulationUpdater = ( currentFaceOff , partialUpdate ) => { this . battlegroundsUpdater . next ( new BgsBattleSimulationUpdateEvent ( currentFaceOff , partialUpdate ) ) ; } ; this . simulationReset = ( faceOffId ) => { this . battlegroundsUpdater . next ( new BgsBattleSimulationResetEvent ( faceOffId ) ) ; } ; } selectBattle ( faceOff ) { if ( this . _isMainWindow ) { this . store . send ( new BattlegroundsMainWindowSelectBattleEvent ( faceOff ) ) ; } else { this . battlegroundsUpdater . next ( new BgsSelectBattleEvent ( faceOff ?. id ) ) ; } } closeBattle ( faceOff ) { this . battlegroundsUpdater . next ( new BgsSelectBattleEvent ( null ) ) ; } trackByFn ( index , item ) { return item . id ; } }