import { Component, OnInit, Input,} from '@angular/core';
import { ModalController, IonHeader, IonContent, IonInput, IonToolbar, IonItem, IonButtons, IonButton, IonTitle } from '@ionic/angular/standalone';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { IonicModule } from '@ionic/angular';
import { CloudObject } from 'src/lib/ncloud';

@Component({
  selector: 'app-data-modal',
  templateUrl: './data-modal.component.html',
  styleUrls: ['./data-modal.component.scss'],
  standalone: true,
  imports: [
    IonicModule,IonHeader,IonContent,IonInput,IonToolbar,IonItem,IonButtons,IonButton,
    IonTitle,FormsModule,ReactiveFormsModule,
  ]
})

export class DataModalComponent  implements OnInit {
  name: string = '';

  constructor(private modalCtrl: ModalController) {
  }

  ngOnInit(){
  }

  cancel() {
    return this.modalCtrl.dismiss(null, 'cancel');
  }

  confirm() {
    return this.modalCtrl.dismiss(this.name, 'confirm');
  }
}

export async function cardDisplay(modalCtrl:ModalController){
    const modal = await modalCtrl.create({
        component: DataModalComponent,
        breakpoints:[0.5,0.7],
        initialBreakpoint:0.5
    });
    modal.present(); // 展示模态框
    const { role, data } = await modal.onDidDismiss(); // 等待用户关闭模态框并获取返回的数据
    console.log(data); // 打印返回的数据
    if (role === 'confirm') {
        console.log('User confirmed the action');
        return data;
    }
}
