# Dashboard

<div id="dashboard">
<p style="color:var(--color-text-secondary)">Loading your account...</p>
</div>

<script>
(function() {
  function init() {
  var auth = window.__sitemdAuth;
  if (!auth) return;

  var container = document.getElementById('dashboard');

  // Show purchase success banner
  if (/[?&]purchase=success/.test(location.search)) {
    var banner = document.createElement('div');
    banner.style.cssText = 'background:var(--color-accent,#16a34a);color:#fff;padding:var(--space-sm) var(--space-md);border-radius:var(--radius-md,6px);margin-bottom:var(--space-md)';
    banner.textContent = 'Welcome to sitemd! Your license is active. Activate your first site from the CLI.';
    container.parentNode.insertBefore(banner, container);
    history.replaceState(null, '', location.pathname);
  }

  function render(account, licensesData) {
    var licenses = licensesData.licenses || [];
    var html = '';

    // Welcome
    html += '<div class="auth-section">';
    html += '<h1>Welcome back' + (account.name ? ', ' + esc(account.name) : '') + '</h1>';
    html += '<p style="color:var(--color-text-secondary)">' + esc(account.email) + '</p>';
    html += '<div style="margin-top:var(--space-md)">';
    html += '<a href="/account/add-ons" class="auth-btn auth-btn--accent" style="margin-right:var(--space-sm)">Get More Site Slots</a>';
    html += '<a href="/account/purchases" class="auth-btn" style="margin-right:var(--space-sm)">Purchase History</a>';
    html += '<a href="/account/settings" class="auth-btn" style="margin-right:var(--space-sm)">Change Email</a>';
    html += '<button class="auth-btn" id="logout-btn">Log Out</button>';
    html += '</div>';
    html += '</div>';

    // Licenses — consolidated view
    html += '<div class="auth-section">';
    html += '<h2>Site Slots</h2>';
    if (licenses.length === 0) {
      html += '<p style="color:var(--color-text-secondary)">No licenses yet. <a href="/upgrade">Get sitemd Web Deploy</a></p>';
    } else {
      var totalMax = 0;
      var totalUsed = 0;
      for (var i = 0; i < licenses.length; i++) {
        totalMax += licenses[i].max_sites;
        totalUsed += licenses[i].sites_used;
      }
      html += '<div class="auth-card">';
      html += '<p class="auth-card-meta" id="slots-meta">' + totalMax + ' account site slots: ' + totalUsed + ' used, ' + (totalMax - totalUsed) + ' available</p>';
      html += '<div id="all-sites"><p style="color:var(--color-text-secondary);font-size:var(--font-sm)">Loading sites\u2026</p></div>';
      html += '</div>';
    }
    html += '</div>';

    container.innerHTML = html;

    // Logout handler
    var logoutBtn = document.getElementById('logout-btn');
    if (logoutBtn) {
      logoutBtn.addEventListener('click', function() {
        auth.logout().then(function() { location.href = '/'; });
      });
    }

    // Load all site activations
    if (licenses.length > 0) {
      loadAllSites(licenses);
    }
  }

  function formatDate(iso) {
    var d = new Date(iso);
    var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
    return months[d.getMonth()] + ' ' + d.getDate() + ', ' + d.getFullYear();
  }

  function loadAllSites(licenses) {
    var totalMax = 0;
    var totalUsed = 0;
    for (var i = 0; i < licenses.length; i++) {
      totalMax += licenses[i].max_sites;
      totalUsed += licenses[i].sites_used;
    }

    auth.listActivations().then(function(data) {
      var activations = data.activations || [];

      // Update count
      var meta = document.getElementById('slots-meta');
      if (meta) meta.textContent = totalMax + ' account site slots: ' + totalUsed + ' used, ' + (totalMax - totalUsed) + ' available';

      var el = document.getElementById('all-sites');
      if (!el) return;
      if (activations.length === 0) {
        el.innerHTML = '<p style="color:var(--color-text-secondary);font-size:var(--font-sm)">No activated sites yet. Your site will activate the first time you run <code>sitemd deploy</code> or <code>sitemd build</code> from your project.</p>';
        return;
      }
      // Sort by activation date
      activations.sort(function(a, b) { return new Date(a.activated_at) - new Date(b.activated_at); });

      var html = '<div style="overflow-x:auto">';
      html += '<table style="width:100%;border-collapse:collapse;font-size:var(--font-sm)">';
      html += '<thead><tr style="border-bottom:2px solid var(--color-border)">';
      html += '<th style="text-align:left;padding:var(--space-xs) var(--space-sm)">#</th>';
      html += '<th style="text-align:left;padding:var(--space-xs) var(--space-sm)">Site</th>';
      html += '<th style="text-align:left;padding:var(--space-xs) var(--space-sm)">URL</th>';
      html += '<th style="text-align:right;padding:var(--space-xs) var(--space-sm)">Activation Date</th>';
      html += '</tr></thead><tbody>';
      for (var k = 0; k < activations.length; k++) {
        var a = activations[k];
        html += '<tr style="border-bottom:1px solid var(--color-border)">';
        html += '<td style="padding:var(--space-xs) var(--space-sm);color:var(--color-text-secondary)">' + (k + 1) + '</td>';
        html += '<td style="padding:var(--space-xs) var(--space-sm)"><strong>' + esc(a.site_title) + '</strong></td>';
        html += '<td style="padding:var(--space-xs) var(--space-sm)">' + (a.domain ? '<a href="https://' + esc(a.domain) + '" target="_blank">' + esc(a.domain) + '</a>' : '<span style="color:var(--color-text-secondary)">—</span>') + '</td>';
        html += '<td style="text-align:right;padding:var(--space-xs) var(--space-sm)">' + formatDate(a.activated_at) + '</td>';
        html += '</tr>';
      }
      html += '</tbody></table>';
      html += '</div>';
      el.innerHTML = html;
    });
  }

  function esc(s) {
    var d = document.createElement('div');
    d.textContent = s;
    return d.innerHTML;
  }

  // Load data
  Promise.all([auth.getAccount(), auth.getLicenses()]).then(function(results) {
    render(results[0], results[1]);
  }).catch(function(e) {
    container.innerHTML = '<p style="color:#dc2626">Failed to load account data. <a href="/login">Try logging in again</a>.</p>';
  });
  }
  if (window.__sitemdAuth) { window.__sitemdAuth.ready.then(init); }
  else { document.addEventListener('sitemd:auth-ready', init); }
})();
</script>

---

## FAQ

**How many sites do I get?**\n
When you initially purchase sitemd, you get 3 starter site slots. If you need more sites, you can [purchase additional slots individually or in bulk](/add-ons).

**What counts as 1 "site"?**\n
Any set of pages (could be 1, could be 100+) that share the same site title, brand name, and deploy URL. We call this your "site identity" and it's how we verify your site's activation status.\n

Note: subdomains are considered their own unique deploy URL, so if you need to deploy pages to both mydomain.com and sub.mydomain.com, that uses 2 site slots.

**Can I reassign my site slots?**\n
Activating a site is permanent — it cannot be undone, refunded, or credited.

**Do you offer refunds?**\n
No. You can fully preview all sitemd functionality for free for as long as you need before making a purchase decision.

---

### Still have questions?
Email us at support@sitemd.cc