<ion-header>
  <ion-toolbar color="primary">
    <ion-buttons slot="start">
      <ion-back-button defaultHref="/tabs/contacts"></ion-back-button>
    </ion-buttons>
    <ion-title>{{ contactName }}</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content class="chat-content">
  <ion-list lines="none">
    <ion-item *ngFor="let message of messages" class="message-item">
      <ion-label class="message-container"
                 [class.sent-message-container]="message.type === 'sent'"
                 [class.received-message-container]="message.type === 'received'">
        <div class="message-details">
          <p [class.sent-message]="message.type === 'sent'"
             [class.received-message]="message.type === 'received'"
             class="message-text">{{ message.text }}</p>
          <div class="message-time">
            <p>{{ message.time }}</p>
          </div>
        </div>
      </ion-label>
      <ion-avatar slot="end" *ngIf="message.type === 'sent'" class="message-avatar sent-avatar">
        <img [src]="message.avatar">
      </ion-avatar>
      <ion-avatar slot="start" *ngIf="message.type === 'received'" class="message-avatar received-avatar">
        <img [src]="message.avatar">
      </ion-avatar>
    </ion-item>
  </ion-list>
</ion-content>

<ion-footer>
  <ion-toolbar>
    <ion-input placeholder="Type your message..." [(ngModel)]="newMessage" clearInput></ion-input>
    <ion-buttons slot="end">
      <ion-button (click)="sendMessage()" color="primary" [disabled]="!newMessage">Send</ion-button>
    </ion-buttons>
  </ion-toolbar>
</ion-footer>

