<?php
/**
 * ITSWEBER CMS – Default Theme: Stats / Key Figures Section Template
 * Page Builder section template (3.4.0)
 *
 * Displays large numbers/statistics with labels in a row.
 * Ideal for company metrics, achievements, key figures.
 *
 * Variables: $data (array), $section (DB row), $sectionId (string)
 *
 * Data fields:
 *   title, subtitle, color_scheme, section_text_color, section_surface, columns (2-4)
 *   items[] => { value, label, prefix, suffix, icon }
 *
 * @author  Benny Weber
 * @copyright ITSWEBER, www.itsweber.de
 */

$title            = $data['title'] ?? '';
$subtitle         = $data['subtitle'] ?? '';
$columns          = $data['columns'] ?? '4';
$items            = (isset($data['items']) && is_array($data['items'])) ? $data['items'] : [];

if (empty($items)) return;

?>
<section id="<?= e($sectionId) ?>" class="<?= build_section_classes('stats', $data, ['stats--cols-' . $columns]) ?>">
    <div class="container">
        <?php if ($title !== '' || $subtitle !== ''): ?>
        <div class="stats-header reveal">
            <?php if ($title !== ''): ?>
            <h2 class="stats-title"><?= e($title) ?></h2>
            <?php endif; ?>
            <?php if ($subtitle !== ''): ?>
            <p class="stats-subtitle"><?= e($subtitle) ?></p>
            <?php endif; ?>
        </div>
        <?php endif; ?>

        <div class="stats-grid">
            <?php foreach ($items as $item): ?>
            <div class="stats-item reveal">
                <?php if (!empty($item['icon'])): ?>
                <div class="stats-item-icon"><?= render_icon($item['icon'], 28) ?></div>
                <?php endif; ?>
                <div class="stats-item-value">
                    <?php if (!empty($item['prefix'])): ?>
                    <span class="stats-prefix"><?= e($item['prefix']) ?></span>
                    <?php endif; ?>
                    <?= e($item['value'] ?? '0') ?>
                    <?php if (!empty($item['suffix'])): ?>
                    <span class="stats-suffix"><?= e($item['suffix']) ?></span>
                    <?php endif; ?>
                </div>
                <?php if (!empty($item['label'])): ?>
                <div class="stats-item-label"><?= e($item['label']) ?></div>
                <?php endif; ?>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>
