import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { IonHeader, IonButton, IonList, IonListHeader, IonItem, IonContent, IonIcon, IonLabel, IonCardHeader, IonCardContent, IonTitle, IonCard, IonToolbar, IonInput, IonSearchbar, IonSegment, IonSegmentButton, IonSelect, IonSelectOption } from '@ionic/angular/standalone';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms'; // 导入 FormsModule
import { HttpClient } from '@angular/common/http';
import { CloudObject } from 'src/lib/ncloud';
import { IonCardTitle } from '@ionic/angular/standalone';

@Component({
  selector: 'app-throw-drift-bottle',
  templateUrl: './throw-drift-bottle.component.html',
  styleUrls: ['./throw-drift-bottle.component.scss'],
  standalone: true,
  imports: [
    IonHeader, IonToolbar, IonTitle, IonContent, IonSegment, IonSegmentButton, IonSelect, IonSelectOption,
    FormsModule, IonList, IonListHeader, IonItem,
    IonLabel, IonIcon, IonButton, IonCardContent,
    IonInput, IonSearchbar, IonCard, IonCardHeader,
    CommonModule,IonCardTitle
  ]
})
export class ModalThrowDriftBottleComponent implements OnInit {
  driftbottleData: { content: string } = { content: '' }; // 漂流瓶内容

  constructor(private router: Router, private http: HttpClient) { }

  ngOnInit() {}

  throwdriftbottle() {
    console.log('投掷漂流瓶:');
    console.log(`内容: ${this.driftbottleData.content}`);
    // 这里可以添加逻辑将漂流瓶内容发布到后端或其他处理
    const driftbottleData = {
      content: this.driftbottleData.content,
    };

    let driftbottle = new CloudObject("Driftbottle");
    driftbottle.set(driftbottleData);
    driftbottle.save().then(data => {
      console.log('漂流瓶已成功投掷', data);
    }).catch(err => {
      console.error('投掷漂流瓶时出错');
    });
  }
}