{% set admin_page = "users" %}
{% extends "admin/base_admin.html" %}

{% block title %}User: {{ user.email }} - {{ config.APP_NAME }} Admin{% endblock %}
{% block topbar_title %}User Detail{% endblock %}

{% block admin_content %}
  <div style="margin-bottom:16px;">
    <a href="{{ url_for('admin.users') }}" class="text-sm">&larr; Back to Users</a>
    <h2 class="text-xl mt-1">{{ user.email }}</h2>
  </div>

  <div class="grid-2 mb-6">
    <!-- User Info -->
    <div class="card">
      <h3 class="text-lg mb-4">User Info</h3>
      <dl class="space-y-3 text-sm">
        <div class="flex justify-between">
          <dt class="text-stone">ID</dt>
          <dd class="mono">{{ user.id }}</dd>
        </div>
        <div class="flex justify-between">
          <dt class="text-stone">Email</dt>
          <dd>{{ user.email }}</dd>
        </div>
        <div class="flex justify-between">
          <dt class="text-stone">Name</dt>
          <dd>{{ user.name or '-' }}</dd>
        </div>
        <div class="flex justify-between">
          <dt class="text-stone">Created</dt>
          <dd class="mono">{{ user.created_at }}</dd>
        </div>
        <div class="flex justify-between">
          <dt class="text-stone">Last Login</dt>
          <dd class="mono">{{ user.last_login_at or 'Never' }}</dd>
        </div>
      </dl>
    </div>

    <!-- Subscription -->
    <div class="card">
      <h3 class="text-lg mb-4">Subscription</h3>
      <dl class="space-y-3 text-sm">
        <div class="flex justify-between">
          <dt class="text-stone">Plan</dt>
          <dd>
            {% if user.plan %}
            <span class="badge">{{ user.plan }}</span>
            {% else %}
            <span class="text-stone">free</span>
            {% endif %}
          </dd>
        </div>
        <div class="flex justify-between">
          <dt class="text-stone">Status</dt>
          <dd>{{ user.sub_status or 'N/A' }}</dd>
        </div>
        {% if user.stripe_customer_id %}
        <div class="flex justify-between">
          <dt class="text-stone">Paddle Customer</dt>
          <dd class="mono">
            <a href="https://vendors.paddle.com/customers/{{ user.stripe_customer_id }}" target="_blank">
              {{ user.stripe_customer_id }}
            </a>
          </dd>
        </div>
        {% endif %}
      </dl>
    </div>
  </div>

  <!-- Actions -->
  <div class="card">
    <h3 class="text-lg mb-4">Actions</h3>
    <form method="post" action="{{ url_for('admin.impersonate', user_id=user.id) }}">
      <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
      <button type="submit" class="btn-secondary">Impersonate User</button>
    </form>
  </div>
{% endblock %}
