import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { addIcons } from 'ionicons';
import { basketOutline, bookmark, bookmarkOutline, flameOutline, peopleOutline, restaurantOutline, shareSocialOutline, star, starOutline, timeOutline } from 'ionicons/icons';
import { CloudObject, CloudQuery } from 'src/lib/ncloud';

/**
 * 收藏详情页面组件
 * @Component 装饰器定义组件元数据
 * @description 显示用户收藏的食谱详细信息
 */
@Component({
  selector: 'app-page-collections-detail',
  templateUrl: './page-collections-detail.page.html',
  styleUrls: ['./page-collections-detail.page.scss'],
  standalone: false
})
export class PageCollectionsDetailPage implements OnInit {

  /**
   * 构造函数
   * @param {ActivatedRoute} route 路由服务，用于获取参数
   * 
   * @description 
   * 初始化时自动加载图标并订阅路由参数变化
   */
  constructor(
    private route: ActivatedRoute
  ) {
    // 添加所有需要的图标
    addIcons({ 
      timeOutline,
      flameOutline,
      peopleOutline,
      basketOutline,
      restaurantOutline,
      star,
      starOutline,
      bookmark,
      bookmarkOutline,
      shareSocialOutline 
    });
    
    // 订阅路由参数变化
    this.route.params.subscribe(params => {
      console.log(params);
      this.loadRecipe(params['recipeId']);
    });
  }

  /**
   * 当前食谱数据
   * @type {CloudObject | undefined | null}
   */
  recipe: CloudObject | undefined | null;

  /**
   * 加载指定ID的食谱详情
   * @async
   * @param {string} recipeId 食谱ID
   * @returns {Promise<void>}
   * 
   * @description
   * 从云端查询指定ID的食谱详细信息
   * 
   * @example
   * await loadRecipe('recipe123');
   */
  async loadRecipe(recipeId: string): Promise<void> {
    let query = new CloudQuery("Recipe");
    this.recipe = await query.get(recipeId);
    console.log(this.recipe);
  }

  /**
   * 组件初始化生命周期钩子
   * @returns {void}
   */
  ngOnInit(): void {
    // 预留初始化逻辑
  }
}