<?php
require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php');
require __DIR__ . '/include/noindex.php';
require_once __DIR__ . '/include/seo.php';
require_once __DIR__ . '/include/catalog_data.php';

lt_apply_seo(lt_seo_home());
require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/header.php');
$APPLICATION->SetPageProperty('HIDETITLE', 'Y');
$APPLICATION->SetPageProperty('HIDE_LEFT_BLOCK', 'Y');
$APPLICATION->SetPageProperty('HIDE_SIDEBAR', 'Y');

$ltActive = 'home';
$ltHome = true;
require __DIR__ . '/include/header.php';
$ltBase = lt_catalog_base();
$a = $ltBase . '/assets';

$bundle = lt_load_collections_bundle();
$homeRoots = array_values(array_filter(
    array_map('strval', (array) ($bundle['roots'] ?? [])),
    static fn (string $id): bool => $id !== '' && $id !== 'all'
));

require_once __DIR__ . '/include/blog_data.php';
$homeBlog = lt_blog_home_lists();
$articles = $homeBlog['articles'];
$news = $homeBlog['news'];
?>

<section class="lt-hero">
  <div class="lt-hero__bg" aria-hidden="true"></div>
  <div class="lt-wrap lt-hero__content">
    <h1>Разработка и производство микроволновых компонентов</h1>
    <p>Направления: связь 5G, испытания и измерения, астрономия, коммуникационные подсистемы и криогенные компоненты</p>
    <a class="lt-btn" href="<?= $ltBase ?>/catalog/">Перейти в каталог</a>
  </div>
</section>

<section class="lt-catalog">
  <div class="lt-wrap">
    <h2 class="lt-lined-title">Каталог</h2>
    <p class="lt-catalog__lead">Категории</p>
    <div class="lt-catalog__grid">
      <?php
      $ltChevron = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M6 9l6 6 6-6" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>';
      $subsVisible = 8;
      foreach ($homeRoots as $rootId):
          $rootTitle = lt_collection_title($rootId);
          $rootImg = lt_root_category_icon($rootId);
          $childIds = array_values(array_filter(
              lt_collection_children($rootId),
              static function (string $cid) use ($bundle): bool {
                  return $cid !== '' && (isset($bundle['collections'][$cid]) || isset($bundle['tree'][$cid]));
              }
          ));
          ?>
      <div class="lt-col">
        <div class="lt-col__head">
          <a class="lt-col__icon" href="<?= htmlspecialcharsbx(lt_collection_url($rootId)) ?>">
            <?php if ($rootImg !== ''): ?>
              <img src="<?= htmlspecialcharsbx($rootImg) ?>" alt="">
            <?php endif; ?>
          </a>
          <h3 class="lt-col__title"><a href="<?= htmlspecialcharsbx(lt_collection_url($rootId)) ?>"><?= htmlspecialcharsbx($rootTitle) ?></a></h3>
          <?php if ($childIds): ?>
            <button type="button" class="lt-col__toggle" data-lt-accordion aria-expanded="false" aria-label="Показать подкатегории"><?= $ltChevron ?></button>
          <?php endif; ?>
        </div>
        <?php if ($childIds): ?>
        <div class="lt-col__subs">
          <?php foreach ($childIds as $i => $cid): ?>
            <a<?= $i >= $subsVisible ? ' class="is-extra"' : '' ?> href="<?= htmlspecialcharsbx(lt_collection_url($cid)) ?>"><?= htmlspecialcharsbx(lt_collection_title($cid)) ?></a>
          <?php endforeach; ?>
          <?php if (count($childIds) > $subsVisible): ?>
            <button type="button" class="lt-col__more" data-lt-more>Ещё +</button>
            <button type="button" class="lt-col__less" data-lt-less>Скрыть</button>
          <?php endif; ?>
        </div>
        <?php endif; ?>
      </div>
      <?php endforeach; ?>
    </div>
  </div>
</section>

