<?php

namespace app\themes\svo\controllers;

use app\themes\svo\services\MainPageSliderService;
use app\themes\svo\services\SvoThemeService;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\Request;

class SvoAdminController extends AdminController
{

    protected function init(): void
    {
        parent::init();
        $this->cgView->viewPath = APP_DIR . "/themes/svo/views/admin/";
        $this->cgView->addVarToLayout("svo_theme_resources", "/resources/themes/svo");
    }

    public function actionThemeSettings(): void
    {
        $this->cgView->render('theme_settings.php');
    }

    #[NoReturn] public function actionAddSlide(): void
    {
        $request = new Request();
        $slideId = $request->post('slide');

        SvoThemeService::addPostSlide($slideId);

        Flash::setMessage('success', 'Слайд добавлен.');
        $this->redirect('/admin/svo-theme/settings?tab=slider', 302);
    }

    #[NoReturn] public function actionDeleteSlide(int $post_id): void
    {
        $mainPageSlideService = new MainPageSliderService();
        $mainPageSlideService->removeSlide($post_id);

        Flash::setMessage('success', 'Слайд удален.');
        $this->redirect('/admin/svo-theme/settings?tab=slider', 302);
    }

}