<?php
if ($widgets) { ?>
    <?php foreach ($widgets as $widget) { ?>
        <?php if ($widget->position == $widgetPos) { ?>
            <?php if ($widget->preset) { ?>
                <?php include PATH_VIEW . "/widgets/{$widget->preset}.tpl"; ?>
            <?php } else { ?>
                <section class="mb-4 col-md-<?= $widget->col; ?>">
                    <?php if ($widget->is_title == 1 && !empty($widget->title)) { ?>
                        <?php if ($widget->position != 5) { ?>
                            <h2 class="title"><?= $widget->title; ?></h2>
                        <?php } else { ?>
                            <h5 class="title"><?= $widget->title; ?></h5>
                        <?php } ?>
                    <?php } ?>
                    <?php
                    if ($widget->type == 1 || $widget->type == 2) {
                        echo base64_decode($widget->contents);
                    } elseif ($widget->type == 3) {
                        $contentAds = json_decode($widget->contents);
                        if (!empty($contentAds->type)) {
                            if ($contentAds->type == 'slide') {
                                include PATH_VIEW . "/widgets/ads-slide.tpl";
                            } else {
                                include PATH_VIEW . "/widgets/ads.tpl";
                            }
                        }
                    } elseif ($widget->type == 4) {
                        include PATH_VIEW . "/widgets/poll.tpl";
                    }
                    ?>
                </section>
            <?php } ?>
        <?php } ?>
    <?php } ?>
<?php } ?>
