<?php

namespace app\themes\svo\widgets;

use app\themes\svo\services\MainPageSliderService;
use kernel\modules\post\models\Post;
use kernel\Widget;

class MainSliderWidget extends Widget
{
    protected MainPageSliderService $mainPageSliderService;

    protected function init(): void
    {
        $this->cgView->viewPath = APP_DIR . "/themes/svo/views/widget/";
        $this->mainPageSliderService = new MainPageSliderService();
    }

    public function run(): void
    {
        $slides = $this->mainPageSliderService->getSlides();
        $posts = Post::whereIn('id', $slides)->get();

        $this->cgView->render("main_slider.php", [
            'resources' => $this->data['resources'],
            'posts' => $posts,
        ]);
    }

}