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

{% block title %}Journey Templates - 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-diagram-2 text-primary me-2"></i>
                Journey Templates
            </h2>
            <p class="text-muted mb-0">Manage journey templates and stages</p>
        </div>
    </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 "Name" %}</th>
                            <th>{% trans "Journey Type" %}</th>
                            <th>{% trans "Hospital" %}</th>
                            <th>{% trans "Stages" %}</th>
                            <th>{% trans "Status" %}</th>
                            <th>{% trans "Actions" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for template in templates %}
                        <tr>
                            <td><strong>{{ template.name }}</strong></td>
                            <td><span class="badge bg-primary">{{ template.get_journey_type_display }}</span></td>
                            <td><small>{{ template.hospital.name_en }}</small></td>
                            <td><span class="badge bg-info">{{ template.stages.count }} stages</span></td>
                            <td>
                                {% if template.is_active %}
                                <span class="badge bg-success">Active</span>
                                {% else %}
                                <span class="badge bg-secondary">Inactive</span>
                                {% endif %}
                            </td>
                            <td>
                                <a href="{% url 'journeys:instance_list' %}?journey_type={{ template.journey_type }}" 
                                   class="btn btn-sm btn-outline-primary">
                                    View Instances
                                </a>
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="6" class="text-center py-5">
                                <i class="bi bi-inbox" style="font-size: 3rem; color: #ccc;"></i>
                                <p class="text-muted mt-3">No templates found</p>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    {% if page_obj.has_other_pages %}
    <nav aria-label="Templates pagination" class="mt-4">
        <ul class="pagination justify-content-center">
            {% if page_obj.has_previous %}
            <li class="page-item">
                <a class="page-link" href="?page={{ page_obj.previous_page_number }}">
                    <i class="bi bi-chevron-left"></i>
                </a>
            </li>
            {% endif %}
            
            {% for num in page_obj.paginator.page_range %}
                {% if page_obj.number == num %}
                <li class="page-item active"><span class="page-link">{{ num }}</span></li>
                {% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
                <li class="page-item">
                    <a class="page-link" href="?page={{ num }}">{{ num }}</a>
                </li>
                {% endif %}
            {% endfor %}
            
            {% if page_obj.has_next %}
            <li class="page-item">
                <a class="page-link" href="?page={{ page_obj.next_page_number }}">
                    <i class="bi bi-chevron-right"></i>
                </a>
            </li>
            {% endif %}
        </ul>
    </nav>
    {% endif %}
</div>
{% endblock %}
