{% extends 'base.html' %}
{% block title %}Credential Slip{% endblock %}

{% block content %}
<div class="mx-auto max-w-3xl space-y-4">
  <div class="flex items-center justify-between">
    <h1 class="text-2xl font-bold">Credential Slip</h1>
    <a href="{% url 'accounts:user_list' %}" class="btn btn-ghost btn-sm">Back to Users</a>
  </div>

  <div class="card border border-base-300 bg-base-100">
    <div class="card-body space-y-3">
      <h2 class="card-title text-base">{{ user_obj.get_full_name|default:user_obj.username }}</h2>
      <div class="grid grid-cols-1 gap-3 rounded-box border border-base-300 p-4 sm:grid-cols-2">
        <div>
          <div class="text-xs opacity-70">Username</div>
          <div class="font-mono font-semibold">{{ user_obj.username }}</div>
        </div>
        <div>
          <div class="text-xs opacity-70">Role</div>
          <div>{{ user_obj.get_role_display }}</div>
        </div>
        <div class="sm:col-span-2">
          <div class="text-xs opacity-70">Temporary Password</div>
          {% if credential %}
            <div class="font-mono font-semibold">{{ credential.temporary_password }}</div>
          {% else %}
            <div class="text-warning">Not available in this session. Reset password to issue a new one.</div>
          {% endif %}
        </div>
      </div>

      <div class="alert alert-warning">
        User is required to change password at first login.
      </div>

      <div class="flex flex-wrap gap-2">
        <button type="button" class="btn btn-outline btn-sm" onclick="window.print()">Print Slip</button>
        {% if credential and user_obj.email %}
          <form method="post">
            {% csrf_token %}
            <input type="hidden" name="action" value="send_email">
            <button type="submit" class="btn btn-primary btn-sm">Send To Email</button>
          </form>
        {% elif not user_obj.email %}
          <span class="text-sm opacity-70">No email on account.</span>
        {% endif %}
        {% if credential %}
          <form method="post">
            {% csrf_token %}
            <input type="hidden" name="action" value="clear">
            <button type="submit" class="btn btn-ghost btn-sm">Mark As Shared</button>
          </form>
        {% endif %}
      </div>
    </div>
  </div>
</div>
{% endblock %}
