# Add More Sites

<div id="addons-container">
<p style="color:var(--color-text-secondary)">Loading...</p>
</div>

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

  var container = document.getElementById('addons-container');

  function getApiUrl() {
    return auth._apiUrl || 'https://api.sitemd.cc';
  }

  function startCheckout(product) {
    return Promise.resolve(auth.getUser()).then(function(user) {
      return fetch(getApiUrl() + '/checkout/session', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer ' + auth.getToken(),
        },
        body: JSON.stringify({ product: product, email: (user || {}).email }),
      });
    })
      .then(function(r) { return r.json(); })
      .then(function(data) {
        if (!data.url) throw new Error(data.error || 'Could not start checkout');
        window.open(data.url, '_blank');
      });
  }

  auth.getLicenses().then(function(data) {
    var licenses = data.licenses || [];
    if (licenses.length === 0) {
      location.href = '/upgrade';
      return;
    }

    var html = '';
    html += '<div class="auth-section">';
    html += '<h1>Add More Sites</h1>';
    html += '<p style="color:var(--color-text-secondary)">One-time purchase — no subscription, no lock-in. Each slot activates one site permanently.</p>';
    html += '</div>';

    html += '<div class="auth-section" style="display:flex;gap:var(--space-lg);flex-wrap:wrap">';

    // Add-On Site card
    html += '<div class="auth-card" style="flex:1;min-width:220px">';
    html += '<h2 style="margin-top:0">Add-On Site</h2>';
    html += '<p style="font-size:var(--font-xl);font-weight:700;margin:var(--space-sm) 0">$19 <span style="font-size:var(--font-base);font-weight:400;color:var(--color-text-secondary)">one-time</span></p>';
    html += '<p style="color:var(--color-text-secondary);font-size:var(--font-sm)">1 additional site slot. Deploy one more site.</p>';
    html += '<button class="auth-btn auth-btn--accent" id="buy-addon" style="margin-top:var(--space-md);width:100%">Buy Add-On Site</button>';
    html += '</div>';

    // Bulk Pack card
    html += '<div class="auth-card" style="flex:1;min-width:220px">';
    html += '<h2 style="margin-top:0">Bulk Site Pack</h2>';
    html += '<p style="font-size:var(--font-xl);font-weight:700;margin:var(--space-sm) 0">$16.15<span style="font-size:var(--font-base);font-weight:400;color:var(--color-text-secondary)">/slot</span></p>';
    html += '<p style="color:var(--color-text-secondary);font-size:var(--font-sm)">Minimum 50 slots. 15% off vs. single-site price. Quantity adjustable at checkout.</p>';
    html += '<button class="auth-btn auth-btn--accent" id="buy-bulk" style="margin-top:var(--space-md);width:100%">Buy Bulk Pack</button>';
    html += '</div>';

    html += '</div>';

    html += '<p style="margin-top:var(--space-lg)"><a href="/account">\u2190 Back to Account</a></p>';

    container.innerHTML = html;

    document.getElementById('buy-addon').addEventListener('click', function() {
      var btn = this;
      btn.disabled = true;
      btn.textContent = 'Redirecting to checkout\u2026';
      startCheckout('addon').catch(function(e) {
        alert(e.message || 'Could not start checkout');
        btn.disabled = false;
        btn.textContent = 'Buy Add-On Site';
      });
    });

    document.getElementById('buy-bulk').addEventListener('click', function() {
      var btn = this;
      btn.disabled = true;
      btn.textContent = 'Redirecting to checkout\u2026';
      startCheckout('bulk').catch(function(e) {
        alert(e.message || 'Could not start checkout');
        btn.disabled = false;
        btn.textContent = 'Buy Bulk Pack';
      });
    });

  }).catch(function() {
    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>