{% extends 'generic/object.html' %}
{% load helpers %}
{% load plugins %}

{% block breadcrumbs %}
    {{ block.super }}
    <li class="breadcrumb-item"><a href="{% url 'plugins:netbox_freeipa:freeipahost_list' %}">FreeIPA Hosts</a></li>
    <li class="breadcrumb-item active">{{ object }}</li>
{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-6">
        <div class="card">
            <h5 class="card-header">Host Information</h5>
            <div class="card-body">
                <table class="table table-hover attr-table">
                    <tr>
                        <th scope="row">FQDN</th>
                        <td>{{ object.fqdn }}</td>
                    </tr>
                    <tr>
                        <th scope="row">Description</th>
                        <td>{{ object.description|placeholder }}</td>
                    </tr>
                    <tr>
                        <th scope="row">IPA UUID</th>
                        <td>{{ object.ipa_uuid|placeholder }}</td>
                    </tr>
                    <tr>
                        <th scope="row">Managed By</th>
                        <td>{{ object.managed_by|placeholder }}</td>
                    </tr>
                    <tr>
                        <th scope="row">Last Synced</th>
                        <td>{{ object.last_synced }}</td>
                    </tr>
                </table>
            </div>
        </div>
        
        <div class="card mt-3">
            <h5 class="card-header">Authentication</h5>
            <div class="card-body">
                <table class="table table-hover attr-table">
                    <tr>
                        <th scope="row">SSH Public Key</th>
                        <td>
                            {% if object.ssh_public_key %}
                                <details>
                                    <summary>View Key</summary>
                                    <pre class="mt-2">{{ object.ssh_public_key }}</pre>
                                </details>
                            {% else %}
                                {{ ''|placeholder }}
                            {% endif %}
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    
    <div class="col-md-6">
        <div class="card">
            <h5 class="card-header">
                DNS Records
                <span class="badge bg-secondary">{{ object.dns_records.count }}</span>
            </h5>
            <div class="card-body">
                {% if object.dns_records.all %}
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Type</th>
                                <th>Value</th>
                                <th>Zone</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for record in object.dns_records.all %}
                            <tr>
                                <td><a href="{% url 'plugins:netbox_freeipa:freeipadnsrecord' pk=record.pk %}">{{ record.record_name }}</a></td>
                                <td><span class="badge bg-info">{{ record.record_type }}</span></td>
                                <td><code>{{ record.record_value }}</code></td>
                                <td><a href="{% url 'plugins:netbox_freeipa:freeipadnszone' pk=record.dns_zone.pk %}">{{ record.dns_zone.zone_name }}</a></td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                {% else %}
                    <p class="text-muted">No DNS records found for this host.</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}
