{% extends "base.html" %}

{% block title %}Admin Panel - FINA{% endblock %}

{% block body %}
<div class="flex h-screen w-full">
    <!-- Side Navigation -->
    <aside id="sidebar" class="hidden lg:flex w-64 flex-col bg-sidebar-light dark:bg-background-dark border-r border-border-light dark:border-[#233648] transition-all duration-300 shadow-sm dark:shadow-none">
        <div class="p-6 flex flex-col h-full justify-between">
            <div class="flex flex-col gap-8">
                <!-- User Profile -->
                <div class="flex gap-3 items-center">
                    <img src="{{ current_user.avatar | avatar_url }}" alt="{{ current_user.username }}" class="size-10 rounded-full border-2 border-primary/30 object-cover">
                    <div class="flex flex-col">
                        <h1 class="text-text-main dark:text-white text-base font-bold leading-none">{{ current_user.username }}</h1>
                        <p class="text-text-muted dark:text-[#92adc9] text-xs font-normal mt-1">
                            {% if current_user.is_admin %}<span data-translate="user.admin">Admin</span>{% else %}<span data-translate="user.user">User</span>{% endif %}
                        </p>
                    </div>
                </div>
                
                <!-- Navigation Links -->
                <nav class="flex flex-col gap-2">
                    <a class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors" href="{{ url_for('main.dashboard') }}">
                        <span class="material-symbols-outlined text-[20px]">dashboard</span>
                        <span class="text-sm font-medium" data-translate="nav.dashboard">Dashboard</span>
                    </a>
                    <a class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors" href="{{ url_for('main.transactions') }}">
                        <span class="material-symbols-outlined text-[20px]">receipt_long</span>
                        <span class="text-sm font-medium" data-translate="nav.transactions">Transactions</span>
                    </a>
                    <a class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors" href="{{ url_for('main.reports') }}">
                        <span class="material-symbols-outlined text-[20px]">pie_chart</span>
                        <span class="text-sm font-medium" data-translate="nav.reports">Reports</span>
                    </a>
                    <a class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors" href="{{ url_for('main.documents') }}">
                        <span class="material-symbols-outlined text-[20px]">folder_open</span>
                        <span class="text-sm font-medium" data-translate="nav.documents">Documents</span>
                    </a>
                    {% if current_user.is_admin %}
                    <a class="flex items-center gap-3 px-3 py-2.5 rounded-lg bg-primary/10 text-primary border border-primary/10" href="{{ url_for('main.admin') }}">
                        <span class="material-symbols-outlined text-[20px]">admin_panel_settings</span>
                        <span class="text-sm font-medium" data-translate="nav.admin">Admin</span>
                    </a>
                    {% endif %}
                </nav>
            </div>
            
            <!-- Bottom Links -->
            <div class="flex flex-col gap-2">
                <button id="theme-toggle" class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors">
                    <span class="material-symbols-outlined text-[20px]" id="theme-icon">light_mode</span>
                    <span class="text-sm font-medium" id="theme-text" data-translate="dashboard.lightMode">Light Mode</span>
                </button>
                <a class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors" href="{{ url_for('main.settings') }}">
                    <span class="material-symbols-outlined text-[20px]">settings</span>
                    <span class="text-sm font-medium" data-translate="nav.settings">Settings</span>
                </a>
                <a class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors" href="{{ url_for('auth.logout') }}">
                    <span class="material-symbols-outlined text-[20px]">logout</span>
                    <span class="text-sm font-medium" data-translate="nav.logout">Log out</span>
                </a>
            </div>
        </div>
    </aside>
    
    <!-- Main Content -->
    <main class="flex-1 flex flex-col h-full overflow-hidden relative">
        <!-- Top Header -->
        <header class="h-16 flex items-center justify-between px-6 lg:px-8 border-b border-border-light dark:border-[#233648] bg-white/80 dark:bg-background-dark/95 backdrop-blur z-10 shrink-0 shadow-sm dark:shadow-none">
            <div class="flex items-center gap-4">
                <button id="menu-toggle" class="lg:hidden text-text-main dark:text-white">
                    <span class="material-symbols-outlined">menu</span>
                </button>
                <div>
                    <h2 class="text-text-main dark:text-white text-lg font-bold" data-translate="admin.title">Admin Panel</h2>
                    <p class="text-text-muted dark:text-slate-400 text-xs mt-0.5" data-translate="admin.subtitle">Manage users and system settings</p>
                </div>
            </div>
        </header>

        <!-- Content Area -->
        <div class="flex-1 overflow-y-auto bg-background-light dark:bg-card-dark">
            <div class="container mx-auto px-4 py-6 max-w-7xl">

    <!-- Stats Cards -->
    <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
        <div class="bg-card-light dark:bg-card-dark border border-border-light dark:border-slate-700 rounded-xl p-6">
            <div class="flex items-center justify-between">
                <div>
                    <p class="text-text-muted dark:text-slate-400 text-sm" data-translate="admin.totalUsers">Total Users</p>
                    <p id="total-users" class="text-2xl font-bold text-text-main dark:text-white mt-1">-</p>
                </div>
                <span class="material-symbols-outlined text-primary text-[40px]">group</span>
            </div>
        </div>
        
        <div class="bg-card-light dark:bg-card-dark border border-border-light dark:border-slate-700 rounded-xl p-6">
            <div class="flex items-center justify-between">
                <div>
                    <p class="text-text-muted dark:text-slate-400 text-sm" data-translate="admin.adminUsers">Admin Users</p>
                    <p id="admin-users" class="text-2xl font-bold text-text-main dark:text-white mt-1">-</p>
                </div>
                <span class="material-symbols-outlined text-blue-500 text-[40px]">shield_person</span>
            </div>
        </div>
        
        <div class="bg-card-light dark:bg-card-dark border border-border-light dark:border-slate-700 rounded-xl p-6">
            <div class="flex items-center justify-between">
                <div>
                    <p class="text-text-muted dark:text-slate-400 text-sm" data-translate="admin.twoFAEnabled">2FA Enabled</p>
                    <p id="twofa-users" class="text-2xl font-bold text-text-main dark:text-white mt-1">-</p>
                </div>
                <span class="material-symbols-outlined text-green-500 text-[40px]">verified_user</span>
            </div>
        </div>
    </div>

    <!-- Users Table -->
    <div class="bg-card-light dark:bg-card-dark border border-border-light dark:border-slate-700 rounded-xl overflow-hidden">
        <div class="p-6 border-b border-border-light dark:border-slate-700">
            <div class="flex items-center justify-between">
                <h2 class="text-lg font-semibold text-text-main dark:text-white" data-translate="admin.users">Users</h2>
                <button onclick="openCreateUserModal()" class="bg-primary hover:bg-primary/90 text-white px-4 py-2 rounded-lg text-sm font-medium flex items-center gap-2 transition-colors">
                    <span class="material-symbols-outlined text-[18px]">add</span>
                    <span data-translate="admin.createUser">Create User</span>
                </button>
            </div>
        </div>
        
        <div class="overflow-x-auto">
            <table class="w-full">
                <thead class="bg-background-light dark:bg-slate-800/50">
                    <tr>
                        <th class="px-6 py-3 text-left text-xs font-medium text-text-muted dark:text-slate-400 uppercase tracking-wider" data-translate="admin.username">Username</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-text-muted dark:text-slate-400 uppercase tracking-wider" data-translate="admin.email">Email</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-text-muted dark:text-slate-400 uppercase tracking-wider" data-translate="admin.role">Role</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-text-muted dark:text-slate-400 uppercase tracking-wider" data-translate="admin.twoFA">2FA</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-text-muted dark:text-slate-400 uppercase tracking-wider" data-translate="admin.language">Language</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-text-muted dark:text-slate-400 uppercase tracking-wider" data-translate="admin.currency">Currency</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-text-muted dark:text-slate-400 uppercase tracking-wider" data-translate="admin.joined">Joined</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-text-muted dark:text-slate-400 uppercase tracking-wider" data-translate="admin.actions">Actions</th>
                    </tr>
                </thead>
                <tbody id="users-table" class="divide-y divide-border-light dark:divide-slate-700">
                    <!-- Users will be populated here -->
                </tbody>
            </table>
        </div>
    </div>
            </div>
        </div>
    </main>
