<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Backups</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background: #f1f1f1;
      margin: 0;
      padding: 0;
    }
    .container {
      max-width: 800px;
      margin: 40px auto;
      background: #fff;
      padding: 20px;
      border-radius: 8px;
      box-shadow: 0 0 10px #ccc;
    }
    h1 {
      text-align: center;
    }

    .backup-all-container {
      text-align: center;
      margin-bottom: 20px;
    }
    .backup-all-btn {
      display: inline-block;
      padding: 15px 25px;
      background-color: #28a745;
      color: #fff;
      text-align: center;
      text-decoration: none;
      font-size: 1.2em;
      border-radius: 4px;
      max-width: 90%;
    }
    .backup-all-btn:hover {
      background-color: #218838;
    }

    table {
      width: 100%;
      border-collapse: collapse;
    }
    th, td {
      padding: 8px 12px;
      border: 1px solid #ddd;
    }
    th {
      background: #f4f4f4;
    }

    .btn-sm {
      display: inline-block;
      padding: 4px 8px; 
      font-size: 0.85em; 
      text-decoration: none;
      border-radius: 4px;
      margin-right: 5px;
      color: #fff; 
      border: none;  
      cursor: pointer;
    }
    .btn-view {
      background-color: #007bff; 
    }
    .btn-view:hover {
      background-color: #0056b3;
    }

    .btn-restore {
      background-color: #17a2b8; 
    }
    .btn-restore:hover {
      background-color: #138496;
    }

    .btn-delete {
      background-color: #dc3545; 
    }
    .btn-delete:hover {
      background-color: #c82333;
    }

    .links {
      text-align: center;
      margin-top: 10px;
    }
    .links a {
      color: #007bff;
      text-decoration: none;
    }
    .links a:hover {
      text-decoration: underline;
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>Backups</h1>
    
    <div class="backup-all-container">
      <a href="{{ url_for('backup_all') }}" class="backup-all-btn">Backup All Hosts</a>
    </div>
    
    <table>
      <tr>
        <th>ID</th>
        <th>Host</th>
        <th>Created At</th>
        <th>Description</th>
        <th>Actions</th>
      </tr>
      {% for backup in backups %}
      <tr>
        <td>{{ backup.id }}</td>
        <td>{{ backup.host.hostname if backup.host else 'Default Configuration' }}</td>
        <td>{{ backup.created_at }}</td>
        <td>{{ backup.description or '' }}</td>
        <td>
          <!-- View jako przycisk niebieski -->
          <a href="{{ url_for('view_backup', backup_id=backup.id) }}"
             class="btn-sm btn-view">View</a>
          
          <!-- Restore jako przycisk ciemny cyjan -->
          <a href="{{ url_for('restore_backup', backup_id=backup.id) }}"
             class="btn-sm btn-restore">Restore</a>
          
          <!-- Delete jako przycisk czerwony, w formie (method=POST) -->
          <form action="{{ url_for('delete_backup', backup_id=backup.id) }}" method="POST" style="display:inline;">
            <button type="submit"
                    class="btn-sm btn-delete"
                    onclick="return confirm('Delete this backup?')">
              Delete
            </button>
          </form>
        </td>
      </tr>
      {% endfor %}
    </table>
    <div class="links">
      <a href="{{ url_for('dashboard') }}">Back to Dashboard</a>
    </div>
  </div>
</body>
</html>