{% extends 'base.html' %}
{% load static %}

{% block title %}Staff Details - {{ admin.get_full_name }}{% endblock %}

{% block content %}
<div class="space-y-6">
    <!-- Header -->
    <div class="bg-white shadow rounded-lg">
        <div class="px-4 py-5 sm:p-6">
            <div class="flex justify-between items-center">
                <div>
                    <h3 class="text-lg leading-6 font-medium text-gray-900">
                        <span>🛡️</span>
                        Staff Details
                    </h3>
                    <p class="mt-1 max-w-2xl text-sm text-gray-500">
                        Detailed information for {{ admin.get_full_name }}
                    </p>
                </div>
                <div class="flex space-x-3">
                    <a href="{% url 'users:admin_update' admin.id %}" class="inline-flex items-center px-4 py-2 border border-yellow-300 text-sm font-medium rounded-md shadow-sm text-yellow-700 bg-yellow-50 hover:bg-yellow-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-yellow-500">
                        <span>✏️</span>
                        Edit
                    </a>
                    <a href="{% url 'users:user_permissions' admin.id %}" class="inline-flex items-center px-4 py-2 border border-blue-300 text-sm font-medium rounded-md shadow-sm text-blue-700 bg-blue-50 hover:bg-blue-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
                        <i class="fas fa-shield-alt mr-2"></i>
                        Permissions
                    </a>
                    {% if admin.status == 'suspended' %}
                        <a href="{% url 'users:admin_confirm_reactivate' admin.id %}" class="inline-flex items-center px-4 py-2 border border-green-300 text-sm font-medium rounded-md shadow-sm text-green-700 bg-green-50 hover:bg-green-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500">
                            <i class="fas fa-user-check mr-2"></i>
                            Reactivate
                        </a>
                    {% else %}
                        <a href="{% url 'users:admin_confirm_delete' admin.id %}" class="inline-flex items-center px-4 py-2 border border-red-300 text-sm font-medium rounded-md shadow-sm text-red-700 bg-red-50 hover:bg-red-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500">
                            <i class="fas fa-user-slash mr-2"></i>
                            Suspend
                        </a>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        <!-- Main Information -->
        <div class="lg:col-span-2">
            <div class="bg-white shadow rounded-lg">
                <div class="px-4 py-5 sm:p-6">
                    <div class="flex items-start space-x-6">
                        <!-- Profile Picture -->
                        <div class="flex-shrink-0">
                            {% if admin.selfie %}
                                <img src="{{ admin.selfie.url }}" class="h-32 w-32 rounded-full object-cover">
                            {% else %}
                                <div class="h-32 w-32 rounded-full bg-gray-300 flex items-center justify-center">
                                    <span>👤</span>
                                </div>
                            {% endif %}
                        </div>
                        
                        <!-- User Information -->
                        <div class="flex-1">
                            <h4 class="text-2xl font-bold text-gray-900">{{ admin.get_full_name }}</h4>
                            <p class="text-lg text-gray-600">{{ admin.get_role_display }}</p>
                            
                            <div class="mt-4 flex items-center space-x-4">
                                {% if admin.role == 'admin' %}
                                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-red-100 text-red-800">
                                        <i class="fas fa-crown mr-1"></i>Admin
                                    </span>
                                {% elif admin.role == 'team_leader' %}
                                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-blue-100 text-blue-800">
                                        <span>👔</span>Team Leader
                                    </span>
                                {% elif admin.role == 'loan_officer' %}
                                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-800">
                                        <i class="fas fa-handshake mr-1"></i>Loan Officer
                                    </span>
                                {% elif admin.role == 'secretary' %}
                                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-purple-100 text-purple-800">
                                        <i class="fas fa-user-secret mr-1"></i>Secretary
                                    </span>
                                {% endif %}
                                
                                {% if admin.status == 'active' %}
                                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-800">Active</span>
                                {% elif admin.status == 'suspended' %}
                                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-red-100 text-red-800">Suspended</span>
                                {% elif admin.status == 'dormant' %}
                                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-yellow-100 text-yellow-800">Dormant</span>
                                {% endif %}
                            </div>
                            
                            <!-- Contact Information -->
                            <div class="mt-6 grid grid-cols-1 md:grid-cols-2 gap-4">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700">Username</label>
                                    <p class="mt-1 text-sm text-gray-900">{{ admin.username }}</p>
                                </div>
                                
                                <div>
                                    <label class="block text-sm font-medium text-gray-700">Email</label>
                                    <p class="mt-1 text-sm text-gray-900">{{ admin.email|default:"Not provided" }}</p>
                                </div>
                                
                                <div>
                                    <label class="block text-sm font-medium text-gray-700">Phone Number</label>
                                    <p class="mt-1 text-sm text-gray-900">{{ admin.phone_number }}</p>
                                </div>
                                
                                <div>
                                    <label class="block text-sm font-medium text-gray-700">Date Joined</label>
                                    <p class="mt-1 text-sm text-gray-900">{{ admin.date_joined|date:"F d, Y" }}</p>
                                </div>
                                
                                <div>
                                    <label class="block text-sm font-medium text-gray-700">Last Login</label>
                                    <p class="mt-1 text-sm text-gray-900">
                                        {% if admin.last_login %}
                                            {{ admin.last_login|date:"F d, Y H:i" }}
                                        {% else %}
                                            <span class="text-gray-500">Never logged in</span>
                                        {% endif %}
                                    </p>
                                </div>
                                
                                <div>
                                    <label class="block text-sm font-medium text-gray-700">Account Status</label>
                                    <p class="mt-1">
                                        {% if admin.is_active %}
                                            <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">Active</span>
                                        {% else %}
                                            <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">Inactive</span>
                                        {% endif %}
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
                
        <!-- Sidebar -->
        <div class="lg:col-span-1">
            <!-- Quick Actions -->
            <div class="bg-white shadow rounded-lg mb-6">
                <div class="px-4 py-5 sm:p-6">
                    <h5 class="text-lg font-medium text-gray-900 mb-4">
                        <span>⚡</span>
                        Quick Actions
                    </h5>
                    <div class="space-y-3">
                        <a href="{% url 'users:admin_update' admin.id %}" class="w-full inline-flex items-center justify-center px-4 py-2 border border-yellow-300 text-sm font-medium rounded-md shadow-sm text-yellow-700 bg-yellow-50 hover:bg-yellow-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-yellow-500">
                            <span>✏️</span>
                            Edit Staff
                        </a>
                        
                        <a href="{% url 'users:user_permissions' admin.id %}" class="w-full inline-flex items-center justify-center px-4 py-2 border border-blue-300 text-sm font-medium rounded-md shadow-sm text-blue-700 bg-blue-50 hover:bg-blue-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
                            <i class="fas fa-shield-alt mr-2"></i>
                            Manage Permissions
                        </a>
                        
                        {% if admin.status == 'suspended' %}
                            <a href="{% url 'users:admin_confirm_reactivate' admin.id %}" class="w-full inline-flex items-center justify-center px-4 py-2 border border-green-300 text-sm font-medium rounded-md shadow-sm text-green-700 bg-green-50 hover:bg-green-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500">
                                <i class="fas fa-user-check mr-2"></i>
                                Reactivate Staff
                            </a>
                        {% else %}
                            <a href="{% url 'users:admin_confirm_delete' admin.id %}" class="w-full inline-flex items-center justify-center px-4 py-2 border border-red-300 text-sm font-medium rounded-md shadow-sm text-red-700 bg-red-50 hover:bg-red-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500">
                                <i class="fas fa-user-slash mr-2"></i>
                                Suspend Staff
                            </a>
                        {% endif %}
                        
                        <a href="{% url 'users:admin_list' %}" class="w-full inline-flex items-center justify-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md shadow-sm text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary">
                            <span>←</span>
                            Back to Staff List
                        </a>
                    </div>
                </div>
            </div>
            
            <!-- Account Statistics -->
            <div class="bg-white shadow rounded-lg">
                <div class="px-4 py-5 sm:p-6">
                    <h5 class="text-lg font-medium text-gray-900 mb-4">
                        <span>📊</span>
                        Account Statistics
                    </h5>
                    <div class="grid grid-cols-2 gap-4 text-center">
                        <div class="border rounded-lg p-4">
                            <h4 class="text-primary text-2xl font-bold mb-1">{{ audit_logs.count }}</h4>
                            <p class="text-sm text-gray-500">Actions</p>
                        </div>
                        <div class="border rounded-lg p-4">
                            <h4 class="text-green-600 text-2xl font-bold mb-1">
                                {% if admin.is_active %}Yes{% else %}No{% endif %}
                            </h4>
                            <p class="text-sm text-gray-500">Active</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Recent Activity -->
    <div class="bg-white shadow rounded-lg">
        <div class="px-4 py-5 sm:p-6">
            <h5 class="text-lg font-medium text-gray-900 mb-4">
                <i class="fas fa-history text-primary mr-2"></i>
                Recent Activity
            </h5>
            
            {% if audit_logs %}
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Action</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Description</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">IP Address</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Date</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            {% for log in audit_logs %}
                            <tr class="hover:bg-gray-50">
                                <td class="px-6 py-4 whitespace-nowrap">
                                    {% if log.action == 'login' %}
                                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
                                            <i class="fas fa-sign-in-alt mr-1"></i>Login
                                        </span>
                                    {% elif log.action == 'logout' %}
                                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800">
                                            <i class="fas fa-sign-out-alt mr-1"></i>Logout
                                        </span>
                                    {% elif log.action == 'create' %}
                                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
                                            <span>+</span>Create
                                        </span>
                                    {% elif log.action == 'update' %}
                                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800">
                                            <span>✏️</span>Update
                                        </span>
                                    {% elif log.action == 'delete' %}
                                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">
                                            <span>🗑️</span>Delete
                                        </span>
                                    {% else %}
                                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
                                            {{ log.action|title }}
                                        </span>
                                    {% endif %}
                                </td>
                                <td class="px-6 py-4 text-sm text-gray-900">{{ log.description }}</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ log.ip_address|default:"-" }}</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ log.accessed_at|date:"M d, Y H:i" }}</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            {% else %}
                <div class="text-center py-12">
                    <span>ℹ️</span>
                    <h3 class="text-lg font-medium text-gray-900 mb-2">No recent activity found</h3>
                    <p class="text-gray-500">This user hasn't performed any actions yet.</p>
                </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %} 