<?php

namespace App\Controllers;

use App\Libraries\UserAuth;
use App\Models\UserModel;
use App\Models\VisitorModel;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\RESTful\ResourceController;

class DashboardController extends ResourceController
{
    protected $helpers = ['form', 'custom'];
    protected VisitorModel $visitorModel;

    public function __construct()
    {
        $this->visitorModel = new VisitorModel();
    }

    public function index()
    {
        $data = [
            'total' => $this->visitorModel->countAllVisitors(),
            'yesterday' => $this->visitorModel->countYesterdayVisitors(),
            'today' => $this->visitorModel->countTodayVisitors(),
            'in_premises' => $this->visitorModel->countInPremisesVisitors(),
            'visitors' => $this->visitorModel->getVisitors(5),
        ];
        return view("backend/dashboard", $data);
    }


    public function logout(): \CodeIgniter\HTTP\RedirectResponse
    {
        UserAuth::forget();
        return redirect()->route('home')
            ->with('fail', 'You are logged out!');
    }
    public function monitoring()
    {
        return view('backend/monitoring');
    }
}
