<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Editar Turma</title>
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
  <style>
    body {
      background-color: #8C64ED; /* Fundo roxo padrão do projeto */
      color: white;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
    }
    .container-custom {
      background-color: white;
      color: black;
      border-radius: 20px;
      padding: 20px;
      max-width: 600px;
      width: 100%;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }
    .btn-primary {
      background-color: #8C64ED;
      border-color: #8C64ED;
      color: #fff!important;
      border-radius: 20px;
    }
    .form-control {
      border-radius: 20px;
    }
    .header-container {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 20px;
    }
    .pat2math-header {
      font-size: 1.5em;
      color: #8C64ED;
      font-weight: bold;
      text-align: right;
    }
    .back-button {
      background: none;
      border: 2px solid black;
      color: black;
      border-radius: 50%;
      width: 40px;
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      font-size: 1.5em;
      margin-right: 10px;
    }
    .toast {
      position: fixed;
      top: 20px;
      right: 20px;
      z-index: 1060;
    }
  </style>
</head>
<body>
  <div class="container container-custom">
    <div class="header-container">
      <button class="back-button" onclick="window.location.href='/api/teacher/dashboard'">
        &#x2190;
      </button>
      <div class="pat2math-header"><strong>PAT2MATH</strong></div>
    </div>
    <h1>Editar Turma</h1>
    <form action="/api/teacher/edit-class/<%= classItem._id %>" method="POST">
      <div class="form-group">
        <label for="name">Nome da Turma</label>
        <input type="text" class="form-control" id="name" name="name" value="<%= classItem.name %>" required>
      </div>
      <div class="form-group">
        <label for="problems">IDs dos Problemas (separados por vírgula)</label>
        <input type="text" class="form-control" id="problems" name="problems" value="<%= classItem.problems.join(', ') %>">
      </div>
      <button type="submit" class="btn btn-primary">Salvar Alterações</button>
    </form>
  </div>
  
  <% if (typeof errorMessage !== 'undefined') { %>
    <div class="toast" data-autohide="false">
      <div class="toast-header">
        <strong class="mr-auto text-danger">Erro</strong>
        <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="toast-body">
        <%= errorMessage %>
      </div>
    </div>
  <% } %>
  
  <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
  <script src="https://stackpath.amazonaws.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
  <script>
    $(document).ready(function(){
      $('.toast').toast('show');
    });
  </script>
</body>
</html>
