import { CUSTOM_ELEMENTS_SCHEMA, Component, ElementRef, NgZone, ViewChild, ViewEncapsulation } from '@angular/core';
import { GJainStorage } from '@enums/gjain-storage.enum';
import { Roots } from '@enums/root.enum';
import { IonicModule, NavController } from '@ionic/angular';
import { StateManagementService } from '@services/state-management.service';
import { register } from 'swiper/element/bundle';

register();
@Component({
  selector: 'app-intro',
  templateUrl: './intro.page.html',
  styleUrls: ['./intro.page.scss'],
  encapsulation: ViewEncapsulation.None,
  standalone: true,
  imports: [IonicModule],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class IntroPage {
  @ViewChild('swiper') swiper: ElementRef | undefined;
  activeIndex = Number(0);

  constructor(
    private navCtrl: NavController,
    private stateManagementService: StateManagementService,
    private ngZone: NgZone
  ) { }

  setSwiperInstance(swiper: any) {
    this.swiper = swiper;
  }

  slideChange() {
    this.activeIndex = this.swiper?.nativeElement.swiper.activeIndex;
  }

  goToNextSlide() {
    if (this.swiper?.nativeElement.swiper.activeIndex === 2) {
      this.ngZone.run(() => {
        this.stateManagementService.storage.set(GJainStorage.introScreen, 1);
        this.navCtrl.navigateForward(Roots.auth + '/' + Roots.register);
      });
    }
  }

}
