<?php

namespace App\Controllers;

use App\Models\ActivityLogModel;

class Logs extends BaseController
{
    public function index(): string
    {
        return view('logs/index', $this->viewData());
    }

    public function listData(): \CodeIgniter\HTTP\ResponseInterface
    {
        $draw   = (int) ($this->request->getPost('draw') ?? 1);
        $start  = (int) ($this->request->getPost('start') ?? 0);
        $length = (int) ($this->request->getPost('length') ?? 25);
        $search = trim($this->request->getPost('search[value]') ?? '');

        $logModel = new ActivityLogModel();
        $result   = $logModel->getDataTable($start, $length, $search);

        return $this->response->setJSON([
            'draw'            => $draw,
            'recordsTotal'    => $result['total'],
            'recordsFiltered' => $result['filtered'],
            'data'            => $result['data'],
        ]);
    }
}
