<?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="/easychair/admin/email-templates/update" 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'; ?>

<?php /* PACK847_PLACEHOLDERS */ ?>

<hr>

<div
class="card"
style="
border-radius:24px;
padding:28px;
background:
linear-gradient(
135deg,
#f8fbff,
#ffffff
);
"
>

<h3>
Available Placeholders
</h3>

<div class="row">

<?php

$groups=[

'Submission'=>[
'{{submission_id}}',
'{{submission_no}}',
'{{paper_id}}',
'{{title_en}}',
'{{title_ar}}',
'{{abstract}}',
'{{keywords}}',
'{{category}}',
'{{track}}',
'{{topic}}',
'{{file_name}}',
'{{submission_link}}',
'{{camera_ready_link}}',
'{{uploaded_at}}'
],

'Workflow'=>[
'{{status}}',
'{{decision}}',
'{{decision_date}}',
'{{round_no}}',
'{{revision_due}}',
'{{due_date}}',
'{{chair_comments}}',
'{{review_comments}}',
'{{review_link}}'
],

'Author'=>[
'{{author_name}}',
'{{author_first_name}}',
'{{author_last_name}}',
'{{author_email}}',
'{{author_phone}}',
'{{author_affiliation}}',
'{{coauthors}}'
],

'Reviewer'=>[
'{{reviewer_name}}',
'{{reviewer_email}}',
'{{reviewer_username}}',
'{{reviewer_password}}',
'{{review_deadline}}',
'{{review_score}}',
'{{review_url}}'
],

'Conference'=>[
'{{conference_id}}',
'{{conference_title}}',
'{{conference_short_name}}',
'{{conference_slug}}',
'{{conference_url}}',
'{{conference_email}}',
'{{conference_start}}',
'{{conference_end}}'
],

'Organization'=>[
'{{org_name}}',
'{{org_email}}',
'{{org_phone}}',
'{{org_url}}'
],

'System'=>[
'{{portal_url}}',
'{{login_url}}',
'{{support_email}}',
'{{current_date}}',
'{{current_time}}'
]

];

?>

<?php foreach($groups as $title=>$items): ?>

<div class="col-md-6 mb-4">

<div
style="
padding:18px;
border:1px solid #eee;
border-radius:18px;
"
>

<h5>

<?=e($title)?>

</h5>

<?php foreach($items as $p): ?>

<button
type="button"
class="btn btn-sm btn-light mb-2"

onclick="copyPH(this)"

data-v="<?=e($p)?>"
>

<?=e($p)?>

</button>

<?php endforeach; ?>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

<script>

function copyPH(el){

const v=
el.dataset.v;

navigator
.clipboard
.writeText(v);

if(
window.toast
){
toast(
'Copied: '+v
);
}

}

</script>

