import { Component, OnInit, Input } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';
import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service';
import { AuthenticatedUser } from 'src/app/hmg-common/services/authentication/models/authenticated-user';

@Component({
  selector: 'app-business-card',
  templateUrl: './business-card.component.html',
  styleUrls: ['./business-card.component.scss'],
})
export class BusinessCardComponent implements OnInit {

  public userInfo: any;
  public userJobName: any;
  public jobName: any;
  constructor(
    public modalCtrl: ModalController,
    public ts: TranslatorService,
    public common: CommonService,
    public authService: AuthenticationService,
  ) { }

  ngOnInit() {
    this.userInfo = JSON.parse(localStorage.getItem('bussiness-card-info'));

    this.authService
      .loadAuthenticatedUser()
      .subscribe((user: AuthenticatedUser) => {
        if (user) {
          let jobTitle = user.POSITION_NAME.split('.');
          if (jobTitle && jobTitle.length > 1) {
            this.jobName = jobTitle[0] + " " + jobTitle[1];
          }
        }
      });
  }


  dismiss() {
    this.modalCtrl.dismiss({
      'dismissed': true
    });
  }

}