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

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

{% block admin_content %}
  <header class="flex justify-between items-center mb-8">
    <h1 class="text-2xl">{{ user.email }}</h1>
    <a href="{{ url_for('admin.users') }}" class="btn-outline btn-sm">&larr; Users</a>
  </header>

  <div class="grid-2 mb-8">
    <!-- 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-slate">ID</dt>
          <dd class="mono">{{ user.id }}</dd>
        </div>
        <div class="flex justify-between">
          <dt class="text-slate">Email</dt>
          <dd>{{ user.email }}</dd>
        </div>
        <div class="flex justify-between">
          <dt class="text-slate">Name</dt>
          <dd>{{ user.name or '-' }}</dd>
        </div>
        <div class="flex justify-between">
          <dt class="text-slate">Created</dt>
          <dd class="mono">{{ user.created_at }}</dd>
        </div>
        <div class="flex justify-between">
          <dt class="text-slate">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-slate">Plan</dt>
          <dd>
            {% if user.plan %}
            <span class="badge">{{ user.plan }}</span>
            {% else %}
            <span class="text-slate">free</span>
            {% endif %}
          </dd>
        </div>
        <div class="flex justify-between">
          <dt class="text-slate">Status</dt>
          <dd>{{ user.sub_status or 'N/A' }}</dd>
        </div>
        {% if user.provider_customer_id %}
        <div class="flex justify-between">
          <dt class="text-slate">Paddle Customer</dt>
          <dd class="mono">{{ user.provider_customer_id }}</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 %}
