<?php require __DIR__ . '/../../layouts/header.php'; $lang=current_lang(); ?>
<?php $r = $row ?? []; ?>
<div class="container">
  <h4 class="mb-3"><i class="fa-solid fa-pen-to-square me-2"></i><?= e($lang==='ar'?'تعديل قالب':'Edit Template') ?></h4>

  <div class="card border-0 shadow-sm">
    <div class="card-body">
      <form method="post" action="<?= e(base_path('admin/email-templates/save')) ?>" class="row g-3">
        <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
        <input type="hidden" name="id" value="<?= e((string)($r['id'] ?? '0')) ?>">

        <div class="col-md-6">
          <label class="form-label">template_key</label>
          <input class="form-control" name="template_key" value="<?= e((string)($r['template_key'] ?? '')) ?>" required>
        </div>
        <div class="col-md-3">
          <label class="form-label"><?= e($lang==='ar'?'نشط':'Active') ?></label>
          <select class="form-select" name="is_active">
            <option value="1" <?= ((int)($r['is_active'] ?? 1)===1?'selected':'') ?>>ON</option>
            <option value="0" <?= ((int)($r['is_active'] ?? 1)===0?'selected':'') ?>>OFF</option>
          </select>
        </div>

        <div class="col-md-6">
          <label class="form-label">Subject EN</label>
          <input class="form-control" name="subject_en" value="<?= e((string)($r['subject_en'] ?? '')) ?>" required>
        </div>
        <div class="col-md-6">
          <label class="form-label">Subject AR</label>
          <input class="form-control" name="subject_ar" value="<?= e((string)($r['subject_ar'] ?? '')) ?>" required>
        </div>

        <div class="col-md-6">
          <label class="form-label">Body EN (HTML allowed)</label>
          <textarea class="form-control" name="body_en" rows="9"><?= e((string)($r['body_en'] ?? '')) ?></textarea>
        </div>
        <div class="col-md-6">
          <label class="form-label">Body AR (HTML allowed)</label>
          <textarea class="form-control" name="body_ar" rows="9"><?= e((string)($r['body_ar'] ?? '')) ?></textarea>
        </div>

        <div class="col-12 d-flex gap-2">
          <button class="btn btn-primary btn-rounded"><i class="fa-solid fa-save me-2"></i><?= e($lang==='ar'?'حفظ':'Save') ?></button>
          <a class="btn btn-outline-secondary btn-rounded" href="<?= e(base_path('admin/email-templates')) ?>"><?= e($lang==='ar'?'رجوع':'Back') ?></a>
        </div>

        <div class="col-12">
          <div class="text-muted small">
            Placeholders: <code>{{paper_id}}</code>, <code>{{title_en}}</code>, <code>{{title_ar}}</code>, <code>{{status}}</code>, <code>{{decision}}</code>, <code>{{chair_comments}}</code>, <code>{{author_email}}</code>, <code>{{file_name}}</code>, <code>{{category}}</code>
          </div>
        </div>

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