import { NgClass, NgIf } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { constants } from '@enums/constants.enum';
import { SanghProfileData } from '@interfaces/common';
import { IonicModule } from '@ionic/angular';
import { StateManagementService } from '@services/state-management.service';
import { UtilityService } from '@services/utility.service';

@Component({
  selector: 'app-about-sangh',
  templateUrl: './about-sangh.page.html',
  styleUrls: ['./about-sangh.page.scss'],
  standalone: true,
  imports: [IonicModule, NgIf, NgClass]
})
export class AboutSanghPage implements OnInit {
  sanghData: SanghProfileData;

  constructor(
    private router: Router,
    private utilityService: UtilityService,
    private stateManagementService: StateManagementService
  ) { }

  get sanghType() {
    return constants.sanghTypes.find(i => i.value === this.sanghData?.sangh_type)?.text;
  }

  get bhagwanName() {
    return this.stateManagementService?.common?.data?.mulnayak_bhagwan?.find(i => i.id === this.sanghData?.mulnayak_bhagwan_name)?.value;
  }

  get derasarType() {
    return this.stateManagementService?.common?.data?.derasar_type?.find(i => i.id === this.sanghData?.type_of_template)?.value;
  }

  get numberOfMember() {
    return this.stateManagementService?.common?.data?.number_of_members?.find(i => i.id === +this.sanghData?.number_of_members)?.value;
  }

  get numberOfStudent() {
    return this.stateManagementService?.common?.data?.number_of_students?.find(i => i.id === +this.sanghData?.no_of_students)?.value;
  }

  get numberOfBook() {
    return this.stateManagementService?.common?.data?.number_of_books?.find(i => i.id === +this.sanghData?.number_of_books)?.value;
  }

  get isLibraryActive(): boolean {
    return +this.sanghData.library_status > 0;
  }

  get isPathshalaActive(): boolean {
    return +this.sanghData.pathshala_status > 0;
  }

  get isPathshalaInactive(): boolean {
    return +this.sanghData.pathshala_status <= 0;
  }

  ngOnInit() {
    if (this.router.getCurrentNavigation().extras.state) {
      if (this.router.getCurrentNavigation().extras.state.sanghData) {
        this.sanghData = this.router.getCurrentNavigation().extras.state.sanghData;
      }
    }
  }

  address() {
    this.utilityService.openGoogleMap(this.sanghData.latitude, this.sanghData.longitude);
  }

}
