<?php

namespace App\Helpers;

use App\Models\MyLogModel;

class MyLogHelper extends CommonHelper
{
    public function __construct()
    {
        parent::__construct();
        $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']['actionFilters'])) {
                    if (array_key_exists($value, $viewDatas['control']['filter_optons'][$field])) {
                        $value = $viewDatas['control']['filter_optons'][$field][$value]->getTitle();
                    } else {
                        $value = "";
                    }
                }
                break;
        }
        if (is_array($value)) {
            echo __METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다";
            exit;
        }
        return $value;
    }
    public function getListButton(string $action, string $label, array $viewDatas, array $extras = []): string
    {
        switch ($action) {
            case 'modify':
                $action = $viewDatas['cnt'];
                break;
            case 'create':
            case 'delete':
            case 'batchjob':
            case 'batchjob_delete':
                $action = "";
                break;
            default:
                $action = parent::getListButton($action, $label, $viewDatas, $extras);
                break;
        }
        return $action;
    }
}
