import { Router } from 'express';

const router = Router();

router.get('/', (req, res) => {
  if (!req.session?.user) {
    return res.redirect('/auth/discord');
  }

  const guildId = typeof req.query.guildId === 'string' ? req.query.guildId : '';

  // TODO: TICKETS: Dashboard-Layout neu aufsetzen (Filter/Status/Live-Ansicht) statt statischem Inline-HTML.
  // TODO: MODULE: Musik-Modul im Dashboard als toggelbares Modul mit Status/Queue-Ansicht abbilden.
  // TODO: AUTOMOD: Konfiguration (Schwellenwerte, Filter, Logging) im Dashboard editierbar machen.
  const sidebar = `
    <aside class="sidebar">
      <div class="brand">Papo Control</div>
      <div class="nav">
        <a class="active" href="#overview" data-target="overview"><span class="icon">#</span> Uebersicht</a>
        <a href="#tickets" data-target="tickets"><span class="icon">#</span> Ticketsystem</a>
        <a href="#automod" data-target="automod" class="automod-link"><span class="icon">🛡️</span> Automod</a>
        <a href="#welcome" data-target="welcome" class="welcome-link"><span class="icon">🎉</span> Willkommensnachrichten</a>
        <a href="#modules" data-target="modules"><span class="icon">#</span> Module</a>
        <a href="#settings" data-target="settings"><span class="icon">#</span> Einstellungen</a>
      </div>
      <div class="muted">Angemeldet als <span id="userInfo"></span></div>
      <button id="logoutBtn" class="logout">Logout</button>
    </aside>
  `;

  if (!guildId) {
    res.send(`
    <!doctype html>
    <html lang="de">
    <head>
      <meta charset="UTF-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Papo Dashboard - Auswahl</title>
      <style>
        :root { --bg:#0f172a; --card:#111827; --text:#e5e7eb; --accent:#22c55e; --muted:#9ca3af; }
