import { Component, Input } from '@angular/core';
import { ModalController, IonicModule } from '@ionic/angular';
import { CommonModule } from '@angular/common';
import { CloudObject } from 'src/lib/ncloud';
import { DetailModalComponent } from '../detail-modal/detail-modal.component'; // 确保路径正确

@Component({
  selector: 'app-all-products-modal',
  templateUrl: './all-products-modal.component.html',
  styleUrls: ['./all-products-modal.component.scss'],
  standalone: true,
  imports: [
    IonicModule,
    CommonModule,
    DetailModalComponent
  ]
})
export class AllProductsModalComponent {
  @Input() products: Array<CloudObject> = [];
  @Input() title: string = '';

  constructor(private modalCtrl: ModalController) {}

  // 关闭模态窗口
  dismiss() {
    this.modalCtrl.dismiss();
  }

  // 打开药品详情模态窗口
  async openDetailModal(product: any) {
    const modal = await this.modalCtrl.create({
      component: DetailModalComponent, // 确保 DetailModalComponent 已创建
      componentProps: { product: product },
      cssClass: 'bottom-modal'
    });
    return await modal.present();
  }
}