import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { NavController } from '@ionic/angular';
import { CloudObject } from 'src/lib/ncloud';

/**
 * 搜索结果列表页面组件
 * @Component 装饰器定义组件元数据
 */
@Component({
  selector: 'app-page-selectlist',
  templateUrl: './page-selectlist.page.html',
  styleUrls: ['./page-selectlist.page.scss'],
})
export class PageSelectlistPage {
  /**
   * 搜索查询字符串
   * @type {string}
   */
  searchQuery: string = '';

  /**
   * 搜索结果列表
   * @type {CloudObject[]}
   */
  searchResults: CloudObject[] = [];

  /**
   * 构造函数
   * @param {NavController} navCtrl Ionic导航控制器
   * @param {Router} router Angular路由服务
   * 
   * @description
   * 初始化时从导航状态中获取搜索结果数据
   */
  constructor(private navCtrl: NavController, private router: Router) {
    const navigation = this.router.getCurrentNavigation();
    if (navigation?.extras?.state) {
      this.searchResults = navigation.extras.state['searchResults'];
      console.log('Received search results:', this.searchResults);
    }
  }

  /**
   * 导航到食谱详情页面
   * @param {any} recipeId 食谱ID
   * @returns {void}
   * 
   * @example
   * goToDetail('recipe123');
   */
  goToDetail(recipeId: any): void {
    this.navCtrl.navigateForward(`/tabs/tab1/page-selectlist/page-selectlist-detail/${recipeId}`);
    console.log('Navigating to page-collections-detail');
  }

  /**
   * @ignore
   * 返回上一页（已注释）
   * @returns {void}
   */
  /*
  goBack(): void {
    this.navCtrl.navigateBack(['/tabs/tab1']);
  }
  */
}