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

import { Component, Inject, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';

import { LoadingScreenOptions } from './loading-screen.model';
import { BciSharedIntl } from '../../shared/shared-intl';

@Component({
  selector: 'bci-loading-screen',
  templateUrl: './loading-screen.component.html',
  styleUrls: ['./loading-screen.component.scss'],
})
export class LoadingScreenComponent implements OnInit {
  private defaultInderminate = true;
  private defaultValuePercent = 0;
  private defaultCloseable = false;

  title: string;
  valuePercent: number;
  statusText: string;
  indeterminate: boolean;
  closeable: boolean;

  constructor(
    public intl: BciSharedIntl,
    @Inject(MAT_DIALOG_DATA) private data: LoadingScreenOptions,
    private dialogRef: MatDialogRef<LoadingScreenComponent>
  ) {}

  ngOnInit() {
    this.title = this.data.title !== undefined ? this.data.title : this.intl.loadingTitle;
    this.valuePercent = this.data.initialValue !== undefined ? this.data.initialValue : this.defaultValuePercent;
    this.statusText = this.data.initialStatus !== undefined ? this.data.initialStatus : this.intl.loadingStatus;
    this.indeterminate = this.data.indeterminate !== undefined ? this.data.indeterminate : this.defaultInderminate;
    this.closeable = this.data.closeable !== undefined ? this.data.closeable : this.defaultCloseable;
  }

  close() {
    this.dialogRef.close();
  }
}
