<?php

namespace App\Helpers;

use CodeIgniter\HTTP\IncomingRequest;
use App\Models\MyLogModel;

class MyLogHelper extends CommonHelper
{
    protected ?IncomingRequest $request = null;
    public function __construct(?IncomingRequest $request = null)
    {
        parent::__construct($request);
        $this->setTitleField(MyLogModel::TITLE);
    }
    public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null
    {
        switch ($field) {
            case 'content':
                $value = nl2br($value);
                break;
            default:
                if (in_array($field, $viewDatas['control']['filter_fields'])) {
                    $value = $viewDatas['control']['filter_optons'][$field][$value]->getTitle();
                }
                break;
        }
        if (is_array($value)) {
            echo __METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다";
            exit;
        }
        return $value;
    }
    public function getListButton(string $action, array $viewDatas, array $extras = []): string
    {
        switch ($action) {
            case 'create':
                $action = "";
                break;
            case 'modify':
                $action = $viewDatas['cnt'];
                break;
            case 'delete':
                $action = "";
                break;
            case 'batchjob':
                $action = "";
                break;
            case 'batchjob_delete':
                $action = "";
                break;
            default:
                $action = parent::getListButton($action, $viewDatas, $extras);
                break;
        }
        return $action;
    }
}
