<?php

declare(strict_types=1);

namespace Plugin\tnt_stabila_shop\adminmenu\Controller;

use JTL\Shop;
use Plugin\tnt_stabila_shop\src\Repositories\DatabaseRepository;
use Plugin\tnt_stabila_shop\src\Repositories\SessionRepository;
use Plugin\tnt_stabila_shop\src\Services\SettingsService;

class Dashboard extends BaseController
{
    public function handleRequest(): string
    {
        $settingService = new SettingsService(
            new DatabaseRepository(Shop::Container()->getDB()),
            new SessionRepository('tnt_stabila_shop'),
            Shop::Container()->getCache()
        );

        $performanceBoosterIsEnabled    = (int)$settingService->getPerformanceBoosterEnabled();
        $performanceBoosterCanBeEnabled = $settingService->canBeEnabled('performanceBooster');
        $this->smarty
            ->assign(
                tpl_var: 'performanceBooster',
                value: $performanceBoosterIsEnabled && $performanceBoosterCanBeEnabled
            )->assign(
                tpl_var: 'performanceBoosterDisabled',
                value: $performanceBoosterCanBeEnabled === false
            )->assign(
                tpl_var: 'qualityBooster',
                value: $settingService->getSetting('qualityBooster') ?? 0
            );

        return $this->smarty->fetch(self::TAIL_ADMIN_PATH . 'smarty/static/tabs/dashboard.tpl');
    }
}
