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

import { Component, EventEmitter, Input } from '@angular/core';
import { ClosableOverlayComponentModel } from '../bci-sidebar/closable-overlay-component.model';
import { BciLayoutIntl } from '../layout-intl';
import { LogoutComponentConfig } from './logout.component.model';

/**
 * Simple logout component to appear next to the user nav element. It will be properly aligned to the sidebar nav item.
 *
 * This component is dynamically created using portals, it must be included in the entryComponents of your NgModule!
 */
@Component({
  selector: 'bci-logout',
  templateUrl: './logout.component.html',
  styleUrls: ['./logout.component.scss'],
})
export class LogoutComponent implements ClosableOverlayComponentModel<LogoutComponentConfig> {
  /**
   * You must provide the header text and a logout callback
   */
  @Input() public config: LogoutComponentConfig;

  constructor(public layoutIntl: BciLayoutIntl) {}

  /**
   * Informs that the component wishes to be closed. Used by the overlay handler.
   */
  public onClose: EventEmitter<void> = new EventEmitter<void>();

  logout() {
    this.close();
    this.config.onLogout();
  }

  close() {
    this.onClose.emit();
  }
}
