<?php

namespace App\Controllers\Admin;

use App\Controllers\CommonController;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;

abstract class AdminController extends CommonController
{
    private $_layout = 'admin';
    protected $layouts = [];
    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        parent::initController($request, $response, $logger);
        $this->addActionPaths($this->_layout);
        $this->layouts = LAYOUTS[$this->_layout];
    }
    protected function action_init_process(string $action, array $formDatas = []): void
    {
        parent::action_init_process($action, $formDatas);
        $this->addViewDatas('layout', $this->layouts);
        $this->addViewDatas('title', $this->getTitle());
        $this->addViewDatas('helper', $this->service->getHelper());
        $this->service->getActionForm()->action_init_process($action, $formDatas);
        $this->addViewDatas('formFields', $this->service->getActionForm()->getFormFields());
        $this->addViewDatas('formRules', $this->service->getActionForm()->getFormRules());
        $this->addViewDatas('formFilters', $this->service->getActionForm()->getFormFilters());
        $this->addViewDatas('formOptions', $this->service->getActionForm()->getFormOptions());
        $this->addViewDatas('index_actionButtons', $this->service->getActionForm()->getActionButtons());
        $this->addViewDatas('index_batchjobFields', $this->service->getActionForm()->getBatchjobFilters());
        $this->addViewDatas('index_batchjobButtons', $this->service->getActionForm()->getBatchjobButtons());
    }
}
