import { Component, OnInit } from '@angular/core';
import { AnimationController, ModalController } from '@ionic/angular';
import { Router } from '@angular/router';
import { LoginUserRespose } from 'src/app/models/user.model';
import { ProfilePage } from 'src/app/modals/profile/profile.page';
import { SessionStore } from 'src/app/store/session.service';


@Component({
  selector: 'app-header-no-search',
  templateUrl: './header-no-search.page.html',
  styleUrls: ['./header-no-search.page.scss'],
})
export class HeaderNoSearchPage implements OnInit {

  loggeduser: LoginUserRespose;
  SessionStore = SessionStore

  constructor(private modalController: ModalController,
    private animationController: AnimationController,
    private router: Router) {

      this.loggeduser = SessionStore.user;
    }

  ngOnInit() {
  }

  async openProfile() {

    const enterAnimation = (baseEl: any) => {
      const backdropAnimation = this.animationController.create()
        .addElement(baseEl.querySelector('ion-backdrop')!)
        .fromTo('opacity', '0.01', 'var(--backdrop-opacity)');

      const wrapperAnimation = this.animationController.create()
        .addElement(baseEl.querySelector('.modal-wrapper')!)
        .keyframes([
          { offset: 0, opacity: '1', right: '-100%' },
          { offset: 1, opacity: '1', right: '0px' }
        ]);

      return this.animationController.create()
        .addElement(baseEl)
        .easing('ease-out')
        .duration(500)
        .addAnimation([backdropAnimation, wrapperAnimation]);
    }

    const leaveAnimation = (baseEl: any) => {
      return enterAnimation(baseEl).direction('reverse');
    }


    const modal = await this.modalController.create({
      enterAnimation,
      leaveAnimation,
      component: ProfilePage,
      cssClass: 'model profile-modal',
      componentProps: {
      }
    });
    return await modal.present();
  }

  changeRoute(path){
    this.router.navigateByUrl(path)
  }

  locationPathname(): string {
    return window.location.pathname
  }


  profileLabel(text) {
    if (text == 'MDGPR') {
      return 'MD'
    } else if (text=='PR') {
      return text
    } else {
      return 'UN'
    }
  }

}
