import { IController } from 'angular';

/**
 * Controller holding the application-logic for <browser-support>
 */
export class BrowserSupportController implements IController {
  /**
   * The state of visibility
   */
  public showNotification = false;
  /**
   * The key under which the state will be saved in sessionStorage
   */
  public readonly sessionStorageKey = 'browserWarningDismissed'
  /**
   * @constructor
   */
  constructor() {
    if (sessionStorage.getItem(this.sessionStorageKey)) {
      this.showNotification = false;
    } else {
      const ieVersion = document['documentMode'];
      this.showNotification = ieVersion && ieVersion <= 11;
    }
  }
  /**
   * Closes the dialog and saves this to sessionStorage
   * to prevent popping up on every new page-visit
   *
   * @return void
   */
  public closeDialog(): void {
    sessionStorage.setItem(this.sessionStorageKey, 'true');
    this.showNotification = false;
  }
}
