
import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams } from '@ionic/angular';

@Component({
  selector: 'app-case-detail',
  templateUrl: './case-detail.page.html',
  styleUrls: ['./case-detail.page.scss'],
})
export class CaseDetailPage implements OnInit {

  case: any = {
    title: '',
    date: new Date()
  };
  index: number | undefined;

  constructor(
    private modalCtrl: ModalController,
    private navParams: NavParams
  ) {}

  ngOnInit() {
    // 接收从父组件传递的数据
    const caseData = this.navParams.get('case');
    if (caseData) {
      this.case = caseData;
    } else {
      this.case = { title: '', date: new Date() }; // 初始化一个新的空对象
    }
    this.index = this.navParams.get('index');

    // 调试信息
    console.log('Received case:', this.case);
    console.log('Received index:', this.index);
  }

  saveCase() {
    // 处理保存逻辑并返回数据
    this.modalCtrl.dismiss({ case: this.case, index: this.index });
  }

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