{% extends "base.html" %}

{% block title %}Transactions - FINA{% endblock %}

{% block body %}
<div class="flex h-screen w-full">
    <!-- Sidebar (reuse from dashboard) -->
    <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]">
        <div class="p-6 flex flex-col h-full justify-between">
            <div class="flex flex-col gap-8">
                <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 %}Admin{% else %}User{% endif %}
                        </p>
                    </div>
                </div>
                
                <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-background-light 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">Dashboard</span>
                    </a>
                    <a class="flex items-center gap-3 px-3 py-2.5 rounded-lg bg-primary/20 text-primary border border-primary/10" href="{{ url_for('main.transactions') }}">
                        <span class="material-symbols-outlined text-[20px]">receipt_long</span>
                        <span class="text-sm font-medium">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-background-light 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">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-background-light 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">Documents</span>
                    </a>
                </nav>
            </div>
            
            <div 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-background-light 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">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-background-light 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">Log out</span>
                </a>
            </div>
        </div>
    </aside>
    
    <main class="flex-1 flex flex-col h-full overflow-hidden relative bg-background-light dark:bg-background-dark">
        <header class="h-16 flex items-center justify-between px-6 lg:px-8 border-b border-border-light dark:border-[#233648] bg-card-light/95 dark:bg-background-dark/95 backdrop-blur z-10 shrink-0">
            <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>
                <h2 class="text-text-main dark:text-white text-lg font-bold">Transactions</h2>
            </div>
            <div class="flex items-center gap-3">
                <button id="export-csv-btn" class="bg-background-light dark:bg-[#1a2632] border border-border-light dark:border-[#233648] text-text-muted dark:text-[#92adc9] hover:text-text-main dark:hover:text-white h-9 px-4 rounded-lg text-sm font-medium transition-colors flex items-center gap-2">
                    <span class="material-symbols-outlined text-[18px]">download</span>
                    <span class="hidden sm:inline">Export CSV</span>
                </button>
                <button id="import-csv-btn" class="bg-background-light dark:bg-[#1a2632] border border-border-light dark:border-[#233648] text-text-muted dark:text-[#92adc9] hover:text-text-main dark:hover:text-white h-9 px-4 rounded-lg text-sm font-medium transition-colors flex items-center gap-2">
                    <span class="material-symbols-outlined text-[18px]">upload</span>
                    <span class="hidden sm:inline">Import CSV</span>
                </button>
                <button id="add-expense-btn" class="bg-primary hover:bg-primary/90 text-white h-9 px-4 rounded-lg text-sm font-semibold shadow-lg shadow-primary/20 transition-all flex items-center gap-2">
                    <span class="material-symbols-outlined text-[18px]">add</span>
                    <span class="hidden sm:inline">Add Expense</span>
                </button>
            </div>
        </header>
        
        <div class="flex-1 overflow-y-auto p-6 lg:p-8 bg-background-light dark:bg-background-dark">
            <div class="max-w-7xl mx-auto">
                <!-- Transactions Card -->
                <div class="bg-card-light dark:bg-card-dark border border-border-light dark:border-[#233648] rounded-xl overflow-hidden">
                    <!-- Header with Search and Filters -->
                    <div class="p-6 border-b border-border-light dark:border-[#233648]">
                        <div class="flex flex-col sm:flex-row gap-4 justify-between items-start sm:items-center">
                            <!-- Search Bar -->
                            <div class="relative flex-1 max-w-md">
                                <span class="material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-text-muted dark:text-[#92adc9] text-[20px]">search</span>
                                <input 
                                    type="text" 
                                    id="filter-search" 
                                    placeholder="Search transactions..." 
                                    class="w-full bg-background-light dark:bg-[#111a22] border border-border-light dark:border-[#233648] rounded-lg pl-10 pr-4 py-2 text-text-main dark:text-white text-sm placeholder-text-muted dark:placeholder-[#5f7a96] focus:outline-none focus:ring-2 focus:ring-primary/50"
                                >
                            </div>
                            
                            <!-- Filter Buttons -->
                            <div class="flex flex-wrap gap-2">
                                <button id="date-filter-btn" class="flex items-center gap-2 px-3 py-2 bg-background-light dark:bg-[#111a22] border border-border-light dark:border-[#233648] rounded-lg text-text-muted dark:text-[#92adc9] hover:text-text-main dark:hover:text-white hover:border-primary/50 transition-colors text-sm">
                                    <span class="material-symbols-outlined text-[18px]">calendar_today</span>
                                    <span>Date</span>
                                </button>
                                <select id="filter-category" class="px-3 py-2 bg-background-light dark:bg-[#111a22] border border-border-light dark:border-[#233648] rounded-lg text-text-muted dark:text-[#92adc9] hover:text-text-main dark:hover:text-white hover:border-primary/50 transition-colors text-sm">
                                    <option value="">Category</option>
                                </select>
                                <button id="more-filters-btn" class="flex items-center gap-2 px-3 py-2 bg-background-light dark:bg-[#111a22] border border-border-light dark:border-[#233648] rounded-lg text-text-muted dark:text-[#92adc9] hover:text-text-main dark:hover:text-white hover:border-primary/50 transition-colors text-sm">
                                    <span class="material-symbols-outlined text-[18px]">tune</span>
                                    <span>Filters</span>
                                </button>
                            </div>
                        </div>
                        
                        <!-- Advanced Filters (Hidden by default) -->
                        <div id="advanced-filters" class="hidden mt-4 pt-4 border-t border-border-light dark:border-[#233648]">
                            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                                <div>
                                    <label class="text-text-muted dark:text-[#92adc9] text-sm mb-2 block">Start Date</label>
                                    <input type="date" id="filter-start-date" class="w-full bg-background-light dark:bg-[#111a22] border border-border-light dark:border-[#233648] rounded-lg px-4 py-2 text-text-main dark:text-white text-sm">
                                </div>
                                <div>
                                    <label class="text-text-muted dark:text-[#92adc9] text-sm mb-2 block">End Date</label>
                                    <input type="date" id="filter-end-date" class="w-full bg-background-light dark:bg-[#111a22] border border-border-light dark:border-[#233648] rounded-lg px-4 py-2 text-text-main dark:text-white text-sm">
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Transactions Table -->
                    <div class="overflow-x-auto">
                        <table class="w-full">
                            <thead class="bg-background-light dark:bg-[#0f1419]">
                                <tr class="border-b border-border-light dark:border-[#233648]">
                                    <th class="p-5 text-left text-text-muted dark:text-[#92adc9] text-sm font-medium">Transaction</th>
                                    <th class="p-5 text-left text-text-muted dark:text-[#92adc9] text-sm font-medium">Category</th>
                                    <th class="p-5 text-left text-text-muted dark:text-[#92adc9] text-sm font-medium">Date</th>
                                    <th class="p-5 text-left text-text-muted dark:text-[#92adc9] text-sm font-medium">Payment</th>
                                    <th class="p-5 text-right text-text-muted dark:text-[#92adc9] text-sm font-medium">Amount</th>
                                    <th class="p-5 text-center text-text-muted dark:text-[#92adc9] text-sm font-medium">Status</th>
                                    <th class="p-5 text-right text-text-muted dark:text-[#92adc9] text-sm font-medium">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="transactions-list" class="divide-y divide-border-light dark:divide-[#233648]">
                                <!-- Transactions will be loaded here -->
                            </tbody>
                        </table>
                    </div>
                    
                    <!-- Pagination Footer -->
                    <div class="p-4 border-t border-border-light dark:border-[#233648] flex flex-col sm:flex-row gap-4 justify-between items-center bg-card-light dark:bg-card-dark">
                        <span class="text-sm text-text-muted dark:text-[#92adc9]">
                            Showing <span id="page-start" class="text-text-main dark:text-white font-medium">1</span> to 
                            <span id="page-end" class="text-text-main dark:text-white font-medium">10</span> of 
                            <span id="total-count" class="text-text-main dark:text-white font-medium">0</span> results
                        </span>
                        <div id="pagination" class="flex gap-2">
                            <!-- Pagination buttons will be added here -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>
</div>

<!-- Hidden file input for CSV import -->
<input type="file" id="csv-file-input" accept=".csv" class="hidden">

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