import { Component, OnInit, OnDestroy } from '@angular/core'; import { ActivatedRoute, Router, RouterModule } from '@angular/router'; import { forkJoin } from 'rxjs'; import { LucideAngularModule, ArrowLeft } from 'lucide-angular'; import { TranslatePipe, TranslateService } from '@ngx-translate/core'; import { CampaignService } from '../../../services/campaign.service'; import { NpcService } from '../../../services/npc.service'; import { RandomTableService } from '../../../services/random-table.service'; import { EnemyService } from '../../../services/enemy.service'; import { PlaythroughService } from '../../../services/playthrough.service'; import { LayoutService } from '../../../services/layout.service'; import { PageTitleService } from '../../../services/page-title.service'; import { Playthrough } from '../../../services/campaign.model'; import { loadCampaignTreeData, buildCampaignSidebarConfig } from '../../campaign-tree.helper'; import { PlaythroughFlagsManagerComponent } from '../../../shared/playthrough-flags-manager/playthrough-flags-manager.component'; /** * Page dédiée aux "Faits" d'une Partie. * Route : /campaigns/:campaignId/playthroughs/:playthroughId/flags */ @Component({ selector: 'app-playthrough-flags-page', imports: [RouterModule, LucideAngularModule, PlaythroughFlagsManagerComponent, TranslatePipe], templateUrl: './playthrough-flags-page.component.html', styleUrls: ['./playthrough-flags-page.component.scss'] }) export class PlaythroughFlagsPageComponent implements OnInit, OnDestroy { readonly ArrowLeft = ArrowLeft; campaignId = ''; playthroughId = ''; playthrough: Playthrough | null = null; constructor( private route: ActivatedRoute, private router: Router, private campaignService: CampaignService, private npcService: NpcService, private randomTableService: RandomTableService, private enemyService: EnemyService, private playthroughService: PlaythroughService, private layoutService: LayoutService, private pageTitleService: PageTitleService, private translate: TranslateService ) {} ngOnInit(): void { this.route.paramMap.subscribe(pm => { const cid = pm.get('campaignId')!; const pid = pm.get('playthroughId')!; if (cid !== this.campaignId || pid !== this.playthroughId) { this.campaignId = cid; this.playthroughId = pid; this.load(); } }); } private load(): void { forkJoin({ campaign: this.campaignService.getCampaignById(this.campaignId), allCampaigns: this.campaignService.getAllCampaigns(), treeData: loadCampaignTreeData(this.campaignService, this.campaignId, this.npcService, this.randomTableService, this.enemyService), playthrough: this.playthroughService.getById(this.playthroughId) }).subscribe(({ campaign, allCampaigns, treeData, playthrough }) => { this.playthrough = playthrough; this.pageTitleService.set(this.translate.instant('playthroughFlagsPage.pageTitle', { name: playthrough.name })); this.layoutService.show(buildCampaignSidebarConfig(campaign, allCampaigns, treeData, this.campaignId, this.translate)); }); } back(): void { this.router.navigate(['/campaigns', this.campaignId]); } ngOnDestroy(): void {} }