<?php require __DIR__ . '/../../layouts/header.php'; ?>

<div class="container-fluid py-3">
  <div class="d-flex align-items-center justify-content-between flex-wrap gap-2 mb-3">
    <h4 class="mb-0"><?= e(t('schedule') ?? 'Schedule') ?></h4>

    <div class="d-flex gap-2">
      <form method="get" action="<?= e(base_path('admin/schedule')) ?>" class="d-flex gap-2">
        <select name="conference_id" class="form-select" onchange="this.form.submit()">
          <?php foreach(($confs??[]) as $c): ?>
            <option value="<?= (int)$c['id'] ?>" <?= ((int)$confId===(int)$c['id'])?'selected':'' ?>>
              <?= e(($c['title_ar']??'') ?: ($c['title_en']??('Conference #'.$c['id']))) ?>
            </option>
          <?php endforeach; ?>
        </select>
      </form>

      <a class="btn btn-outline-primary" href="<?= e(base_path('admin/sessions?conference_id='.(int)$confId)) ?>">
        <i class="fa fa-cog"></i> <?= e(t('manage_sessions') ?? 'Manage Sessions') ?>
      </a>
    </div>
  </div>

  <?php if(empty($timeline)): ?>
    <div class="alert alert-light border">—</div>
  <?php else: ?>
    <?php foreach($timeline as $day=>$items): ?>
      <div class="card border-0 shadow-sm mb-3">
        <div class="card-header bg-white">
          <div class="fw-semibold"><?= e($day) ?></div>
        </div>
        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
              <thead>
                <tr>
                  <th><?= e(t('time') ?? 'Time') ?></th>
                  <th><?= e(t('title') ?? 'Title') ?></th>
                  <th><?= e(t('type') ?? 'Type') ?></th>
                  <th><?= e(t('room') ?? 'Room') ?></th>
                </tr>
              </thead>
              <tbody>
                <?php foreach($items as $s): ?>
                  <tr>
                    <td class="text-nowrap"><?= e((string)$s['start_time']) ?> - <?= e((string)$s['end_time']) ?></td>
                    <td>
                      <div class="fw-semibold"><?= e((string)$s['title_en']) ?></div>
                      <?php if(!empty($s['title_ar'])): ?><div class="text-muted small"><?= e((string)$s['title_ar']) ?></div><?php endif; ?>
                    </td>
                    <td><?= e((string)$s['session_type']) ?></td>
                    <td><?= e((string)($s['room_name'] ?? '')) ?></td>
                  </tr>
                <?php endforeach; ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    <?php endforeach; ?>
  <?php endif; ?>
</div>

<?php require __DIR__ . '/../../layouts/footer.php'; ?>
