{% extends "base.html" %}

{% block title %}Servers • Keywarden{% endblock %}

{% block content %}
  <div class="space-y-8">

    {% if servers %}
      <div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
        {% for item in servers %}
          <article class="group relative overflow-hidden rounded-2xl border border-gray-200 bg-white p-5 shadow-sm transition hover:-translate-y-0.5 hover:shadow-md">
            <div class="flex items-start justify-between">
              <div class="flex items-center gap-3">
                <div class="flex h-10 w-10 items-center justify-center rounded-lg bg-purple-600 text-white font-semibold">
                  {{ item.server.initial }}
                </div>
                <div>
                  <h2 class="text-lg font-semibold text-gray-900">{{ item.server.display_name }}</h2>
                  <p class="text-xs text-gray-500">
                    {{ item.server.hostname|default:item.server.ipv4|default:item.server.ipv6|default:"Unassigned" }}
                  </p>
                </div>
              </div>
              <span class="inline-flex items-center rounded-full bg-emerald-50 px-2.5 py-1 text-xs font-semibold text-emerald-700">Active</span>
            </div>

            <dl class="mt-4 space-y-2 text-sm text-gray-600">
              <div class="flex items-center justify-between">
                <dt>Access until</dt>
                <dd class="font-medium text-gray-900">
                  {% if item.expires_at %}
                    {{ item.expires_at|date:"M j, Y H:i" }}
                  {% else %}
                    No expiry
                  {% endif %}
                </dd>
              </div>
              <div class="flex items-center justify-between">
                <dt>Last accessed</dt>
                <dd class="font-medium text-gray-900">
                  {% if item.last_accessed %}
                    {{ item.last_accessed|date:"M j, Y H:i" }}
                  {% else %}
                    —
                  {% endif %}
                </dd>
              </div>
            </dl>

            <div class="mt-4 border-t border-gray-100 pt-3 text-xs text-gray-500">
              <a href="{% url 'servers:detail' item.server.id %}" class="font-semibold text-purple-700 hover:text-purple-800">View details and logs</a>
            </div>
          </article>
        {% endfor %}
      </div>
    {% else %}
      <div class="rounded-xl border border-dashed border-gray-300 bg-white p-10 text-center">
        <h2 class="text-lg font-semibold text-gray-900">No server access yet</h2>
        <p class="mt-2 text-sm text-gray-600">Request access to a server to see it here.</p>
      </div>
    {% endif %}
  </div>
{% endblock %}
