<?php
/**
 * ITSWEBER CMS – Page Builder Admin Form: Code Showcase (Terminal Theme)
 *
 * @var array $data    Decoded JSON content
 * @var array $section DB row
 */
$sectionId = (int) $section['id'];
$tabs = $data['tabs'] ?? [];
$languages = ['css', 'php', 'json', 'js', 'html', 'sql', 'bash', 'python'];
?>

<div style="background:linear-gradient(135deg,#0d1117 0%,#161b22 100%);border-radius:8px;padding:0.625rem 1rem;margin-bottom:1.25rem;display:flex;align-items:center;gap:0.5rem;">
    <span style="color:#10b981;font-size:0.75rem;font-weight:700;text-transform:uppercase;letter-spacing:0.08em;">★ Terminal Theme – Code Showcase</span>
</div>

<?php admin_field('text', 'title', __('admin.section.title'), $data['title'] ?? '', [
    'placeholder' => 'z.B. Code Example',
]) ?>

<?php admin_field('text', 'subtitle', __('admin.section.subtitle'), $data['subtitle'] ?? '', [
    'placeholder' => 'Optionale Beschreibung',
    'hint' => __('admin.section.optional'),
]) ?>

<h5 style="margin:1.5rem 0 1rem;font-size:.85rem;text-transform:uppercase;letter-spacing:.06em;color:#10b981;">
    Tabs (bis zu 5)
</h5>

<?php for ($i = 0; $i < 5; $i++):
    $tab = $tabs[$i] ?? ['filename' => '', 'language' => '', 'code' => ''];
    $tabLabel = (string) ($tab['label'] ?? $tab['filename'] ?? '');
    $num = $i + 1;
?>
<details style="margin-bottom:0.75rem;border:1px solid var(--color-border, #e2e8f0);border-radius:6px;padding:0;"<?= $i === 0 && $tabLabel !== '' ? ' open' : '' ?>>
    <summary style="padding:0.75rem 1rem;cursor:pointer;font-weight:600;font-size:0.875rem;color:var(--gray-700, #374151);">
        Tab <?= $num ?><?= $tabLabel !== '' ? ': ' . e($tabLabel) : '' ?>
    </summary>
    <div style="padding:0.5rem 1rem 1rem;">
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:0.5rem 1rem;margin-bottom:0.75rem;">
            <div class="form-group" style="margin:0;">
                <label class="form-label">Dateiname</label>
                <input type="text" name="tab_filename[]" class="form-control" value="<?= e($tabLabel) ?>" placeholder="z.B. style.css">
            </div>
            <div class="form-group" style="margin:0;">
                <label class="form-label">Sprache</label>
                <select name="tab_language[]" class="form-control">
                    <option value="">– waehlen –</option>
                    <?php foreach ($languages as $lang): ?>
                    <option value="<?= $lang ?>"<?= ($tab['language'] ?? '') === $lang ? ' selected' : '' ?>><?= strtoupper($lang) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
        <div class="form-group" style="margin:0;">
            <label class="form-label">Code</label>
            <textarea name="tab_code[]" class="form-control" rows="8" style="font-family:Consolas,'Courier New',monospace;font-size:0.8125rem;" placeholder="Code hier einfuegen..."><?= e($tab['code']) ?></textarea>
        </div>
    </div>
</details>
<?php endfor; ?>

<?php admin_section_separator() ?>

<?php admin_field_grid_open(2) ?>
    <?php admin_color_scheme_field($data['color_scheme'] ?? '') ?>
    <?php render_section_text_color_field($data) ?>
<?php admin_field_grid_close() ?>
