import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core'; import { CommonModule } from '@angular/common'; import { MatCardModule } from '@angular/material/card'; import { FormsModule } from '@angular/forms'; import { PlanGameComponent } from './plan-game/plan-game.component'; import { PlanService } from '../../core/services/plan.service'; import { GamePlan, PokemonFamilyEntry } from '../../core/models/plan.model'; import { PlanPokemonV2Component } from "./plan-pokemon/plan-pokemonV2.component"; import { ScrollingModule, CdkVirtualScrollViewport } from '@angular/cdk/scrolling'; import { PlanPokemonDetailsComponent } from "./plan-pokemon-details/plan-pokemon-details.component"; @Component({ selector: 'app-planV2', standalone: true, imports: [ CommonModule, MatCardModule, FormsModule, PlanGameComponent, PlanPokemonV2Component, ScrollingModule, PlanPokemonDetailsComponent ], template: `

{{ selectedGame.game_name }} - Game Stats

{{ selectedPokemon?.representative }} - Details

`, styles: [` .plan-container { display: flex; height: calc(100vh - 64px); /* Adjust based on your header height */ overflow: hidden; } .games-section { width: 11%; padding: 20px; overflow-y: auto; background: #f5f5f5; border-right: 1px solid #ddd; } .games-scroll { width: 100%; } .games-list { display: flex; flex-direction: column; gap: 16px; } .content-section { flex: 1; display: flex; flex-direction: column; padding: 20px; overflow: hidden; } .middle-section { flex: 2; display: flex; flex-direction: row; margin-right: 20px; } .game-stats { padding-bottom: 16px; border-bottom: 1px solid #ddd; margin-bottom: 16px; } .pokemon-section { flex: 1; min-height: 0; /* Important for Firefox */ display: flex; flex-direction: row; margin-right: 15px; } .pokemon-viewport { flex: 1; overflow-y: auto; padding: 16px; background: #f5f5f5; border-radius: 8px; margin-bottom: 20px; } .details-section { flex: 1; padding: 16px; background: #fff; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); width:15% } `] }) export class PlanV2Component implements OnInit { @ViewChild(CdkVirtualScrollViewport) viewport!: CdkVirtualScrollViewport; gamePlans: GamePlan[] = []; selectedGame: GamePlan | null = null; selectedPokemon: PokemonFamilyEntry | null = null; constructor(private planService: PlanService, private cdr: ChangeDetectorRef) {} ngOnInit() { this.loadPlan(); } private loadPlan() { this.planService.getPlan().subscribe( plan => { this.gamePlans = plan; if (!this.selectedGame && plan.length > 0) { this.selectedGame = plan[0]; } } ); } selectGame(game: GamePlan) { if (this.viewport) { this.viewport.scrollToIndex(0); // Reset scroll to top when switching games } this.selectedGame = null; // Clear the selected game first to avoid stale data this.cdr.detectChanges(); this.selectedGame = game; this.cdr.detectChanges(); } onPokemonStatusUpdate(event: { pfic: string, caught: boolean }) { this.loadPlan(); } selectPokemon(pokemon: any) { this.selectedPokemon = pokemon; } trackByPfic(index: number, item: any): string { return item.key; // Assuming PFIC or another unique identifier is available } }