import * as Log from './../util/logging.js'
import { UnoSession, UnoPlayer, } from './UnoSession.js';

export class UnoChat {
    private chatHistory: string[];
    private game: UnoSession;
    constructor(game: UnoSession) {
        this.chatHistory = [];
        this.game = game;
    }

    public writeMessage (msg:string ) {
        let now = new Date();
        let timestamp = now.getHours() + ":" + now.getMinutes();
        const line = "<span class='chat-line-date'>" + timestamp + "</span><span class='chat-line-msg'> " + msg + "</span><br />"
        Log.logChat(line);

        [...this.game.players, ...this.game.winners].forEach(el =>{
            if (el.socket && el.socket?.OPEN){
                el.socket.send(JSON.stringify({
                    "chat": line
                }))
            }
        })
    
    }

}

