{% extends "whm/base.html" %}
{% block title %}Imunifyav antivirus{% endblock title %}
{% block content %}
<div class="row justify-content-center my-5">
  <div class="col-12 col-md-8 col-lg-6">
    <div class="card shadow-lg border-0 rounded-4 overflow-hidden">
      
      <div class="card-header bg-gradient text-white text-center py-4" 
           style="background: linear-gradient(135deg, #007bff, #00c6ff);">
        <h4 class="mb-0 fw-bold">ImunifyAV Antivirus</h4>
      </div>

      <div class="card-body text-center py-5">
        <img src="/media/icon/imunifyfav.png" alt="ImunifyAV Logo" 
             class="img-fluid mb-4" style="max-width: 140px;">

        {% if install_available %}
          <div class="d-flex justify-content-center">
            <a href="/3rdparty/imunifyfav/auto_index.php" target="_blank" 
               class="btn btn-outline-primary d-flex align-items-center gap-2 px-4 py-2 rounded-pill shadow-sm hover-glow">
              <img src="/media/icon/imunifyfav.png" width="30" height="30" alt="ImunifyAV">
              <span class="fw-semibold">Access ImunifyAV Dashboard</span>
            </a>
          </div>
        {% else %}
          <div class="alert alert-danger rounded-3 py-3 px-4 mx-auto mt-3" style="max-width: 450px;">
            ImunifyAV is not installed yet.
          </div>
          <div class="form-group mt-3">
            <button id="save" class="btn btn-primary btn-lg rounded-pill px-5 shadow-sm">
              <i class="bi bi-download me-2"></i> Install ImunifyAV
            </button>
          </div>
        {% endif %}

        <div class="form-group d-none">
          {% csrf_token %}
        </div>

        <div id="responseContainer" class="sk-wave my-4" style="display: none;">
          <div class="rect1"></div>
          <div class="rect2"></div>
          <div class="rect3"></div>
          <div class="rect4"></div>
          <div class="rect5"></div>
        </div>

        <div id="alertContainer" class="alert alert-success alert-dismissible fade show mt-3" 
             role="alert" style="display: none;">
          <div id="message"></div>
          <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
      </div>
    </div>
  </div>
</div>

<style>
  .hover-glow:hover {
    box-shadow: 0 0 20px rgba(0, 123, 255, 0.3);
    transform: translateY(-2px);
    transition: all 0.2s ease-in-out;
  }
</style>


<script>
document.getElementById('save').addEventListener('click', function(event) {
    event.preventDefault();
    install_soft();
});

function install_soft() {
    const responseDisplay = document.getElementById('responseContainer');
    const alertContainer = document.getElementById('alertContainer');
    const messageDisplay = document.getElementById('message');
    const csrfToken = document.querySelector('input[name="csrfmiddlewaretoken"]').value;

    responseDisplay.style.display = 'inline-block';

    fetch("{% url 'install_imunifyfav' %}", {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'X-CSRFToken': csrfToken
        },
        body: new URLSearchParams({ 'domain': "ok" }),
    })
    .then(response => response.json())
    .then(data => {
        responseDisplay.style.display = 'none';
        if (data.status === 'success') {
            alertContainer.className = "alert alert-success alert-dismissible fade show";
            messageDisplay.innerText = data.message || "Installation completed successfully.";
        } else {
            alertContainer.className = "alert alert-danger alert-dismissible fade show";
            messageDisplay.innerText = data.message || "Installation failed.";
        }
        alertContainer.style.display = "block";
        setTimeout(() => location.reload(), 3000);
    })
    .catch(error => {
        console.error(error);
        responseDisplay.style.display = 'none';
        alertContainer.className = "alert alert-danger alert-dismissible fade show";
        messageDisplay.innerText = "imunifyfav installation failed.";
        alertContainer.style.display = "block";
    });
}
</script>


{% include "whm/footer.html" %}
{% endblock content %}
