{% extends 'generic/supervisor_base.html' %}

{% block content %}
    <div class="d-flex flex-wrap justify-content-between align-items-start gap-3 mb-4">
        <div>
            <h2 class="mb-1">{{ object.name }}</h2>
            <p class="text-muted mb-0">
                Supervisor profile and trainee links.
            </p>
        </div>
        <div class="text-md-end">
            <span class="badge bg-info-subtle text-info-emphasis rounded-pill px-3 py-2">
                {{ object.trainee.count }} trainee{{ object.trainee.count|pluralize }}
            </span>
        </div>
    </div>

    <div class="row g-3 mb-4">
        <div class="col-12 col-lg-7">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body">
                    <h5 class="card-title mb-3">Supervisor Details</h5>
                    <dl class="row mb-0">
                        <dt class="col-sm-4 text-muted">Name</dt>
                        <dd class="col-sm-8" id="name">{{ object.name|default:"-" }}</dd>

                        <dt class="col-sm-4 text-muted">Email</dt>
                        <dd class="col-sm-8" id="email">{% if object.email %}<a href="mailto:{{ object.email }}" class="link-body-emphasis">{{ object.email }}</a>{% else %}-{% endif %}</dd>

                        <dt class="col-sm-4 text-muted">User Account</dt>
                        <dd class="col-sm-8" id="user">{{ object.user|default:"-" }}</dd>

                        <dt class="col-sm-4 text-muted">Site</dt>
                        <dd class="col-sm-8" id="site">{{ object.site|default:"-" }}</dd>
                    </dl>
                </div>
            </div>
        </div>

        <div class="col-12 col-lg-5">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body">
                    <h5 class="card-title mb-3">Actions</h5>
                    <div class="d-grid gap-2">
                        <a class="btn btn-outline-primary" href="{% url 'generic:supervisor_overview' pk=object.pk %}">
                            Supervisor Overview
                        </a>
                        {% if request.user.is_superuser or request.user.groups.filter|length %}
                            <a class="btn btn-outline-secondary" href="{% url 'generic:supervisor_edit' pk=object.pk %}">
                                Edit Supervisor
                            </a>
                            <a class="btn btn-outline-danger" href="{% url 'generic:supervisor_delete' pk=object.pk %}">
                                Delete Supervisor
                            </a>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="card border-0 shadow-sm mb-3">
        <div class="card-body">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <h5 class="card-title mb-0">Trainees</h5>
                <span class="text-muted small">{{ object.trainee.count }} linked</span>
            </div>

            {% if request.user == object.user or request.user.is_superuser or request.user.groups.filter|length %}
                <div class="mb-3">
                    <label class="form-label small text-muted">Search to add trainee</label>
                    <input type="search"
                           class="form-control form-control-sm"
                           placeholder="Name, email, username…"
                           hx-get="{% url 'generic:supervisor_trainee_search' object.pk %}"
                           hx-target="#trainee-search-results"
                           hx-trigger="input delay:300ms"
                           name="q">
                </div>
                <div id="trainee-search-results" class="mb-3"></div>
            {% endif %}

            <div id="trainees-list-content">
                {% include 'generic/partials/supervisor_trainees_list.html' with supervisor=object %}
            </div>
        </div>
    </div>
{% endblock %}

{% block css %}
    {{ block.super }}
    <style>
        .trainee-row:not(:last-child) {
            border-bottom: 1px solid var(--bs-border-color);
        }
    </style>
{% endblock %}