<?php

namespace App\Livewire;

use App\Models\ZEmail;
use Livewire\Component;

class Home extends Component
{
    protected $listeners = ['fetchMessages' => 'checkIfAnyMessage'];

    public function checkIfAnyMessage()
    {
        $email = ZEmail::getEmail();
        $messages = ZEmail::getMessages($email);
        if (count($messages['data']) > 0) {
            return redirect()->route('mailbox');
        }
    }
    public function render()
    {
        return view('livewire.home');
    }
}
