<section class="project-form-shell">
  <div class="admin-header">
    <h1><%= template ? 'Edit Template' : 'New Template' %></h1>
    <a class="button button-secondary" href="/admin/crm/templates">Back to templates</a>
  </div>

  <form method="POST" action="<%= template ? '/admin/crm/templates/' + template.id + '?_method=PUT' : '/admin/crm/templates' %>">
    <div class="form-section">
      <label>
        Name
        <input type="text" name="name" value="<%= template ? template.name : '' %>" required placeholder="e.g. Diplomatic - National Day Events">
      </label>
      <label>
        Category <span class="hint">(optional, for grouping in the picker)</span>
        <input type="text" name="category" value="<%= template && template.category ? template.category : '' %>" placeholder="e.g. Diplomatic, NGO / Beyta">
      </label>
      <label>
        Subject
        <input type="text" name="subject" value="<%= template ? template.subject : '' %>" required placeholder="e.g. ZUCE Group - Event &amp; Production Partner for {{companyName}}">
      </label>
      <label>
        Body <span class="hint">Placeholders: {{companyName}}, {{contactName}}, {{email}}, {{sector}}, {{region}}</span>
        <textarea name="body" rows="14" required><%= template ? template.body : '' %></textarea>
      </label>
    </div>
    <button type="submit" class="button button-primary">Save Template</button>
    <% if (template) { %>
      <form action="/admin/crm/templates/<%= template.id %>?_method=DELETE" method="POST" style="display:inline"
            onsubmit="return confirm('Delete this template?')">
        <button type="submit" class="button-ghost">Delete</button>
      </form>
    <% } %>
  </form>
</section>
