<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Mastermind — Email Accounts</title>
  <style>
    body{font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;margin:0;background:#0b0f14;color:#e8eef7}
    header{background:#111824;border-bottom:1px solid #233043;padding:14px 16px;position:sticky;top:0}
    main{max-width:1100px;margin:0 auto;padding:16px}
    .card{background:#111824;border:1px solid #233043;border-radius:12px;padding:14px;margin:12px 0}
    a{color:#7cc4ff;text-decoration:none}
    .muted{color:#a9b7c6}
    table{width:100%;border-collapse:collapse}
    th,td{border-bottom:1px solid #233043;padding:10px 6px;text-align:left;color:#a9b7c6;font-size:13px;vertical-align:top}
    th{color:#e8eef7}
    button{padding:10px 12px;border-radius:10px;border:1px solid #233043;background:#1c2a3d;color:#e8eef7}
    .pill{display:inline-block;padding:2px 8px;border:1px solid #233043;border-radius:999px;font-size:12px;color:#a9b7c6}
  </style>
</head>
<body>
<header>
  <div style="display:flex;justify-content:space-between;align-items:center;gap:10px">
    <div style="font-weight:700">Email Accounts</div>
    <div style="display:flex;gap:10px">
      <a href="/admin/email-rules">Rules</a>
      <a href="/">Dashboard</a>
      <a href="/logout">Logout</a>
    </div>
  </div>
</header>
<main>
  <div class="card">
    <p class="muted">Connectors are first-class from day 1. They’ll show <b>Not configured</b> until you provide OAuth credentials. Manual .eml upload works now.</p>
  </div>

  <div class="card">
    <h2 style="margin:0 0 8px">Connectors</h2>
    <table>
      <thead>
        <tr>
          <th>Provider</th>
          <th>Enabled</th>
          <th>Configured</th>
          <th>Authorized</th>
          <th>Last sync</th>
          <th>Last error</th>
          <th>Action</th>
        </tr>
      </thead>
      <tbody>
        <% connectors.forEach(c => { %>
          <tr>
            <td><b><%= c.provider %></b></td>
            <td><span class="pill"><%= c.enabled ? 'yes' : 'no' %></span></td>
            <td><span class="pill"><%= c.configured ? 'yes' : 'no' %></span></td>
            <td><span class="pill"><%= c.authorized ? 'yes' : 'no' %></span></td>
            <td><%= c.last_sync_at || '' %></td>
            <td><%= c.last_error || '' %></td>
            <td>
              <form method="post" action="/admin/email-connectors/<%= c.provider %>/toggle">
                <button type="submit"><%= c.enabled ? 'Disable' : 'Enable' %></button>
              </form>
              <div class="muted" style="margin-top:6px">
                <% if (!c.configured) { %>
                  Not configured — add OAuth credentials in <code>.env</code> (we’ll add UI later).
                <% } else if (!c.authorized) { %>
                  Configured — needs OAuth authorization (pending).
                <% } else { %>
                  Connected.
                <% } %>
              </div>
            </td>
          </tr>
        <% }) %>
      </tbody>
    </table>
  </div>

  <div class="card">
    <h2 style="margin:0 0 8px">Manual import</h2>
    <p><a href="/inbox">→ Inbox import + triage</a></p>
  </div>
</main>
</body>
</html>
