import { Router, Response } from 'express';

const router = Router();


router.get('/dynamic', (_req, res) => {
  const now = new Date();
  const timeString = now.toLocaleTimeString();
  const randomValue = Math.floor(Math.random() * 1000);
  // Toggle status based on seconds (even/odd) to guarantee change
  const isNormal = now.getSeconds() % 2 === 0;
  const statusMessage = isNormal
    ? "System Status: NORMAL - Everything is running smoothly."
    : "System Status: WARNING - High load detected on server node!";
  const statusColor = isNormal ? "green" : "red";

  const html = `
    <!DOCTYPE html>
    <html>
    <head>
      <title>Dynamic Test Page</title>
      <style>
        body { font-family: sans-serif; padding: 20px; }
        .time { font-size: 2em; color: #0066cc; }
        .status { font-size: 1.5em; color: ${statusColor}; font-weight: bold; padding: 20px; border: 2px solid ${statusColor}; margin: 20px 0; }
      </style>
    </head>
    <body>
      <h1>Website Monitor Test</h1>
      
      <div class="status">${statusMessage}</div>
      
      <div class="content">
        <p>Current Time: <span class="time">${timeString}</span></p>
        <p>Random Value: <span class="random">${randomValue}</span></p>
        <p>This page content flips every second to simulate a real website change.</p>
        <div style="background: #f0f9ff; padding: 15px; margin-top: 20px; border-left: 4px solid #0066cc;">
          <h3>New Feature Update</h3>
          <p>We have deployed a new importance scoring update!</p>
        </div>
      </div>
    </body>
    </html>
  `;

  res.send(html);
});

// Test endpoint that returns a 404 error for testing incident display
router.get('/error', (_req, res: Response) => {
  res.status(404).send(`
    <!DOCTYPE html>
    <html>
    <head>
      <title>404 Not Found</title>
    </head>
    <body>
      <h1>404 - Page Not Found</h1>
      <p>This page intentionally returns a 404 error for testing.</p>
    </body>
    </html>
  `);
});

export default router;
