/*
 * Copyright (C) 2019 Robert Bosch GmbH Copyright (C) 2019 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { BreadcrumbsService } from '@bci-web-core/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

@Component({
  selector: 'bci-breadcrumbs-demo-subcomponent',
  templateUrl: './breadcrumbs-demo-subcomponent.component.html',
  styleUrls: ['./breadcrumbs-demo-subcomponent.component.scss'],
})
export class BreadcrumbsDemoSubcomponentComponent implements OnInit, OnDestroy {
  private componentDestroyed$ = new Subject<void>();

  constructor(private route: ActivatedRoute, private breadcrumbsService: BreadcrumbsService) {}

  ngOnInit() {
    this.route.params.pipe(takeUntil(this.componentDestroyed$)).subscribe((params) => {
      this.breadcrumbsService.setTemporaryTitleForRoute(this.route.snapshot, 'Level 3: ' + params['level3']);
    });
  }

  ngOnDestroy(): void {
    this.componentDestroyed$.next();
    this.componentDestroyed$.complete();
  }
}