<section class="lt-press" data-lt-slider>
  <div class="lt-wrap">
    <div class="lt-slider-head">
      <h2>О нас пишут</h2>
      <div class="lt-nav-btns">
        <button type="button" data-lt-prev aria-label="Назад">‹</button>
        <button type="button" data-lt-next aria-label="Вперёд">›</button>
      </div>
    </div>
    <div class="lt-track lt-press__track">
      <a class="lt-press__item" href="https://www.cnews.ru/news/line/2025-03-24_v_rossii_anonsirovan_proizvoditelnyj" target="_blank" rel="noopener">
        <img class="lt-press__img" src="<?= $a ?>/press/press-cnews.png" alt="CNews" loading="eager" decoding="async">
      </a>
      <a class="lt-press__item" href="https://dzen.ru/a/Z-Z7XczAIkUDzyb5" target="_blank" rel="noopener">
        <img class="lt-press__img" src="<?= $a ?>/press/press-dzen.png" alt="Дзен" loading="eager" decoding="async">
      </a>
      <a class="lt-press__item" href="https://microwave-e.ru/market/lauftex/" target="_blank" rel="noopener">
        <img class="lt-press__img" src="<?= $a ?>/press/press-microwave-orig.jpg" alt="СВЧ Электроника" loading="eager" decoding="async">
      </a>
      <a class="lt-press__item" href="https://1d.media/aggregator/detail.php?ID=32646" target="_blank" rel="noopener">
        <img class="lt-press__img" src="<?= $a ?>/press/press-1d-orig.png" alt="Первый цифровой" loading="eager" decoding="async">
      </a>
      <a class="lt-press__item" href="https://russianelectronics.ru/rossijskie-razrabotchiki-sozdali-metod-prediktivnoj-diagnostiki-sistem-svyazi/" target="_blank" rel="noopener">
        <img class="lt-press__img" src="<?= $a ?>/press/press-vreya.png" alt="Время электроники" loading="eager" decoding="async">
      </a>
    </div>
  </div>
</section>

<section class="lt-articles" data-lt-slider>
  <div class="lt-wrap">
    <div class="lt-slider-head">
      <div class="lt-nav-btns">
        <button type="button" data-lt-prev aria-label="Назад">‹</button>
        <button type="button" data-lt-next aria-label="Вперёд">›</button>
      </div>
      <h2 class="lt-lined-title">Обзорные статьи</h2>
    </div>
    <div class="lt-track">
      <?php foreach ($articles as $item): ?>
        <a class="lt-card" href="<?= htmlspecialcharsbx($item['url']) ?>">
          <?php if (!empty($item['img'])): ?>
            <img src="<?= htmlspecialcharsbx($item['img']) ?>" alt="" loading="lazy">
          <?php endif; ?>
          <div class="lt-card__title"><?= htmlspecialcharsbx($item['title']) ?></div>
          <?php if (!empty($item['date'])): ?>
            <div class="lt-card__date"><?= htmlspecialcharsbx($item['date']) ?></div>
          <?php endif; ?>
        </a>
      <?php endforeach; ?>
    </div>
    <p class="lt-slider-more"><a href="<?= htmlspecialcharsbx(lt_blog_url('osnovi-svch-electroniki')) ?>">Все статьи</a></p>
  </div>
</section>

<section class="lt-news" data-lt-slider>
  <div class="lt-wrap">
    <div class="lt-slider-head">
      <h2>Новости</h2>
      <div class="lt-nav-btns">
        <button type="button" data-lt-prev aria-label="Назад">‹</button>
        <button type="button" data-lt-next aria-label="Вперёд">›</button>
      </div>
    </div>
    <div class="lt-track">
      <?php foreach ($news as $item): ?>
        <a class="lt-card lt-card--news" href="<?= htmlspecialcharsbx($item['url']) ?>">
          <?php if (!empty($item['img'])): ?>
            <img src="<?= htmlspecialcharsbx($item['img']) ?>" alt="" loading="lazy">
          <?php endif; ?>
          <div class="lt-card__title"><?= htmlspecialcharsbx($item['title']) ?></div>
          <?php if (!empty($item['date'])): ?>
            <div class="lt-card__date"><?= htmlspecialcharsbx($item['date']) ?></div>
          <?php endif; ?>
        </a>
      <?php endforeach; ?>
    </div>
    <p class="lt-slider-more"><a href="<?= htmlspecialcharsbx(lt_blog_url('pomosch-inzheneram')) ?>">Все новости</a></p>
  </div>
</section>

<?php require __DIR__ . '/include/footer.php'; ?>
<?php require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/footer.php'); ?>
