import { Component, OnInit } from '@angular/core';
import { CloudShipu } from '../../lib/cloudshipu';  // 引入 CloudShipu 类
import { IonButton } from '@ionic/angular/standalone';
import { CloudQuery } from 'src/lib/ncloud';
import { NewlineToBrPipe } from '.././newline-to-br.pipe';  // 导入管道
import { IonicModule } from '@ionic/angular';  // 确保导入 IonicModule
import { sanitizeIdentifier } from '@angular/compiler';

@Component({
  selector: 'app-asy',
  templateUrl: './asy.component.html',
  styleUrls: ['./asy.component.scss'],
  standalone: true,
  imports: [
    IonButton,
    IonicModule
  ],
})
export class AsyComponent  implements OnInit {

  private CloudShipu: CloudShipu =new CloudShipu(); // 引入 CloudShipu 实例
  private shipuData: any = null; // 信息

    // 定义存储食谱详细信息的变量
    dishDetails: any = {
      title: '',
      image_url: '',
      ingredient: '',
      instructions: '',
      tips: '',
    };

  async ngOnInit(): Promise<void> {
    await this.loadUserData(); // 页面初始化时加载用户数据
    console.log(this.shipuData)
    const randomIndex = Math.floor(Math.random() * this.shipuData.length);

    // 访问这个随机索引的元素
    this.dishDetails = this.shipuData[randomIndex].data;
    // this.dishDetails = this.shipuData[1].data
  }
  
  async loadUserData() {
    try {
        this.shipuData = await this.CloudShipu.getAllShipu();
        
    } catch (error) {
        console.error('加载用户数据失败', error);
    }
  }

  
}

