<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><%= inquiry.full_name %> — Inquiry</title>
  <style>
    body { margin: 0; font-family: system-ui, sans-serif; background: #f4f4f2; color: #222; }
    .app-header {
      position: sticky; top: 0; z-index: 10;
      display: flex; align-items: center; justify-content: space-between;
      padding: 16px 24px; background: #fff; border-bottom: 1px solid #ddd;
    }
    .app-header .brand { font-size: 1.3rem; font-weight: 700; letter-spacing: 0.02em; }
    .app-main { max-width: 640px; margin: 0 auto; padding: 24px; }
    .detail-card { background: #fff; border: 1px solid #e6e0d8; border-radius: 12px; padding: 1.5rem; }
    .detail-row { margin-bottom: 1rem; }
    .detail-row:last-child { margin-bottom: 0; }
    .detail-label { display: block; font-size: 0.8rem; font-weight: 700; color: #6b625a; margin-bottom: 0.2rem; text-transform: uppercase; letter-spacing: 0.04em; }
    .detail-value { white-space: pre-line; }
    .detail-error { background: #fdeceb; color: #7a281f; border: 1px solid #f3c3bd; border-radius: 8px; padding: 0.75rem 1rem; margin-bottom: 1rem; }
    .detail-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
    .detail-actions button { padding: 0.6em 1.4em; border-radius: 999px; font-size: 0.95rem; cursor: pointer; border: 1px solid #ccc; background: #fff; }
    .btn-approve { border-color: #2f6b3a; color: #2f6b3a; }
    .btn-decline { border-color: #7a281f; color: #7a281f; }
  </style>
</head>
<body>
  <header class="app-header">
    <span class="brand">Weddings</span>
    <form method="POST" action="/admin/logout"><button type="submit">Log out</button></form>
  </header>

  <main class="app-main">
  <p><a href="/admin/inquiries">&larr; Back to inquiries</a></p>
  <h1><%= inquiry.full_name %></h1>

  <% if (typeof error !== 'undefined' && error) { %>
    <p class="detail-error"><%= error %></p>
  <% } %>

  <div class="detail-card">
    <div class="detail-row">
      <span class="detail-label">Status</span>
      <span class="detail-value"><%= inquiry.status %></span>
    </div>
    <div class="detail-row">
      <span class="detail-label">Submitted</span>
      <span class="detail-value"><%= inquiry.created_at.toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric' }) %></span>
    </div>
    <div class="detail-row">
      <span class="detail-label">Phone</span>
      <span class="detail-value"><%= inquiry.phone %></span>
    </div>
    <div class="detail-row">
      <span class="detail-label">Email</span>
      <span class="detail-value"><%= inquiry.email %></span>
    </div>
    <div class="detail-row">
      <span class="detail-label">Event type</span>
      <span class="detail-value"><%= eventTypeLabel %></span>
    </div>
    <div class="detail-row">
      <span class="detail-label">Preferred theme</span>
      <span class="detail-value"><%= preferredThemeLabel || 'No preference' %></span>
    </div>
    <% var accessModeLabels = { open: 'Open event', recognized: 'Recognised guests', closed: 'Private event' }; %>
    <div class="detail-row">
      <span class="detail-label">Requested access mode</span>
      <span class="detail-value"><%= accessModeLabels[inquiry.preferred_access_mode] || 'No preference stated' %></span>
    </div>
    <div class="detail-row">
      <span class="detail-label">Note</span>
      <span class="detail-value"><%= inquiry.note || '' %></span>
    </div>
    <div class="detail-row">
      <span class="detail-label">Source</span>
      <span class="detail-value"><%= inquiry.client_id ? 'Submitted from client account' : 'Anonymous booking' %></span>
    </div>
  </div>

  <% if (inquiry.status === 'new') { %>
    <div class="detail-actions">
      <form method="POST" action="/admin/inquiries/<%= inquiry.id %>/approve"
            onsubmit="return confirm('Approve this inquiry? This creates a draft event and a client-access link that cannot be shown again after this.');">
        <button type="submit" class="btn-approve">Approve inquiry</button>
      </form>
      <form method="POST" action="/admin/inquiries/<%= inquiry.id %>/decline"
            onsubmit="return confirm('Decline this inquiry? This cannot be undone through this page.');">
        <button type="submit" class="btn-decline">Decline inquiry</button>
      </form>
    </div>
  <% } %>

  <% if (inquiry.event_id) { %>
    <!-- input_20 Phase 10D: event_id is only ever set at approval time
         (inquiryModel.approve()'s own transaction), so this is exactly
         "an approved, linked inquiry" — no separate query needed, the
         value is already on this row from the existing SELECT *. -->
    <p style="margin-top:1.5rem;"><a href="/admin/events/<%= inquiry.event_id %>/client-preview">View Client Portal</a></p>
  <% } %>
  </main>
</body>
</html>
