<?php
/**
 * ITSWEBER CMS – Default Theme: Topic Cards 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('topic-cards', $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="topic-cards-grid">
            <?php foreach ($data['items'] as $card): ?>
            <?php $cardUrl = trim($card['url'] ?? ''); ?>
            <?php if ($cardUrl): ?>
            <a href="<?= e($cardUrl) ?>" class="topic-card reveal">
            <?php else: ?>
            <div class="topic-card topic-card--plain reveal">
            <?php endif; ?>
                <?php if (!empty($card['icon'])): ?>
                <div class="topic-card-icon"><?= render_icon($card['icon'], 32) ?></div>
                <?php endif; ?>
                <h3 class="topic-card-title"><?= e($card['title'] ?? '') ?></h3>
                <?php if (!empty($card['text'])): ?>
                <p class="topic-card-text"><?= e($card['text']) ?></p>
                <?php endif; ?>
                <?php if ($cardUrl): ?>
                <span class="topic-card-link">Learn more →</span>
                <?php endif; ?>
            <?php if ($cardUrl): ?>
            </a>
            <?php else: ?>
            </div>
            <?php endif; ?>
            <?php endforeach; ?>
        </div>
    </div>
</section>
