<?php
/**
 * ITSWEBER CMS – Default Theme: Feature Showcase 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
 */

$title            = $data['title'] ?? '';
$subtitle         = $data['subtitle'] ?? '';
$colorScheme      = $data['color_scheme'] ?? '';
$sectionTextColor = $data['section_text_color'] ?? '';
$columns          = $data['columns'] ?? '3';
$cardStyle        = $data['card_style'] ?? '';
$cards            = (isset($data['cards']) && is_array($data['cards'])) ? $data['cards'] : [];

if (empty($cards)) return;

// Build CSS classes
$cls = 'feature-showcase-section';
if ($colorScheme !== '')      $cls .= ' section--scheme-' . e($colorScheme);
$surface = $data['section_surface'] ?? '';
if ($surface !== '')          $cls .= ' section--surface-' . e($surface);
if ($sectionTextColor !== '') $cls .= ' section--text-' . e($sectionTextColor);
$cls .= ' fss--cols-' . e($columns);
if ($cardStyle !== '')        $cls .= ' fss--card-' . e($cardStyle);

// Default SVG fallback icon
$defaultIcon = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="12" cy="12" r="10"/><path d="M8 12l2 2 4-4"/></svg>';
?>
<section class="<?= $cls ?>" id="<?= e($sectionId) ?>">
    <div class="container">
        <?php if ($title !== '' || $subtitle !== ''): ?>
        <div class="fss-header reveal">
            <?php if ($subtitle !== ''): ?>
            <div class="fss-label"><?= e($subtitle) ?></div>
            <?php endif; ?>
            <?php if ($title !== ''): ?>
            <h2 class="fss-title"><?= e($title) ?></h2>
            <?php endif; ?>
        </div>
        <?php endif; ?>

        <div class="fss-grid">
            <?php foreach ($cards as $card): ?>
            <div class="fss-card reveal">
                <div class="fss-card-icon">
                    <?php
                    $icon = $card['icon'] ?? '';
                    $rendered = ($icon !== '') ? render_icon($icon, 32) : '';
                    echo ($rendered !== '' && $rendered !== e($icon)) ? $rendered : ($icon !== '' ? $icon : $defaultIcon);
                    ?>
                </div>
                <h3 class="fss-card-title"><?= e($card['title'] ?? '') ?></h3>
                <?php if (!empty($card['text'])): ?>
                <p class="fss-card-text"><?= e($card['text']) ?></p>
                <?php endif; ?>
                <?php
                $url = trim($card['url'] ?? '');
                $linkText = trim($card['link_text'] ?? '');
                if ($url !== '' && $linkText !== ''):
                ?>
                <a href="<?= e($url) ?>" class="fss-card-link"><?= e($linkText) ?></a>
                <?php elseif ($url !== ''): ?>
                <a href="<?= e($url) ?>" class="fss-card-link">Mehr erfahren →</a>
                <?php endif; ?>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>
