import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { IonicModule } from '@ionic/angular';
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';

@Component({
  selector: 'app-chat',
  templateUrl: 'chat.page.html',
  styleUrls: ['chat.page.scss'],
  standalone: true,
  imports: [IonicModule, FormsModule, CommonModule]
})
export class ChatPage {
  username: string = '';
  newMessage: string = '';
  messages: any[] = [
    { text: '你好，您家的地址在哪里呢？', isSent: false, time: new Date() }
  ];

  constructor(private route: ActivatedRoute, private router: Router) {
    this.username = this.route.snapshot.paramMap.get('username') || '';
  }

  goBack() {
    this.router.navigate(['/tabs/tab2']); // 修改为正确的路由路径
  }

  sendMessage() {
    if (this.newMessage.trim()) {
      this.messages.push({
        text: this.newMessage,
        isSent: true,
        time: new Date()
      });
      this.newMessage = '';
      // 这里可以添加消息发送到服务器的逻辑
    }
  }
}
