{% load helpers %}

<div class="row">
    <div class="col-12">
        {% if error %}
        <div class="alert alert-warning">
            <i class="mdi mdi-alert"></i> {{ error }}
        </div>
        {% elif ise_data %}
        <div class="row">
            <!-- NAD Registration Status Card -->
            <div class="col-md-4 mb-3">
                <div class="card h-100">
                    <div class="card-header">
                        <h5 class="card-title mb-0">
                            <i class="mdi mdi-check-decagram"></i> ISE Registration
                        </h5>
                    </div>
                    <div class="card-body text-center">
                        <div class="p-3 mb-2 bg-success rounded">
                            <span class="text-white fs-3 fw-bold">
                                <i class="mdi mdi-check-circle"></i> Registered
                            </span>
                        </div>
                        {% if ise_data.name %}
                        <div class="mt-2">
                            <span class="text-muted">NAD Name:</span>
                            <strong class="ms-2">{{ ise_data.name }}</strong>
                        </div>
                        {% endif %}
                        {% if ise_data.profile_name %}
                        <div class="mt-1">
                            <span class="text-muted">Profile:</span>
                            <span class="badge bg-info text-dark ms-2">{{ ise_data.profile_name }}</span>
                        </div>
                        {% endif %}
                    </div>
                </div>
            </div>

            <!-- Device Details Card -->
            <div class="col-md-4 mb-3">
                <div class="card h-100">
                    <div class="card-header">
                        <h5 class="card-title mb-0">
                            <i class="mdi mdi-router"></i> Device Details
                        </h5>
                    </div>
                    <div class="card-body">
                        <table class="table table-sm table-borderless mb-0">
                            {% if ise_data.ip_addresses %}
                            <tr>
                                <th class="text-muted" style="width: 40%">IP Address(es):</th>
                                <td>
                                    {% for ip in ise_data.ip_addresses %}
                                    <code>{{ ip }}</code>{% if not forloop.last %}, {% endif %}
                                    {% endfor %}
                                </td>
                            </tr>
                            {% endif %}
                            {% if ise_data.model_name %}
                            <tr>
                                <th class="text-muted">Model:</th>
                                <td>{{ ise_data.model_name }}</td>
                            </tr>
                            {% endif %}
                            {% if ise_data.software_version %}
                            <tr>
                                <th class="text-muted">Software:</th>
                                <td>{{ ise_data.software_version }}</td>
                            </tr>
                            {% endif %}
                            {% if ise_data.description %}
                            <tr>
                                <th class="text-muted">Description:</th>
                                <td>{{ ise_data.description }}</td>
                            </tr>
                            {% endif %}
                            {% if ise_data.coA_port %}
                            <tr>
                                <th class="text-muted">CoA Port:</th>
                                <td>{{ ise_data.coA_port }}</td>
                            </tr>
                            {% endif %}
                        </table>
                    </div>
                </div>
            </div>

            <!-- Authentication Settings Card -->
            <div class="col-md-4 mb-3">
                <div class="card h-100">
                    <div class="card-header">
                        <h5 class="card-title mb-0">
                            <i class="mdi mdi-shield-key"></i> Authentication Settings
                        </h5>
                    </div>
                    <div class="card-body">
                        <table class="table table-sm table-borderless mb-0">
                            <tr>
                                <th class="text-muted" style="width: 50%">RADIUS:</th>
                                <td>
                                    {% if ise_data.authentication_settings.radius_enabled %}
                                    <span class="badge bg-success text-white">Enabled</span>
                                    {% else %}
                                    <span class="badge bg-warning text-dark">Disabled</span>
                                    {% endif %}
                                </td>
                            </tr>
                            <tr>
                                <th class="text-muted">TACACS+:</th>
                                <td>
                                    {% if ise_data.tacacs_settings.enabled %}
                                    <span class="badge bg-success text-white">Enabled</span>
                                    {% else %}
                                    <span class="badge bg-warning text-dark">Disabled</span>
                                    {% endif %}
                                </td>
                            </tr>
                            <tr>
                                <th class="text-muted">TrustSec:</th>
                                <td>
                                    {% if ise_data.trustsec_enabled %}
                                    <span class="badge bg-success text-white">Enabled</span>
                                    {% else %}
                                    <span class="badge bg-warning text-dark">Disabled</span>
                                    {% endif %}
                                </td>
                            </tr>
                            {% if ise_data.snmp_settings.version %}
                            <tr>
                                <th class="text-muted">SNMP:</th>
                                <td>{{ ise_data.snmp_settings.version }}</td>
                            </tr>
                            {% endif %}
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <!-- Network Device Groups -->
        {% if ise_data.groups %}
        <div class="row">
            <div class="col-12 mb-3">
                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title mb-0">
                            <i class="mdi mdi-folder-network"></i> Network Device Groups
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            {% for category, value in ise_data.groups.items %}
                            <div class="col-md-3 col-sm-6 mb-2">
                                <div class="border rounded p-2">
                                    <div class="text-muted small">{{ category }}</div>
                                    <div class="fw-bold">{{ value }}</div>
                                </div>
                            </div>
                            {% endfor %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {% endif %}

        <!-- Cache indicator and external link -->
        <div class="mt-3 d-flex justify-content-between align-items-center">
            <div>
                {% if ise_data.cached %}
                <span class="text-muted small">
                    <i class="mdi mdi-cached"></i> Data from cache
                </span>
                {% endif %}
            </div>
            <div>
                {% if ise_url %}
                <a href="{{ ise_url }}" target="_blank" class="btn btn-outline-primary btn-sm">
                    <i class="mdi mdi-open-in-new"></i> Open Cisco ISE
                </a>
                {% endif %}
            </div>
        </div>

        {% else %}
        <div class="alert alert-info">
            <i class="mdi mdi-information"></i> This device is not registered as a Network Access Device in ISE.
        </div>
        {% endif %}
    </div>
</div>
