import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { ChatMessage } from 'app/chat/models/chat-message';
import { ChatMessageType } from 'app/chat/models/chat-message-type.enum';

@Component({
  selector: 'app-chat-input',
  templateUrl: './chat-input.component.html',
  styleUrls: ['./chat-input.component.scss']
})
export class ChatInputComponent implements OnInit {

  message: ChatMessage;

  @Output()
  onMessageReady: EventEmitter<ChatMessage> = new EventEmitter();

  constructor() { }

  ngOnInit() {
    this.resetMessage();
  }

  messageReady() {
    this.onMessageReady.emit(this.message);
    this.resetMessage();
  }

  private resetMessage() {
    this.message = {
      type: ChatMessageType.TEXT
    } as ChatMessage;
  }

}
