{% extends 'layouts/base.html' %}
{% load i18n %}

{% block title %}{% trans "Standards Compliance Dashboard" %}{% endblock %}

{% block content %}
<div class="container-fluid px-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-0">{% trans "Standards Compliance Dashboard" %}</h1>
            <p class="text-muted mb-0">{{ hospital.name }}</p>
        </div>
        <div>
            <a href="{% url 'standards:search' %}" class="btn btn-primary">
                <i class="fas fa-search me-2"></i>{% trans "Search Standards" %}
            </a>
        </div>
    </div>

    <!-- Statistics Cards -->
    <div class="row mb-4">
        <div class="col-md-2 mb-3">
            <div class="card bg-info text-white h-100">
                <div class="card-body">
                    <h6 class="card-title">{% trans "Total Standards" %}</h6>
                    <h2 class="mb-0">{{ stats.total_standards }}</h2>
                </div>
            </div>
        </div>
        <div class="col-md-2 mb-3">
            <div class="card bg-success text-white h-100">
                <div class="card-body">
                    <h6 class="card-title">{% trans "Met" %}</h6>
                    <h2 class="mb-0">{{ stats.met }}</h2>
                </div>
            </div>
        </div>
        <div class="col-md-2 mb-3">
            <div class="card bg-warning text-dark h-100">
                <div class="card-body">
                    <h6 class="card-title">{% trans "Partially Met" %}</h6>
                    <h2 class="mb-0">{{ stats.partially_met }}</h2>
                </div>
            </div>
        </div>
        <div class="col-md-2 mb-3">
            <div class="card bg-danger text-white h-100">
                <div class="card-body">
                    <h6 class="card-title">{% trans "Not Met" %}</h6>
                    <h2 class="mb-0">{{ stats.not_met }}</h2>
                </div>
            </div>
        </div>
        <div class="col-md-2 mb-3">
            <div class="card bg-secondary text-white h-100">
                <div class="card-body">
                    <h6 class="card-title">{% trans "Not Assessed" %}</h6>
                    <h2 class="mb-0">{{ stats.not_assessed }}</h2>
                </div>
            </div>
        </div>
        <div class="col-md-2 mb-3">
            <div class="card bg-primary text-white h-100">
                <div class="card-body">
                    <h6 class="card-title">{% trans "Departments" %}</h6>
                    <h2 class="mb-0">{{ stats.total_departments }}</h2>
                </div>
            </div>
        </div>
    </div>

    <!-- Departments List -->
    <div class="card mb-4">
        <div class="card-header">
            <h5 class="card-title mb-0">{% trans "Departments" %}</h5>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>{% trans "Department" %}</th>
                            <th>{% trans "Status" %}</th>
                            <th>{% trans "Actions" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for department in departments %}
                        <tr>
                            <td>{{ department.name }}</td>
                            <td>
                                <span class="badge bg-info">
                                    <i class="fas fa-folder-open me-1"></i>
                                    {% trans "View Standards" %}
                                </span>
                            </td>
                            <td>
                                <a href="{% url 'standards:department_standards' pk=department.id %}"
                                   class="btn btn-sm btn-primary">
                                    <i class="fas fa-list me-1"></i>{% trans "View" %}
                                </a>
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="3" class="text-center text-muted">
                                {% trans "No departments found" %}
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- Recent Updates -->
    <div class="card">
        <div class="card-header">
            <h5 class="card-title mb-0">{% trans "Recent Compliance Updates" %}</h5>
        </div>
        <div class="card-body">
            {% if recent_updates %}
            <div class="table-responsive">
                <table class="table table-sm">
                    <thead>
                        <tr>
                            <th>{% trans "Standard" %}</th>
                            <th>{% trans "Department" %}</th>
                            <th>{% trans "Status" %}</th>
                            <th>{% trans "Last Updated" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for update in recent_updates %}
                        <tr>
                            <td>{{ update.standard.code }}</td>
                            <td>{{ update.department.name }}</td>
                            <td>
                                <span class="badge {% if update.status == 'met' %}bg-success{% elif update.status == 'partially_met' %}bg-warning{% elif update.status == 'not_met' %}bg-danger{% else %}bg-secondary{% endif %}">
                                    {{ update.get_status_display }}
                                </span>
                            </td>
                            <td>{{ update.updated_at|date:"Y-m-d H:i" }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% else %}
            <p class="text-muted text-center">{% trans "No recent updates" %}</p>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
