<?php
namespace App\Controllers\manage;

use App\Controllers\BaseController;
use App\Models\manage\LoginLogModel;


class LoginLog extends BaseController
{
    private $logModel;

    public function __construct()
    {
        $this->logModel = new LoginLogModel();
    }

    public function lists()
    {
        return view("pages/manage/log/lists", $this->data);
    }

    public function getLogList()
    {
        $start = (int) $this->request->getGet('start') ?: 0;
        $end = (int) $this->request->getGet('length') ?: 10;

        $data = [
            'srchTxt' => $this->request->getGet('search[value]') ?: '',
        ];

        $totalCount = $this->logModel->getTotalCount($data);


        $datas = $this->logModel->getLoginLogList($start, $end, $data);


        return $this->response->setJSON(body: [
            'recordsTotal' => $totalCount,
            'recordsFiltered' => $totalCount,
            'data' => $datas,
        ]);
    }

    public function excel()
    {
        $data = [
            'srchTxt' => $this->request->getGet('search[value]') ?: '',
        ];

        $datas = $this->logModel->getExcelDownList($data);

        return $this->response->setJSON(body: [
            'data' => $datas,
        ]);
    }
}