<?php
declare(strict_types=1);
require __DIR__ . '/../../layouts/header.php';

$page_title = trans('public_proceedings');
?>

<?php
$title = trans('public_proceedings');
$subtitle = current_lang()==='ar' ? 'الوقائع المنشورة حسب المجلدات والأعداد.' : 'Published proceedings by volumes and issues.';
$actions = [];
require __DIR__ . '/../../partials/page_header.php';

$kpis = [
  ['label'=>trans('conference_list'),'value'=>count($conferences ?? []),'icon'=>'fa-solid fa-calendar-days','tone'=>'primary'],
  ['label'=>trans('volume'),'value'=>count($volumes ?? []),'icon'=>'fa-solid fa-book-open','tone'=>'info'],
];
require __DIR__ . '/../../partials/kpi_chips.php';
?>

<div class="ec-card mb-3">
  <div class="ec-card-bd">
    <form method="get" action="<?= e(base_path('proceedings')) ?>" class="row g-3">
      <div class="col-md-9">
        <label class="form-label"><?= e(trans('conference')) ?></label>
        <select name="conference_id" class="form-select">
          <option value="0">--</option>
          <?php foreach (($conferences ?? []) as $c): if (empty($c['is_active'])) continue; ?>
            <option value="<?= e((string)$c['id']) ?>" <?= ((int)($conference_id ?? 0)===(int)$c['id']) ? 'selected' : '' ?>>
              <?= e(current_lang()==='ar' ? (string)($c['title_ar'] ?? '') : (string)($c['title_en'] ?? '')) ?>
            </option>
          <?php endforeach; ?>
        </select>
      </div>
      <div class="col-md-3 d-grid align-items-end">
        <button class="btn btn-primary ec-btn"><i class="fa-solid fa-magnifying-glass me-2"></i><?= e(trans('search')) ?></button>
      </div>
    </form>
  </div>
</div>

<?php if ((int)($conference_id ?? 0) > 0): ?>
  <div class="row g-4">
    <?php foreach (($volumes ?? []) as $v): ?>
      <div class="col-md-6 col-lg-4">
        <div class="ec-card h-100">
          <div class="ec-card-bd">
            <div class="badge-soft mb-2">
              <i class="fa-solid fa-book-open me-2"></i><?= e(trans('volume')) ?> <?= e((string)$v['volume_no']) ?>
            </div>
            <div class="fw-bold mb-1">
              <?= e(current_lang()==='ar' ? (string)($v['title_ar'] ?? '') : (string)($v['title_en'] ?? '')) ?>
            </div>
            <div class="text-muted small mb-3">
              <?= e((string)($v['year'] ?? '')) ?>
              <?= !empty($v['isbn']) ? ' • ISBN: '.e((string)$v['isbn']) : '' ?>
            </div>
            <a class="btn btn-outline-primary ec-btn" href="<?= e(base_path('proceedings/volume?volume_id='.(int)$v['id'])) ?>">
              <i class="fa-solid fa-eye me-2"></i><?= e(trans('view')) ?>
            </a>
          </div>
        </div>
      </div>
    <?php endforeach; ?>

    <?php if (empty($volumes ?? [])): ?>
      <div class="col-12">
        <?php
          $title = trans('no_data');
          $desc = current_lang()==='ar' ? 'لا توجد مجلدات منشورة لهذا المؤتمر.' : 'No published volumes for this conference.';
          $cta_label = '';
          $cta_href = '';
          $icon = 'fa-solid fa-circle-info';
          require __DIR__ . '/../../partials/empty_state.php';
        ?>
      </div>
    <?php endif; ?>
  </div>
<?php else: ?>
  <?php
    $title = current_lang()==='ar' ? 'اختر مؤتمرًا' : 'Select a conference';
    $desc = current_lang()==='ar' ? 'اختر المؤتمر من القائمة لعرض المجلدات المنشورة.' : 'Choose a conference from the list to view published volumes.';
    $cta_label = '';
    $cta_href = '';
    $icon = 'fa-solid fa-hand-pointer';
    require __DIR__ . '/../../partials/empty_state.php';
  ?>
<?php endif; ?>

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