<?php
/**
 * ITSWEBER CMS – Default Theme: Highlight Grid Section Template
 * Page Builder section template (3.2.0)
 *
 * Variables: $data (array), $section (DB row), $sectionId (string)
 *
 * @author  Benny Weber
 * @copyright ITSWEBER, www.itsweber.de
 */

if (empty($data['items'])) return;

$extra = [];
if (!empty($data['card_style'])) $extra[] = 'section--card-' . $data['card_style'];
if (!empty($data['columns']))    $extra[] = 'section--cols-' . $data['columns'];
?>
<section id="<?= e($sectionId) ?>" class="<?= build_section_classes('highlight-grid', $data, $extra) ?>">
    <div class="container">
        <?php if (!empty($data['title'])): ?>
        <h2 class="reveal"><?= e($data['title']) ?></h2>
        <?php endif; ?>
        <?php if (!empty($data['subtitle'])): ?>
        <p class="section-subtitle reveal"><?= e($data['subtitle']) ?></p>
        <?php endif; ?>
        <div class="highlight-grid">
            <?php foreach ($data['items'] as $item): ?>
            <?php $itemUrl = trim($item['url'] ?? ''); ?>
            <?php if ($itemUrl): ?>
            <a href="<?= e($itemUrl) ?>" class="highlight-card reveal">
            <?php else: ?>
            <div class="highlight-card reveal">
            <?php endif; ?>
                <?php if (!empty($item['icon'])): ?>
                <div class="highlight-card-icon"><?= render_icon($item['icon'], 32) ?></div>
                <?php endif; ?>
                <h3 class="highlight-card-title"><?= e($item['title'] ?? '') ?></h3>
                <?php if (!empty($item['text'])): ?>
                <p class="highlight-card-text"><?= e($item['text']) ?></p>
                <?php endif; ?>
                <?php if (!empty($item['source'])): ?>
                <p class="highlight-card-source"><?= e($item['source']) ?></p>
                <?php endif; ?>
                <?php if ($itemUrl): ?>
                <span class="highlight-card-link">Details →</span>
                <?php endif; ?>
            <?php if ($itemUrl): ?>
            </a>
            <?php else: ?>
            </div>
            <?php endif; ?>
            <?php endforeach; ?>
        </div>
    </div>
</section>
