{% extends "layouts/base.html" %}
{% load i18n %}
{% load static %}

{% block title %}Routing Rules - PX360{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h2 class="mb-1">
                <i class="bi bi-signpost-split text-info me-2"></i>
                Routing Rules
            </h2>
            <p class="text-muted mb-0">Manage action routing and assignment rules</p>
        </div>
        <a href="{% url 'config:dashboard' %}" class="btn btn-outline-secondary">
            <i class="bi bi-arrow-left me-1"></i> Back to Config
        </a>
    </div>

    <div class="card">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>{% trans "Priority" %}</th>
                            <th>{% trans "Name" %}</th>
                            <th>{% trans "Source Type" %}</th>
                            <th>{% trans "Severity" %}</th>
                            <th>{% trans "Hospital" %}</th>
                            <th>{% trans "Assign To" %}</th>
                            <th>{% trans "Status" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for rule in routing_rules %}
                        <tr>
                            <td><span class="badge bg-primary">{{ rule.priority }}</span></td>
                            <td>
                                <strong>{{ rule.name }}</strong><br>
                                {% if rule.description %}
                                <small class="text-muted">{{ rule.description|truncatewords:10 }}</small>
                                {% endif %}
                            </td>
                            <td>
                                {% if rule.source_type %}
                                <span class="badge bg-info">{{ rule.get_source_type_display }}</span>
                                {% else %}
                                <span class="text-muted">Any</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if rule.severity %}
                                <span class="badge bg-warning">{{ rule.get_severity_display }}</span>
                                {% else %}
                                <span class="text-muted">Any</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if rule.hospital %}
                                <small>{{ rule.hospital.name_en }}</small>
                                {% else %}
                                <span class="badge bg-secondary">All</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if rule.assign_to_user %}
                                <small>{{ rule.assign_to_user.get_full_name }}</small>
                                {% elif rule.assign_to_department %}
                                <small>{{ rule.assign_to_department.name_en }}</small>
                                {% elif rule.assign_to_role %}
                                <small>{{ rule.assign_to_role }}</small>
                                {% else %}
                                <span class="text-muted">-</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if rule.is_active %}
                                <span class="badge bg-success">Active</span>
                                {% else %}
                                <span class="badge bg-secondary">Inactive</span>
                                {% endif %}
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="7" class="text-center py-5">
                                <i class="bi bi-signpost-split" style="font-size: 3rem; color: #ccc;"></i>
                                <p class="text-muted mt-3">No routing rules found</p>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}
