import { Component } from '@angular/core';
import { NavController } from '@ionic/angular';
import { Router } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
import { FormsModule } from '@angular/forms';

@Component({
  selector: 'app-chat',
  templateUrl: 'chat.page.html',
  styleUrls: ['chat.page.scss']
})
export class ChatPage {
  contactName: string;
  messages = [
    { type: 'received', avatar: 'assets/1.png', time: '10:30 AM', text: 'Hi there!' },
    { type: 'sent', avatar: 'assets/美津未.jpg', time: '10:31 AM', text: 'Hey! How are you?' },
    // Add more messages as needed
  ];
  
  newMessage: string = '';

  constructor(private route: ActivatedRoute) {
    this.contactName = this.route.snapshot.paramMap.get('username') as string;
  }

  sendMessage() {
    if (this.newMessage.trim() === '') {
      return;
    }
    this.messages.push({ type: 'sent', avatar: 'assets/美津未.jpg', time: this.getCurrentTime(), text: this.newMessage });
    this.newMessage = '';
  }

  getCurrentTime() {
    const now = new Date();
    return now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
  }
}