<?php

namespace App\Livewire\Agent;

use App\Models\AgentLog;
use Livewire\Component;

class History extends Component
{
    public $history = [];

    protected $listeners = ['agent:sent' => 'reload'];

    public function mount(): void
    {
        $this->load();
    }

    public function reload(): void
    {
        $this->load();
    }

    private function load(): void
    {
        $this->history = AgentLog::where('user_id', auth()->id())
            ->latest()
            ->limit(8)
            ->get();
    }

    public function render()
    {
        return view('livewire.agent.history');
    }
}
