import { Component } from '@angular/core';
import { ApiService } from '../../../frontcraft/services/login-api';
import { ShoutMessage } from '../../../../../../backend/Components/Shoutbox/Interface';

@Component({
  selector: 'chat',
  template: `
        <nb-chat title="Shoutbox" size="large" status="primary">
          <nb-chat-message *ngFor="let msg of messages"
                           [type]="text"
                           [message]="msg.message"
                           [sender]="msg.sender"
                           [date]="msg.date">
          </nb-chat-message>
          <nb-chat-form (send)="submit($event)" [dropFiles]="false">
          </nb-chat-form>
        </nb-chat>
  `, 
  styles: [`
  nb-chat {
    width: 600px;
    margin: 0.5rem 0 2rem 2rem;
  }`],
})
export class ChatComponent {

  messages : ShoutMessage[] = []
  history

  constructor(
    private api: ApiService
  ) {}

  submit(event){
    this.sendMessage({
      date: ""+Date.now(),
      message: event.message,
      sender: this.api.getCurrentUser().username
    })
  }

  sendMessage : (msg:ShoutMessage)=>Promise<void>
}
