import { Component, OnInit } from '@angular/core';
import { PetService } from './pet.service';
import Parse from "parse";
@Component({
  selector: 'app-case-parse-petmarket',
  templateUrl: './case-parse-petmarket.page.html',
  styleUrls: ['./case-parse-petmarket.page.scss'],
})
export class CaseParsePetmarketPage implements OnInit {
  Foodcourts: any[] = [];
  searchQuery: string = '';
  selectedType: string = '';
  FoodcourtTypes: string[] = ['购物', '特色美食', '历史文化', '自然风光'];
  sortByName: boolean = false;
 
  constructor(private FoodcourtService: PetService) {}
  user:Parse.User|undefined
  ngOnInit() {
    this.user = Parse.User.current();
    this.fetchFoodcourts();
  }

  async fetchFoodcourts() {
    const queryParams = {
      name: this.searchQuery,
      type: this.selectedType,
      sortByName: this.sortByName
    };
    this.Foodcourts = await this.FoodcourtService.getFoodcourts(queryParams);
  }

  toggleSort() {
    this.sortByName = !this.sortByName;
    this.fetchFoodcourts();
  }
}
