<?php

namespace app\themes\svo\controllers;

use app\themes\svo\services\MainPageSliderService;
use kernel\Controller;
use kernel\helpers\Debug;
use kernel\modules\post\models\Post;
use kernel\modules\post\service\PostService;
use kernel\modules\user\service\UserService;

class LpController extends Controller
{

    protected \kernel\modules\user\models\User $user;
    protected MainPageSliderService $mainPageSliderService;

    protected function init(): void
    {
        parent::init();
        $this->cgView->viewPath = APP_DIR . "/themes/svo/views/lp/";
        $this->cgView->layout = "lp.php";
        $this->cgView->layoutPath = APP_DIR . "/themes/svo/views/layout/";
        $this->cgView->addVarToLayout("resources", "/resources/themes/svo/assets");

        $user = UserService::getAuthUser();
        $this->mainPageSliderService = new MainPageSliderService();
        if ($user){
            $this->cgView->addVarToLayout("currentUser", $user);
            $this->user = $user;
        }
    }

    public function actionIndex(): void
    {
        $this->cgView->render('index.php', []);
    }

    public function actionPost(int $postId): void
    {
        $post = Post::find($postId);

        $this->cgView->render('post.php', ['post' => $post]);
    }

}