import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { IonButtons, IonHeader, IonToolbar,IonButton, IonIcon, IonTitle, IonInput, IonFooter, IonContent, AlertController, IonCardContent, IonList, IonItem, IonLabel, IonCard, IonCardHeader, IonCardTitle, NavController,  } from '@ionic/angular/standalone';
@Component({
  selector: 'app-chat-content',
  templateUrl: './chat-content.component.html',
  styleUrls: ['./chat-content.component.scss'],
  standalone: true,
  imports: [IonHeader,IonToolbar,IonTitle,IonContent,IonList,IonItem,IonLabel,CommonModule,IonCard,IonCardHeader,IonCardTitle,
      IonButton,IonCardContent,IonIcon,IonButtons,IonInput,IonFooter,IonInput,IonContent,],
  
})
export class ChatContentComponent  implements OnInit {

  chat: any;
  selectedChat: any; // 存储当前选择的聊天记录,json字符串

  constructor(private router: Router,private navCtrl: NavController) {
    const navigation = this.router.getCurrentNavigation();
    if (navigation && navigation.extras.state) {
       // 使用类型断言
       this.chat = (navigation.extras.state as { chat: any }).chat;
       console.log(this.chat);
    }
  }

  ngOnInit() {
    this.handle()
  }


  handle(){
       this.selectedChat = this.chat.data.content; // 更新当前选择的聊天记录
    console.log("选择聊天记录", this.selectedChat);
    // 解析 JSON 字符串为对象数组
 this.selectedChat = JSON.parse(this.selectedChat);
console.log("解析后的聊天记录", this.selectedChat);
  }

  goBack() {
    this.navCtrl.back(); // 返回上一页
    }

}
