import { Component } from '@angular/core';
import { ToastController } from '@ionic/angular';
import { UserService } from 'src/modules/user/service-user/user.service';
import * as Parse from "parse"

@Component({
  selector: 'app-me',
  templateUrl: './me.component.html',
  styleUrls: ['./me.component.scss']
})

export class MeComponent {

  currentUser: Parse.User | undefined


  constructor(
    private toastCtrl: ToastController,
    public userServ: UserService
  ) {
    this.currentUser = Parse.User.current();
  }

  async ngOnInit() {
    this.myAttentionList = await this.gteAttentionData()
    this.myScienceList = await this.getScienceData()
    this.myRecommendList = await this.getRecommendDate()
  }

  cate: string = "关注"
  myRecommendList: Array<Parse.Object> = []
  async getRecommendDate() {
    let query = new Parse.Query("PetRecommend");
    query.equalTo("user", Parse.User.current()?.toPointer())
    query.include("user")
    let list = await query.find();
    return list
  }
  
  myAttentionList: Array<Parse.Object> = []
  async gteAttentionData() {
    let query = new Parse.Query("PetAttention");
    query.equalTo("user", Parse.User.current()?.toPointer())
    query.include("user")
    let list = await query.find();
    return list
  }
  myScienceList: Array<Parse.Object> = []
  async getScienceData() {
    let query = new Parse.Query("PetScience");
    query.equalTo("user", Parse.User.current()?.toPointer())
    query.include("user")
    let list = await query.find();
    return list
  }
  async logout() {
    await Parse.User.logOut()
    this.currentUser = undefined
    let toast = await this.toastCtrl.create({
      message: "登出成功",
      position: "top",
      duration: 500
    })
    toast.present();
  }

}
