{% extends "base.html" %}
{% block title %}Moje urządzenia - RouterOS Update{% endblock %}
{% block content %}
<h2>Moje urządzenia</h2>
<button type="button" class="btn btn-success mb-3" onclick="window.location.href='{{ url_for('add_device') }}'">Dodaj nowe urządzenie</button>
<table class="table table-bordered table-hover">
  <thead class="table-dark">
    <tr>
      <th>Nazwa / Adres IP</th>
      <th>Ostatnie sprawdzenie</th>
      <th>Status</th>
      <th>System / Firmware</th>
      <th>Akcje</th>
    </tr>
  </thead>
  <tbody>
    {% for device in devices %}
    <tr>
      <td>
        {% if device.name %}
          {{ device.name }} | 
          <code><small class="text-muted">{{ device.ip }}</small></code>
        {% else %}
          {{ device.ip }}
        {% endif %}
      </td>
      <td>{{ device.last_check.strftime('%Y-%m-%d %H:%M:%S') if device.last_check else 'Brak' }}</td>
      <td>
        {% if device.update_required %}
          <span class="badge bg-danger">Wymaga aktualizacji</span>
        {% else %}
          <span class="badge bg-success">Aktualny</span>
        {% endif %}
      </td>
      <td>
        <small>
          <strong>System:</strong> {{ device.current_version or 'Brak' }}<br>
          <strong>Firmware:</strong> {{ device.current_firmware or 'Brak' }}
        </small>
      </td>
      <td>
        <button type="button" class="btn btn-info btn-sm" onclick="window.location.href='{{ url_for('device_detail', device_id=device.id) }}'">Szczegóły</button>
        <button type="button" class="btn btn-secondary btn-sm" onclick="window.location.href='{{ url_for('force_check', device_id=device.id) }}'">Wymuś sprawdzenie</button>
        <button type="button" class="btn btn-warning btn-sm" onclick="window.location.href='{{ url_for('edit_device', device_id=device.id) }}'">Edytuj</button>
      </td>
    </tr>
    {% else %}
    <tr>
      <td colspan="5" class="text-center">Brak dodanych urządzeń.</td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% endblock %}