<?php
/**
 * @var string $resources
 * @var string $svo_theme_resources
 * @var \kernel\CgView $view
 */
\kernel\Theme::$assetsCollector->registerAsset(new \app\themes\svo\assets\AdminSliderAssets($svo_theme_resources));
?>

<ul class="nav nav-tabs" id="myTab" role="tablist">
    <li class="nav-item" role="presentation">
        <button class="nav-link active" id="home-tab" data-toggle="tab" data-target="#home" type="button" role="tab"
                aria-controls="home" aria-selected="true">
            Основные
        </button>
    </li>
    <li class="nav-item" role="presentation">
        <button class="nav-link" id="slider-tab" data-toggle="tab" data-target="#slider" type="button" role="tab"
                aria-controls="slider" aria-selected="false">
            Слайдер
        </button>
    </li>
    <li class="nav-item" role="presentation">
        <button class="nav-link" id="contact-tab" data-toggle="tab" data-target="#contact" type="button" role="tab"
                aria-controls="contact" aria-selected="false">
            Contact
        </button>
    </li>
</ul>
<div class="tab-content" id="myTabContent">
    <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
        Основные настройки темы
    </div>
    <div class="tab-pane fade" id="slider" role="tabpanel" aria-labelledby="slider-tab">
        <div class="form-group">
            <label>Новости в сладере</label>
            <br>
            <form id="add_slide_form" action="/admin/svo-theme/add_slide" method="post">
                <select name="slide" class="form-control" id="postSelect" style="width: 300px">
                    <?php foreach (\kernel\modules\post\service\PostService::getListArr() as $key => $item): ?>
                        <option value="<?= $key ?>"><?= $item ?></option>
                    <?php endforeach; ?>
                </select>
            </form>
        </div>
        <br>
        <?= \kernel\helpers\Html::link('Добавить', '#', [
            'id' => 'saveSliderPost',
            'class' => 'btn btn-success',
            'onclick' => 'document.getElementById("add_slide_form").submit(); return false;'
        ]) ?>
        <br>
        <?php \app\themes\svo\widgets\AdminSliderPostsList::create()->run(); ?>
    </div>
    <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
        Contact
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        // Получаем параметр из URL
        const urlParams = new URLSearchParams(window.location.search);
        const activeTab = urlParams.get('tab');

        // Если параметр есть, активируем соответствующую вкладку
        if (activeTab) {
            const tabTrigger = new bootstrap.Tab(document.querySelector(`[data-target="#${activeTab}"]`));
            tabTrigger.show();
        }
    });
</script>
