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

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

if (empty($cards)) return;

$cls = 'service-cards-section';
if ($colorScheme !== '')      $cls .= ' section--scheme-' . e($colorScheme);
$sectionSurface = $data['section_surface'] ?? '';
if ($sectionSurface !== '')   $cls .= ' section--surface-' . e($sectionSurface);
if ($sectionTextColor !== '') $cls .= ' section--text-' . e($sectionTextColor);
$cls .= ' scs--cols-' . e($columns);

$defaultIcon = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="3"/></svg>';
?>
<section class="<?= $cls ?>" id="<?= e($sectionId) ?>">
    <div class="container">
        <?php if ($title !== '' || $subtitle !== '' || $description !== ''): ?>
        <div class="scs-header reveal">
            <?php if ($subtitle !== ''): ?>
            <div class="scs-subtitle"><?= e($subtitle) ?></div>
            <?php endif; ?>
            <?php if ($title !== ''): ?>
            <h2 class="scs-title"><?= e($title) ?></h2>
            <?php endif; ?>
            <?php if ($description !== ''): ?>
            <p class="scs-description"><?= e($description) ?></p>
            <?php endif; ?>
        </div>
        <?php endif; ?>

        <div class="scs-grid">
            <?php foreach ($cards as $card): ?>
            <div class="scs-card reveal">
                <div class="scs-card-visual">
                    <?php
                    $icon = $card['icon'] ?? '';
                    $rendered = ($icon !== '') ? render_icon($icon, 32) : '';
                    echo ($rendered !== '' && $rendered !== e($icon)) ? $rendered : ($icon !== '' ? $icon : $defaultIcon);
                    ?>
                </div>
                <div class="scs-card-body">
                    <h3 class="scs-card-title"><?= e($card['title'] ?? '') ?></h3>
                    <?php if (!empty($card['text'])): ?>
                    <p class="scs-card-text"><?= e($card['text']) ?></p>
                    <?php endif; ?>
                    <?php if (!empty($card['price'])): ?>
                    <div class="scs-card-price"><?= e($card['price']) ?></div>
                    <?php endif; ?>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>
