<?php
/**
 * ITSWEBER CMS – Page Builder Admin Form: Tournament (Nexus Theme)
 *
 * @var array $data    Decoded JSON content
 * @var array $section DB row
 */
$sectionId = (int) $section['id'];
$items = $data['items'] ?? [];
$statuses = ['open' => 'Offen', 'full' => 'Ausgebucht', 'live' => 'Live', 'completed' => 'Abgeschlossen'];
?>

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

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

<?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:#ff00ff;">
    Events (bis zu 8)
</h5>

<?php for ($i = 0; $i < 8; $i++):
    $item = $items[$i] ?? ['title' => '', 'detail' => '', 'game' => '', 'date' => '', 'prize' => '', 'status' => '', 'status_label' => '', 'url' => ''];
    $num = $i + 1;
?>
<details style="margin-bottom:0.75rem;border:1px solid var(--color-border, #e2e8f0);border-radius:6px;padding:0;">
    <summary style="padding:0.75rem 1rem;cursor:pointer;font-weight:600;font-size:0.875rem;color:var(--gray-700, #374151);">
        Event <?= $num ?><?= !empty($item['title']) ? ': ' . e($item['title']) : '' ?>
    </summary>
    <div style="padding:0.5rem 1rem 1rem;display:grid;grid-template-columns:1fr 1fr;gap:0.5rem 1rem;">
        <div class="form-group" style="margin:0;">
            <label class="form-label">Titel</label>
            <input type="text" name="event_title[]" class="form-control" value="<?= e($item['title']) ?>" placeholder="z.B. Nexus Championship 2026">
        </div>
        <div class="form-group" style="margin:0;">
            <label class="form-label">Game (Badge)</label>
            <input type="text" name="event_game[]" class="form-control" value="<?= e($item['game']) ?>" placeholder="z.B. Valorant">
        </div>
        <div class="form-group" style="margin:0;grid-column:span 2;">
            <label class="form-label">Details</label>
            <input type="text" name="event_detail[]" class="form-control" value="<?= e($item['detail']) ?>" placeholder="z.B. 5v5 – Double Elimination – 32 Teams">
        </div>
        <div class="form-group" style="margin:0;">
            <label class="form-label">Datum</label>
            <input type="text" name="event_date[]" class="form-control" value="<?= e($item['date']) ?>" placeholder="z.B. 15. Mai 2026">
        </div>
        <div class="form-group" style="margin:0;">
            <label class="form-label">Preisgeld</label>
            <input type="text" name="event_prize[]" class="form-control" value="<?= e($item['prize']) ?>" placeholder="z.B. 2.500 EUR">
        </div>
        <div class="form-group" style="margin:0;">
            <label class="form-label">Status</label>
            <select name="event_status[]" class="form-control">
                <option value="">– kein Status –</option>
                <?php foreach ($statuses as $val => $lbl): ?>
                <option value="<?= $val ?>"<?= ($item['status'] ?? '') === $val ? ' selected' : '' ?>><?= $lbl ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <div class="form-group" style="margin:0;">
            <label class="form-label">Status-Label</label>
            <input type="text" name="event_status_label[]" class="form-control" value="<?= e($item['status_label']) ?>" placeholder="z.B. Anmeldung offen">
        </div>
        <div class="form-group" style="margin:0;grid-column:span 2;">
            <label class="form-label">Link-URL</label>
            <input type="text" name="event_url[]" class="form-control" value="<?= e($item['url']) ?>" placeholder="/turniere/championship-2026">
        </div>
    </div>
</details>
<?php endfor; ?>

<?php admin_field('select', 'color_scheme', __('admin.section.color_scheme'), $data['color_scheme'] ?? '', [
    'options' => ['' => 'Standard', 'alt' => 'Alternativ', 'primary' => 'Primaer', 'dark' => 'Dunkel', 'none' => 'Transparent'],
]) ?>
