<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gmail Accounts — Bulk Mailer</title>
<link rel="stylesheet" href="/static/css/app.css">
<style>
.acc-tbl td{vertical-align:top}
.mono{font-family:ui-monospace,Menlo,Consolas,monospace;font-size:.85em}
.cfg-note{background:#f8f9fc;border:1px solid #e3e8f0;border-radius:10px;padding:14px 16px;font-size:.86rem;color:#475569}
.cfg-note b{color:#1e293b}
</style>
<script src="https://sites.super.myninja.ai/_assets/ninja-daytona-script.js"></script>
</head>
<body>
<div id="layout"></div>
<main id="content">
  <div class="page-head">
    <div>
      <h1>Gmail Accounts</h1>
      <p class="sub">Connect up to <span id="maxAcc">10</span> authenticated Gmail accounts via Google OAuth 2.0. Tokens are encrypted at rest.</p>
    </div>
    <div class="btns">
      <button class="btn" id="btnConnect">Connect Gmail Account</button>
      <button class="btn secondary" id="btnImportCfg">Import Gmail Configuration</button>
      <button class="btn danger-o" id="btnClearAll">Clear All</button>
    </div>
  </div>

  <div id="cfgCard" class="card" style="display:none">
    <div class="card-hd"><h2>Import Google OAuth Client Configuration</h2></div>
    <div class="card-bd">
      <div class="cfg-note">
        Upload the <b>client_secret_*.json</b> file from Google Cloud Console → APIs &amp; Services → Credentials.
        The file is validated, encrypted, and stored locally; the secret is <b>never echoed back</b>.
        Redirect URI for this app: <span class="mono" id="cfgRedirect">/auth/google/callback</span>
      </div>
      <form id="cfgForm" class="form" style="margin-top:14px">
        <input type="file" id="cfgFile" accept=".json,application/json" required>
        <button class="btn" type="submit">Upload &amp; Validate</button>
      </form>
    </div>
  </div>

  <div class="card">
    <div class="card-hd">
      <h2>Connected Accounts <span class="badge b-gray" id="accCount">0</span></h2>
      <input type="text" id="accSearch" class="inp" placeholder="Search accounts…" style="width:220px">
    </div>
    <div class="card-bd" id="accWrap">
      <table class="tbl acc-tbl" id="accTbl">
        <thead><tr>
          <th>Gmail Address</th><th>Status</th><th>Sending Method</th>
          <th>Daily / Campaign Limit</th><th>Today</th><th>Last Success</th>
          <th>Errors</th><th>Actions</th>
        </tr></thead>
        <tbody id="accBody"></tbody>
      </table>
      <div id="accEmpty" class="empty" style="display:none">
        <div class="empty-t">No Gmail accounts connected</div>
        <p>Click <b>Connect Gmail Account</b> to start the Google OAuth 2.0 flow. You must import the OAuth client configuration first.</p>
      </div>
    </div>
  </div>
</main>
<script src="/static/js/app.js"></script>
<script src="/static/js/pages/gmail-accounts.js"></script>
</body>
</html>
