const http = require('http');
const fs = require('fs');
const path = require('path');

const server = http.createServer((req, res) => {
  // Servir arquivos estáticos da pasta public
  if (req.url.startsWith('/') && req.url.includes('.')) {
    const filePath = path.join(__dirname, 'public', req.url);
    const ext = path.extname(filePath).toLowerCase();
    const contentTypes = {
      '.html': 'text/html',
      '.jpg': 'image/jpeg',
      '.jpeg': 'image/jpeg',
      '.png': 'image/png',
      '.gif': 'image/gif',
      '.svg': 'image/svg+xml',
      '.webp': 'image/webp',
      '.ico': 'image/x-icon'
    };
    
    if (fs.existsSync(filePath)) {
      const contentType = contentTypes[ext] || 'application/octet-stream';
      res.writeHead(200, { 
        'Content-Type': contentType,
        'Cache-Control': 'public, max-age=3600',
        'Access-Control-Allow-Origin': '*'
      });
      fs.createReadStream(filePath).pipe(res);
      return;
    }
  }
  
  res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
  res.end(`
<!DOCTYPE html>
<html lang="pt-BR">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>PDIMaker - Plataforma de Desenvolvimento Individual</title>
  <style>
    * { margin: 0; padding: 0; box-sizing: border-box; }
    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
      background-image: url('/pdimaker-background.jpg');
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
      background-attachment: fixed;
      color: white;
      text-align: center;
      padding: 2rem;
      position: relative;
    }
    body::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(0, 0, 0, 0.5);
      z-index: 0;
    }
    .container {
      max-width: 800px;
      position: relative;
      z-index: 1;
    }
    h1 {
      font-size: 4rem;
      margin-bottom: 1rem;
      animation: pulse 2s infinite;
    }
    .subtitle {
      font-size: 1.5rem;
      opacity: 0.9;
      margin-bottom: 2rem;
    }
    .status {
      margin-top: 3rem;
      padding: 2rem;
      background: rgba(255,255,255,0.15);
      border-radius: 15px;
      backdrop-filter: blur(15px);
      box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    }
    .status h2 {
      font-size: 1.5rem;
      margin-bottom: 1rem;
    }
    .status p {
      font-size: 1.1rem;
      opacity: 0.8;
    }
    .features {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
      gap: 1.5rem;
      margin-top: 2rem;
    }
    .feature {
      background: rgba(255,255,255,0.2);
      padding: 1.5rem;
      border-radius: 10px;
      backdrop-filter: blur(10px);
      transition: transform 0.3s ease;
    }
    .feature:hover {
      transform: translateY(-5px);
      background: rgba(255,255,255,0.25);
    }
    .feature h3 {
      font-size: 2rem;
      margin-bottom: 0.5rem;
    }
    @keyframes pulse {
      0%, 100% { transform: scale(1); }
      50% { transform: scale(1.05); }
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>🚀 PDIMaker</h1>
    <p class="subtitle">Plataforma de Desenvolvimento Individual</p>
    
    <div class="status">
      <h2>✨ Sistema em Construção</h2>
      <p>Estamos preparando uma experiência incrível para seu desenvolvimento profissional!</p>
      
      <div class="features">
        <div class="feature">
          <h3>📝</h3>
          <p>Diário de Atividades</p>
        </div>
        <div class="feature">
          <h3>🎯</h3>
          <p>Metas & PDI</p>
        </div>
        <div class="feature">
          <h3>🧪</h3>
          <p>Testes Vocacionais</p>
        </div>
        <div class="feature">
          <h3>👥</h3>
          <p>Reuniões 1:1</p>
        </div>
      </div>
    </div>
    
    <p style="margin-top: 2rem; opacity: 0.6;">
      <small>Versão: 1.0.0-alpha | ${new Date().getFullYear()}</small>
    </p>
  </div>
</body>
</html>
  `);
});

const PORT = 3000;
server.listen(PORT, '0.0.0.0', () => {
  console.log(`✅ PDIMaker Frontend running on port ${PORT}`);
});
