import { NgIf } from '@angular/common';
import { Component, Input, OnInit } from '@angular/core';
import { AvatarPercentageComponent } from '@components/avatar-percentage/avatar-percentage.component';
import { GJainStorage } from '@enums/gjain-storage.enum';
import { Roots } from '@enums/root.enum';
import { SantActivityList, UserData } from '@interfaces/common';
import { IonicModule, NavController } from '@ionic/angular';
import { StateManagementService } from '@services/state-management.service';
import { UtilityService } from '@services/utility.service';

@Component({
  selector: 'app-sant-post',
  templateUrl: './sant-post.component.html',
  styleUrls: ['./sant-post.component.scss'],
  standalone: true,
  imports: [IonicModule, AvatarPercentageComponent, NgIf]
})
export class SantPostComponent implements OnInit {
  @Input() post: SantActivityList;
  userData: UserData;

  constructor(
    private navCtrl: NavController,
    private utilityService: UtilityService,
    private stateManagementService: StateManagementService,
  ) { }

  async ngOnInit() {
    this.userData = await this.stateManagementService.storage.get(GJainStorage.userData);
  }

  santProfile(id: number) {
    this.navCtrl.navigateForward([Roots.page + '/' + Roots.santViewProfile, { santId: id }]);
  }

  openReport(id) {
    this.utilityService.openReport({ postId: id, type: 'sant' });
  }

  hidePost(post) {
    this.utilityService.hidePost(post);
  }

  redirectToUser(id) {
    if (id === this.userData.id) {
      this.navCtrl.navigateForward(Roots.page + '/' + Roots.shravakViewProfile);
    } else {
      this.navCtrl.navigateForward([Roots.page + '/' + Roots.shravakOtherProfile, { id }]);
    }
  }

}
