import { Component, OnInit, Input } from '@angular/core';
import { NGXLogger } from 'ngx-logger';
import { Info, EventType, EventJson } from '@ucap-webmessenger/protocol-event';
import { TranslateService } from '@ngx-translate/core';

@Component({
  selector: 'ucap-chat-message-box-information',
  templateUrl: './information.component.html',
  styleUrls: ['./information.component.scss']
})
export class InformationComponent implements OnInit {
  @Input()
  message: Info<EventJson>;
  @Input()
  senderName?: string;

  EventType = EventType;

  constructor(
    private translateService: TranslateService,
    private logger: NGXLogger
  ) {}

  ngOnInit() {}

  getI18nForSir(names: string | string[]) {
    if (Array.isArray(names)) {
      const inviter: string[] = [];

      names.forEach((userName, idx) => {
        inviter.push(
          this.translateService.instant('common.messages.sirWith', {
            sir: userName
          })
        );
      });

      return inviter.join(',');
    } else {
      return this.translateService.instant('common.messages.sirWith', {
        sir: names
      });
    }
  }

  getCalcTimer(millisec: number) {
    const langs = this.translateService.instant([
      'common.units.hourFrom',
      'common.units.minute',
      'common.units.second'
    ]);

    switch (millisec) {
      case 5000:
        return `5 ${langs['common.units.second']}`;
      case 10000:
        return `10 ${langs['common.units.second']}`;
      case 30000:
        return `30 ${langs['common.units.second']}`;
      case 60000:
        return `1 ${langs['common.units.minute']}`;
      case 300000:
        return `5 ${langs['common.units.minute']}`;
      case 600000:
        return `10 ${langs['common.units.minute']}`;
      case 1800000:
        return `30 ${langs['common.units.minute']}`;
      case 3600000:
        return `1 ${langs['common.units.hourFrom']}`;
      case 21600000:
        return `6 ${langs['common.units.hourFrom']}`;
      case 43200000:
        return `12 ${langs['common.units.hourFrom']}`;
      case 86400000:
        return `24 ${langs['common.units.hourFrom']}`;
      default:
        return `0 ${langs['common.units.second']}`;
    }
  }
}
