<?php

namespace App\Events;

use App\Models\MensagemChat;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

 
   



class ChatComm implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $chat; 
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(MensagemChat $chat)
    {
        $this->chat=$chat;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    
    public function broadcastOn(): Channel
    { 

        return new Channel('canalChat');

    }
    public function broadcastWith(){

        $data="";

        $data.="
        <div class=\"message\">
        <img class=\"avatar-md\" src=\"".asset('storage/img/'.$this->chat->getOrigem->avatar)."\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"Keith\" alt=\"avatar\">
         <div class=\"text-main\">
             <div class=\"text-group\">
                 <div class=\"text\">
                     <p>".$this->chat->mensagem."</p>
                 </div>
             </div>
             <span>09:46 AM</span>
         </div>
     </div>
    ";

        return ['chat'=>$this->chat,'mensagem'=>$data];
    }
}
