<?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('homepage') ?? 'Homepage') ?></h4>

    <div class="d-flex gap-2">
      <form method="get" action="<?= e(base_path('action/hp')) ?>" 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/homepage-blocks?conference_id='.(int)$confId)) ?>">
        <i class="fa fa-layer-group"></i> <?= e(t('homepage_blocks') ?? 'Homepage Blocks') ?>
      </a>
    </div>
  </div>

  <?php if(empty($conf)): ?>
    <div class="alert alert-light border">—</div>
  <?php else: ?>
    <div class="card shadow-sm border-0">
      <div class="card-body">
        <form method="post" action="<?= e(base_path('action/hp')) ?>" enctype="multipart/form-data" class="row g-3">
          <input type="hidden" name="conference_id" value="<?= (int)$confId ?>">

          <div class="col-md-6">
            <label class="form-label"><?= e(t('brief_en') ?? 'Brief (EN)') ?></label>
            <textarea name="brief_en" class="form-control" rows="4"><?= e((string)($conf['brief_en'] ?? '')) ?></textarea>
          </div>
          <div class="col-md-6">
            <label class="form-label"><?= e(t('brief_ar') ?? 'Brief (AR)') ?></label>
            <textarea name="brief_ar" class="form-control" rows="4"><?= e((string)($conf['brief_ar'] ?? '')) ?></textarea>
          </div>

          <div class="col-md-6">
            <label class="form-label"><?= e(t('theme_en') ?? 'Theme (EN)') ?></label>
            <textarea name="theme_en" class="form-control" rows="4"><?= e((string)($conf['theme_en'] ?? '')) ?></textarea>
          </div>
          <div class="col-md-6">
            <label class="form-label"><?= e(t('theme_ar') ?? 'Theme (AR)') ?></label>
            <textarea name="theme_ar" class="form-control" rows="4"><?= e((string)($conf['theme_ar'] ?? '')) ?></textarea>
          </div>

          <div class="col-md-6">
            <label class="form-label"><?= e(t('cfp_en') ?? 'Call for Papers (EN)') ?></label>
            <textarea name="cfp_en" class="form-control" rows="6"><?= e((string)($conf['cfp_en'] ?? '')) ?></textarea>
          </div>
          <div class="col-md-6">
            <label class="form-label"><?= e(t('cfp_ar') ?? 'Call for Papers (AR)') ?></label>
            <textarea name="cfp_ar" class="form-control" rows="6"><?= e((string)($conf['cfp_ar'] ?? '')) ?></textarea>
          </div>

          <div class="col-md-4">
            <label class="form-label"><?= e(t('location_en') ?? 'Location (EN)') ?></label>
            <input type="text" name="location_en" class="form-control" value="<?= e((string)($conf['location_en'] ?? '')) ?>">
          </div>
          <div class="col-md-4">
            <label class="form-label"><?= e(t('location_ar') ?? 'Location (AR)') ?></label>
            <input type="text" name="location_ar" class="form-control" value="<?= e((string)($conf['location_ar'] ?? '')) ?>">
          </div>
          <div class="col-md-4">
            <label class="form-label"><?= e(t('website') ?? 'Website') ?></label>
            <input type="url" name="website_url" class="form-control" value="<?= e((string)($conf['website_url'] ?? '')) ?>">
          </div>

          <div class="col-md-4">
            <label class="form-label"><?= e(t('venue_en') ?? 'Venue (EN)') ?></label>
            <input type="text" name="venue_en" class="form-control" value="<?= e((string)($conf['venue_en'] ?? '')) ?>">
          </div>
          <div class="col-md-4">
            <label class="form-label"><?= e(t('venue_ar') ?? 'Venue (AR)') ?></label>
            <input type="text" name="venue_ar" class="form-control" value="<?= e((string)($conf['venue_ar'] ?? '')) ?>">
          </div>

          <div class="col-md-4">
            <label class="form-label"><?= e(t('featured_image') ?? 'Featured Image') ?></label>
            <input type="file" name="featured_image" class="form-control" accept="image/*">
            <?php if(!empty($conf['featured_image'])): ?>
              <div class="small mt-1">
                <a target="_blank" href="<?= e(base_url($conf['featured_image'])) ?>"><?= e(t('view') ?? 'View') ?></a>
              </div>
            <?php endif; ?>
          </div>

          <div class="col-md-4">
            <label class="form-label"><?= e(t('show_on_homepage') ?? 'Show on Homepage') ?></label>
            <select name="show_on_homepage" class="form-select">
              <option value="1" <?= ((int)($conf['show_on_homepage']??1)===1)?'selected':'' ?>><?= e(t('yes') ?? 'Yes') ?></option>
              <option value="0" <?= ((int)($conf['show_on_homepage']??1)===0)?'selected':'' ?>><?= e(t('no') ?? 'No') ?></option>
            </select>
          </div>

          <div class="col-12 d-flex justify-content-end">
            <button class="btn btn-primary">
              <i class="fa fa-save"></i> <?= e(t('save') ?? 'Save') ?>
            </button>
          </div>
        </form>
      </div>
    </div>
  <?php endif; ?>
</div>

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