{% extends 'base.html' %}
{% load static %}

{% block title %}Dashboard - {{ project_name }}{% endblock %}

{% block content %}
<div class="container-fluid">
    <h1 class="mt-4">Dashboard</h1>
    <p>Overview of application vulnerabilities.</p>

    <div class="row">
        <div class="col-lg-3 col-md-6 mb-4">
            <div class="card text-white bg-primary">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <div class="fs-4 fw-bold">{{ total_applications }}</div>
                            <div>Total Applications</div>
                        </div>
                        <i class="bi bi-box-fill fs-1"></i>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-6 mb-4">
            <div class="card text-white bg-warning">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <div class="fs-4 fw-bold">{{ total_vulnerabilities }}</div>
                            <div>Total Vulnerabilities</div>
                        </div>
                        <i class="bi bi-bug-fill fs-1"></i>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-6 mb-4">
            <div class="card text-white bg-danger">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <div class="fs-4 fw-bold">{{ critical_vulnerabilities }}</div>
                            <div>Critical Vulnerabilities</div>
                        </div>
                        <i class="bi bi-exclamation-octagon-fill fs-1"></i>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-6 mb-4">
            <div class="card text-white bg-info">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <div class="fs-4 fw-bold">{{ new_vulnerabilities }}</div>
                            <div>New Vulnerabilities</div>
                        </div>
                        <i class="bi bi-patch-plus-fill fs-1"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="card mb-4">
        <div class="card-header">
            <i class="bi bi-search me-2"></i>
            Vulnerability Search
        </div>
        <div class="card-body">
            <form action="{% url 'vulnerability_search' %}" method="get">
                <div class="input-group">
                    <input type="text" class="form-control" name="application_name" placeholder="Enter application name...">
                    <button class="btn btn-primary" type="submit">Search</button>
                </div>
            </form>
        </div>
    </div>

    <div class="card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <div>
                <i class="bi bi-box-seam me-2"></i>
                Application Inventory
            </div>
            <a href="{% url 'upload_inventory' %}" class="btn btn-primary">Upload Inventory</a>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Version</th>
                            <th>Vendor</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for app in applications %}
                        <tr>
                            <td>{{ app.name }}</td>
                            <td>{{ app.version }}</td>
                            <td>{{ app.vendor }}</td>
                            <td>
                                <button class="btn btn-sm btn-primary">Details</button>
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="4" class="text-center">No applications found.</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</div>
{% endblock %}