</div>

<!-- Create User Modal -->
<div id="create-user-modal" class="fixed inset-0 bg-black/50 backdrop-blur-sm hidden items-center justify-center z-50 p-4">
    <div class="bg-card-light dark:bg-card-dark border border-border-light dark:border-slate-700 rounded-xl max-w-md w-full p-6">
        <div class="flex items-center justify-between mb-4">
            <h3 class="text-xl font-bold text-text-main dark:text-white" data-translate="admin.createNewUser">Create New User</h3>
            <button onclick="closeCreateUserModal()" class="text-text-muted dark:text-slate-400 hover:text-text-main dark:hover:text-white">
                <span class="material-symbols-outlined">close</span>
            </button>
        </div>
        
        <form id="create-user-form" class="space-y-4">
            <div>
                <label class="text-text-muted dark:text-slate-400 text-sm mb-2 block" data-translate="form.username">Username</label>
                <input type="text" name="username" required class="w-full bg-background-light dark:bg-slate-800 border border-border-light dark:border-slate-700 rounded-lg px-4 py-2 text-text-main dark:text-white focus:border-primary focus:ring-1 focus:ring-primary">
            </div>
            
            <div>
                <label class="text-text-muted dark:text-slate-400 text-sm mb-2 block" data-translate="form.email">Email</label>
                <input type="email" name="email" required class="w-full bg-background-light dark:bg-slate-800 border border-border-light dark:border-slate-700 rounded-lg px-4 py-2 text-text-main dark:text-white focus:border-primary focus:ring-1 focus:ring-primary">
            </div>
            
            <div>
                <label class="text-text-muted dark:text-slate-400 text-sm mb-2 block" data-translate="form.password">Password</label>
                <input type="password" name="password" required minlength="8" class="w-full bg-background-light dark:bg-slate-800 border border-border-light dark:border-slate-700 rounded-lg px-4 py-2 text-text-main dark:text-white focus:border-primary focus:ring-1 focus:ring-primary">
            </div>
            
            <div class="flex items-center gap-2">
                <input type="checkbox" name="is_admin" id="is-admin-checkbox" class="rounded border-border-light dark:border-slate-700 text-primary focus:ring-primary">
                <label for="is-admin-checkbox" class="text-text-main dark:text-white text-sm" data-translate="admin.makeAdmin">Make admin</label>
            </div>
            
            <div class="flex gap-3 pt-2">
                <button type="submit" class="flex-1 bg-primary hover:bg-primary/90 text-white py-2 rounded-lg font-medium transition-colors">
                    <span data-translate="admin.create">Create</span>
                </button>
                <button type="button" onclick="closeCreateUserModal()" class="flex-1 bg-background-light dark:bg-slate-800 text-text-main dark:text-white py-2 rounded-lg font-medium hover:bg-slate-200 dark:hover:bg-slate-700 transition-colors">
                    <span data-translate="common.cancel">Cancel</span>
                </button>
            </div>
        </form>
    </div>
</div>

<script src="{{ url_for('static', filename='js/admin.js') }}"></script>
{% endblock %}
