<section class="project-form-shell">
  <div class="admin-header">
    <h1>Review Draft</h1>
    <a class="button button-secondary" href="/admin/crm/drafts">Back to queue</a>
  </div>

  <div class="form-section">
    <h3 class="form-section-title">To</h3>
    <p class="hint">
      <a href="/admin/crm/<%= prospect.id %>/edit"><%= prospect.companyName %></a>
      &middot; <%= prospect.email || 'No email on file' %>
      &middot; <span class="tag"><%= draft.direction %></span>
      <% if (draft.generatedBy === 'ai') { %><span class="tag">AI-generated - review carefully</span><% } %>
    </p>
  </div>

  <% if (!prospect.email) { %>
    <div class="flash flash-error">This prospect has no email address on file. Add one on their prospect page before this can be approved.</div>
  <% } %>

  <% if (draft.status === 'approved') { %>
    <div class="flash flash-success">Approved - queued to send from Outlook. It'll go out next time the sync script runs (outlook-sync/send-approved-drafts.ps1), using your real Outlook signature.</div>
  <% } %>

  <form method="POST" action="/admin/crm/drafts/<%= draft.id %>/send">
    <div class="form-section">
      <label>
        Subject
        <input type="text" name="subject" value="<%= draft.subject %>" <%= draft.status !== 'pending_review' ? 'readonly' : '' %> required>
      </label>
      <label>
        Body <span class="hint">(edit freely before approving - your Outlook signature is added automatically when it sends, don't retype it here)</span>
        <textarea name="body" rows="14" <%= draft.status !== 'pending_review' ? 'readonly' : '' %> required><%= draft.body %></textarea>
      </label>
    </div>

    <% if (draft.status === 'pending_review') { %>
      <button type="submit" class="button button-primary" <%= !prospect.email ? 'disabled' : '' %>>Approve to send via Outlook</button>
    <% } else { %>
      <p class="hint">This draft is <%= draft.status %><% if (draft.reviewedBy) { %> by <%= draft.reviewedBy %><% } %>. It can no longer be edited<% if (draft.status === 'pending_review') { %> or approved<% } %>.</p>
    <% } %>
  </form>

  <% if (draft.status === 'pending_review') { %>
    <form method="POST" action="/admin/crm/drafts/<%= draft.id %>/reject" style="margin-top: 0.75rem;"
          onsubmit="return confirm('Reject this draft? It will not be sent.')">
      <button type="submit" class="button-ghost">Reject</button>
    </form>
  <% } %>
</section>
