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

import { ChangeDetectorRef, Component, HostBinding, Input } from '@angular/core';

@Component({
  selector: 'bci-breadcrumb',
  templateUrl: './breadcrumb.component.html',
  styleUrls: ['./breadcrumb.component.scss'],
})
export class BreadcrumbComponent {
  @Input() title: string;
  @Input() url: string;

  @HostBinding('attr.title') titleAttribute = undefined;

  private _omitted = false;

  get omitted() {
    return this._omitted;
  }

  @Input()
  set omitted(value) {
    this._omitted = value;

    // handle ExpressionChangedAfterChecked issues for title
    setTimeout(() => (this.titleAttribute = this.omitted ? this.title : undefined));
    // ...and displayed title
    this.cdr.detectChanges();
  }

  constructor(private cdr: ChangeDetectorRef) {}
}
