{% extends "base.html" %}
{% block title %}Czyszczenie /etc/hosts - /etc/hosts Manager{% endblock %}
{% block extra_css %}
  {{ super() }}
  <style>
    .section {
      margin-bottom: 2rem;
    }
    .tooltip-inner {
      max-width: 300px;
      text-align: left;
    }
  </style>
{% endblock %}
{% block content %}
<div class="section">
  <div class="card">
    <div class="card-header">
      <h2>Grupowe czyszczenie /etc/hosts</h2>
    </div>
    <div class="card-body">
      <form method="POST" action="{{ url_for('clear_all_server') }}">
        <div class="mb-3">
          <label class="form-label">Wybierz typy hostów do czyszczenia:</label>
          <div class="form-check">
            <input class="form-check-input" type="checkbox" name="linux" id="linux_group">
            <label class="form-check-label" for="linux_group">Wyczyść Linux</label>
          </div>
          <div class="form-check">
            <input class="form-check-input" type="checkbox" name="mikrotik" id="mikrotik_group">
            <label class="form-check-label" for="mikrotik_group">Wyczyść Mikrotik</label>
          </div>
        </div>
        <button type="submit" class="btn btn-danger">Wyczyść dla wszystkich hostów</button>
      </form>
    </div>
  </div>
</div>

<div class="section">
  <div class="card">
    <div class="card-header">
      <h2>Czyszczenie pojedynczego serwera</h2>
    </div>
    <div class="card-body">
      <form id="clear-single-form" method="POST">
        <div class="mb-3">
          <label for="host_id" class="form-label">Wybierz serwer:</label>
          <select class="form-select" id="host_id" name="host_id">
            {% for host in hosts %}
              <option value="{{ host.id }}">{{ host.hostname }}</option>
            {% endfor %}
          </select>
        </div>
        <button type="submit" class="btn btn-warning">Czyszczenie pojedynczego serwera</button>
      </form>
    </div>
  </div>
</div>
{% endblock %}
{% block extra_js %}
  {{ super() }}
  <script>
    // Ustaw dynamicznie action formularza dla czyszczenia pojedynczego serwera
    document.getElementById('clear-single-form').addEventListener('submit', function(e) {
      e.preventDefault();
      var hostId = document.getElementById('host_id').value;
      if(!hostId) {
        alert("Proszę wybrać serwer!");
        return;
      }
      // Skonstruuj URL bez użycia url_for
      this.action = "/clear-single-server/" + hostId;
      this.submit();
    });
  </script>
{% endblock %}