@extends('layouts.admin_layout')

@push('styles')
<style>
  /* ===============================
       Base (mobile first)
    ================================ */
    
    /* Mobile pagination is visible by default */
    .pagination-mobile {
      display: flex;
    }
    
    /* Desktop pagination hidden by default */
    .pagination-desktop {
      display: none;
    }
    
    
    /* ===============================
       sm breakpoint (≥ 640px)
       Tailwind: sm:items-center sm:justify-between
    ================================ */
    
    @media (min-width: 640px) {
      .pagination-desktop {
        align-items: center;
        justify-content: space-between;
      }
    }
    
    
    /* ===============================
       md breakpoint (≥ 768px)
       Tailwind: sm:hidden md:flex md:flex-1
    ================================ */
    
    @media (min-width: 768px) {
      /* Hide mobile pagination */
      .pagination-mobile {
        display: none;
      }
    
      /* Show desktop pagination */
      .pagination-desktop {
        display: flex;
        flex: 1 1 0%;
      }
    }
    
</style>
@endpush

@section('content')

<main class="h-full pb-16 overflow-y-auto">
  <div class="container grid px-6 mx-auto">
    <h2 class="my-6 text-2xl font-semibold text-gray-700 dark:text-gray-200">
      <span class="text-blue-500">Depo</span>sits
    </h2>

    <!-- CTA -->
    <a
      class="flex items-center bg-blue-600 justify-between p-4 mb-8 text-sm font-semibold shadow-md rounded-lg hover:bg-blue-700 transition-colors focus:outline-none focus:shadow-outline-green"
      href="{{ url('/') }}" style="color: #fff;">
      <div class="flex items-center">
        <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
          <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"></path>
        </svg>
        <span>Go to main website</span>
      </div>
      <span>View &RightArrow;</span>
    </a>

    <!-- Statistics Cards -->
    <div class="grid gap-6 mb-8 md:grid-cols-2 xl:grid-cols-4">
      <!-- Total Deposits Card -->
      <div class="flex items-center p-4 bg-white rounded-lg shadow-md dark:bg-gray-800">
        <div class="p-3 mr-4 text-blue-500 bg-blue-100 rounded-full dark:text-blue-100 dark:bg-blue-500">
          <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
            <path d="M3 1a1 1 0 000 2h1.22l.305 1.222a.997.997 0 00.01.042l1.358 5.43-.893.892C3.74 11.846 4.632 14 6.414 14H15a1 1 0 000-2H6.414l1-1H14a1 1 0 00.894-.553l3-6A1 1 0 0017 3H6.28l-.31-1.243A1 1 0 005 1H3zM16 16.5a1.5 1.5 0 11-3 0 1.5 1.5 0 013 0zM6.5 18a1.5 1.5 0 100-3 1.5 1.5 0 000 3z"></path>
          </svg>
        </div>
        <div>
          <p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
            Total Deposits
          </p>
          <p class="text-lg font-semibold text-gray-700 dark:text-gray-200">
            {{ number_format($stats['total']) }}
          </p>
        </div>
      </div>

      <!-- Waiting Deposits Card -->
      <div class="flex items-center p-4 bg-white rounded-lg shadow-md dark:bg-gray-800">
        <div class="p-3 mr-4 text-orange-500 bg-orange-100 rounded-full dark:text-orange-100 dark:bg-orange-500">
          <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
            <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z" clip-rule="evenodd"></path>
          </svg>
        </div>
        <div>
          <p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
            Waiting
          </p>
          <p class="text-lg font-semibold text-gray-700 dark:text-gray-200">
            {{ number_format($stats['waiting']) }}
          </p>
        </div>
      </div>

      <!-- Completed Deposits Card -->
      <div class="flex items-center p-4 bg-white rounded-lg shadow-md dark:bg-gray-800">
        <div class="p-3 mr-4 text-green-500 bg-green-100 rounded-full dark:text-green-100 dark:bg-green-500">
          <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
            <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"></path>
          </svg>
        </div>
        <div>
          <p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
            Completed
          </p>
          <p class="text-lg font-semibold text-gray-700 dark:text-gray-200">
            {{ number_format($stats['completed']) }}
          </p>
        </div>
      </div>

      <!-- Total Amount Card -->
      <div class="flex items-center p-4 bg-white rounded-lg shadow-md dark:bg-gray-800">
        <div class="p-3 mr-4 text-teal-500 bg-teal-100 rounded-full dark:text-teal-100 dark:bg-teal-500">
          <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
            <path d="M8.433 7.418c.155-.103.346-.196.567-.267v1.698a2.305 2.305 0 01-.567-.267C8.07 8.34 8 8.114 8 8c0-.114.07-.34.433-.582zM11 12.849v-1.698c.22.071.412.164.567.267.364.243.433.468.433.582 0 .114-.07.34-.433.582a2.305 2.305 0 01-.567.267z"></path>
            <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-13a1 1 0 10-2 0v.092a4.535 4.535 0 00-1.676.662C6.602 6.234 6 7.009 6 8c0 .99.602 1.765 1.324 2.246.48.32 1.054.545 1.676.662v1.941c-.391-.127-.68-.317-.843-.504a1 1 0 10-1.51 1.31c.562.649 1.413 1.076 2.353 1.253V15a1 1 0 102 0v-.092a4.535 4.535 0 001.676-.662C13.398 13.766 14 12.991 14 12c0-.99-.602-1.765-1.324-2.246A4.535 4.535 0 0011 9.092V7.151c.391.127.68.317.843.504a1 1 0 101.511-1.31c-.563-.649-1.413-1.076-2.354-1.253V5z" clip-rule="evenodd"></path>
          </svg>
        </div>
        <div>
          <p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
            Total Value
          </p>
          <p class="text-lg font-semibold text-gray-700 dark:text-gray-200">
            ${{ number_format($stats['total_amount'], 2) }}
          </p>
        </div>
      </div>
    </div>

    <!-- Advanced Search Section -->
    <div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-8">
      <div class="flex items-center justify-between mb-4">
        <h3 class="text-lg font-semibold text-gray-700 dark:text-gray-200">
          <svg class="w-5 h-5 inline-block mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
          </svg>
          Advanced Search & Filters
        </h3>
        <button 
          type="button" 
          onclick="toggleAdvancedSearch()" 
          class="text-gray-300 dark:text-gray-300 hover:text-blue-800 dark:hover:text-blue-300 text-sm font-medium focus:outline-none"
          id="toggleBtn">
          <span id="toggleText">Show Filters</span>
          <svg id="toggleIcon" class="w-4 h-4 inline-block ml-1 transform transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
          </svg>
        </button>
      </div>

      <form method="GET" action="{{ route('admin.requests') }}" id="searchForm">
        <!-- Quick Search Bar (Always Visible) -->
        <div class="mb-4">
          <div class="relative">
            <input 
              type="text" 
              name="search" 
              value="{{ $searchTerm ?? '' }}"
              placeholder="Search by name, email, username, or payment ID..." 
              class="block w-full pl-10 pr-3 py-2 text-sm border border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500">
            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none" style="padding-left: 8px;">
              <svg class="h-5 w-5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
              </svg>
            </div>
          </div>
        </div>

        <!-- Advanced Filters (Collapsible) -->
        <div id="advancedFilters" class="hidden">
          <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-4" style="gap: 1rem;">
            
            <!-- Status Filter -->
            <div>
              <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                Status
              </label>
              <select
                name="status"
                class="block w-full text-sm dark:text-gray-300 border border-gray-300 dark:border-gray-600 dark:bg-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500 py-2 px-3">
                <option value="All" {{ request('status') == 'All' || !request('status') ? 'selected' : '' }}>All Status</option>
                <option value="Waiting" {{ request('status') == 'Waiting' ? 'selected' : '' }}>Waiting</option>
                <option value="Completed" {{ request('status') == 'Completed' ? 'selected' : '' }}>Completed</option>
                <option value="Failed" {{ request('status') == 'Failed' ? 'selected' : '' }}>Failed</option>
              </select>
            </div>

            <!-- Username Filter -->
            <div>
              <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                Store Name
              </label>
              <input 
                type="text" 
                name="username" 
                value="{{ request('username') }}"
                placeholder="Enter username"
                class="block w-full text-sm dark:text-gray-300 border border-gray-300 dark:border-gray-600 dark:bg-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500 py-2 px-3">
            </div>

            <!-- Email Filter -->
            <div>
              <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                Email
              </label>
              <input 
                type="email" 
                name="email" 
                value="{{ request('email') }}"
                placeholder="Enter email"
                class="block w-full text-sm dark:text-gray-300 border border-gray-300 dark:border-gray-600 dark:bg-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500 py-2 px-3">
            </div>

            <!-- Payment ID Filter -->
            <div>
              <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                Payment ID
              </label>
              <input 
                type="text" 
                name="payment_id" 
                value="{{ request('payment_id') }}"
                placeholder="Enter payment ID"
                class="block w-full text-sm dark:text-gray-300 border border-gray-300 dark:border-gray-600 dark:bg-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500 py-2 px-3">
            </div>

            <!-- Date From Filter -->
            <div>
              <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                Date From
              </label>
              <input 
                type="date" 
                name="date_from" 
                value="{{ request('date_from') }}"
                class="block w-full text-sm dark:text-gray-300 border border-gray-300 dark:border-gray-600 dark:bg-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500 py-2 px-3">
            </div>

            <!-- Date To Filter -->
            <div>
              <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                Date To
              </label>
              <input 
                type="date" 
                name="date_to" 
                value="{{ request('date_to') }}"
                class="block w-full text-sm dark:text-gray-300 border border-gray-300 dark:border-gray-600 dark:bg-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500 py-2 px-3">
            </div>

            <!-- Amount Min Filter -->
            <div>
              <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                Min Amount (USDT)
              </label>
              <input 
                type="number" 
                name="amount_min" 
                value="{{ request('amount_min') }}"
                placeholder="0.00"
                step="0.01"
                class="block w-full text-sm dark:text-gray-300 border border-gray-300 dark:border-gray-600 dark:bg-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500 py-2 px-3">
            </div>

            <!-- Amount Max Filter -->
            <div>
              <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                Max Amount (USDT)
              </label>
              <input 
                type="number" 
                name="amount_max" 
                value="{{ request('amount_max') }}"
                placeholder="0.00"
                step="0.01"
                class="block w-full text-sm dark:text-gray-300 border border-gray-300 dark:border-gray-600 dark:bg-gray-700 rounded-lg focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500 py-2 px-3">
            </div>
          </div>
        </div>

        <!-- Action Buttons -->
        <div class="flex items-center justify-between pt-4 border-t border-gray-200 dark:border-gray-700">
          <div class="text-sm text-gray-600 dark:text-gray-400">
            Showing {{ $deposits->firstItem() ?? 0 }} to {{ $deposits->lastItem() ?? 0 }} of {{ $deposits->total() }} results
          </div>
          <div class="flex gap-2" style="gap: 0.5rem">
            <a 
              href="{{ route('admin.requests') }}" 
              class="px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-blue-500">
              Clear Filters
            </a>
            <button 
              type="submit" 
              class="px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500">
              Apply Filters
            </button>
          </div>
        </div>
      </form>
    </div>

    <!-- Results Summary -->
    @if(!empty($title))
    <div class="mb-4 p-4 bg-blue-50 dark:bg-blue-900/20 border-l-4 border-blue-500 rounded-r-lg">
      <div class="flex items-center justify-between">
        <p class="text-lg font-semibold text-gray-700 dark:text-gray-200">
          {{ $title }}
        </p>
        <a href="{{ route('admin.requests') }}" class="text-sm text-blue-600 dark:text-blue-400 hover:underline font-semibold">
          &LeftArrow; Back to All
        </a>
      </div>
    </div>
    @else
    <div class="flex items-center justify-between mb-4">
      <h4 class="text-lg font-semibold text-gray-600 dark:text-gray-300">
        List of Investment Deposit Requests
      </h4>
      <div class="text-sm text-gray-600 dark:text-gray-400">
        Total: <span class="font-semibold">{{ $deposits->total() }}</span> deposits
      </div>
    </div>
    @endif

    <x-alert/>

    <!-- Deposits Table -->
    <div class="w-full overflow-hidden rounded-lg shadow-md">
      <div class="w-full overflow-x-auto">
        <table class="w-full whitespace-no-wrap">
          <thead>
            <tr class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b dark:border-gray-700 bg-gray-50 dark:text-gray-400 dark:bg-gray-800">
              <th class="px-4 py-3">User</th>
              <th class="px-4 py-3">Amount</th>
              <th class="px-4 py-3">Payment ID</th>
              <th class="px-4 py-3">Status</th>
              <th class="px-4 py-3">Date</th>
            </tr>
          </thead>
          <tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800">
            @forelse($deposits as $deposit)
            <tr class="text-gray-700 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors">
              <td class="px-4 py-3">
                <div class="flex items-center text-sm">
                  <!-- Avatar with inset shadow -->
                  <div class="relative hidden w-8 h-8 mr-3 rounded-full md:block">
                    <img
                      class="object-cover w-full h-full rounded-full"
                      src="{{ $deposit->user?->avatar ? asset('storage/images/'.$deposit->user->avatar) : asset('images/toy-avatar.png') }}"
                      alt="{{ $deposit->user?->first_name }}"
                      loading="lazy" />
                    <div class="absolute inset-0 rounded-full shadow-inner" aria-hidden="true"></div>
                  </div>
                  <div>
                    <a href="#" class="hover:text-blue-600 dark:hover:text-blue-400">
                      <p class="font-semibold">{{ $deposit->user?->first_name }} {{ $deposit->user?->last_name }}</p>
                      <p class="text-xs text-gray-600 dark:text-gray-400">
                        {{ $deposit->user?->email }} - [{{ $deposit->user?->username }}]
                      </p>
                    </a>
                  </div>
                </div>
              </td>
              <td class="px-4 py-3 text-sm font-medium">
                <span class="text-green-600 dark:text-green-400">
                  USDT {{ number_format($deposit->amount, 2) }}
                </span>
              </td>
              <td class="px-4 py-3 text-sm">
                <code class="px-2 py-1 text-xs font-mono bg-gray-100 dark:bg-gray-700 rounded">
                  {{ $deposit->payment_id }}
                </code>
              </td>
              <td class="px-4 py-3 text-xs">
                @if($deposit->status == 2)
                  <span class="px-2 py-1 font-semibold leading-tight text-red-700 bg-red-100 rounded-full dark:bg-red-700 dark:text-red-100">
                    Failed
                  </span>
                @elseif($deposit->status == null)
                  <span class="px-2 py-1 font-semibold leading-tight text-orange-700 bg-orange-100 rounded-full dark:bg-orange-100 dark:text-orange-500">
                    Waiting...
                  </span>
                @elseif($deposit->status == 1)
                  <span class="px-2 py-1 font-semibold leading-tight text-green-700 bg-green-100 rounded-full dark:bg-green-700 dark:text-green-100">
                    Completed
                  </span>
                @endif
              </td>
              <td class="px-4 py-3 text-sm">
                {{ date('M j, Y', strtotime($deposit->created_at)) }}
              </td>
            </tr>
            @empty
            <tr>
              <td colspan="5" class="px-4 py-12 text-center">
                <div class="flex flex-col items-center justify-center text-gray-500 dark:text-gray-400">
                  <svg class="w-16 h-16 mb-4 text-gray-300 dark:text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"></path>
                  </svg>
                  <p class="text-lg font-medium">No deposit requests found</p>
                  <p class="text-sm mt-1">Try adjusting your filters or search criteria</p>
                </div>
              </td>
            </tr>
            @endforelse
          </tbody>
        </table>
      </div>

      <!-- Pagination -->
      @if($deposits->hasPages())
      <div class="px-4 py-3 border-t dark:border-gray-700 bg-gray-50 dark:bg-gray-800">
        <div class="flex items-center justify-between">
          <div class="flex-1 flex justify-between pagination-mobile">
            @if ($deposits->onFirstPage())
              <span class="relative inline-flex items-center px-4 py-2 text-sm font-medium text-gray-500 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 cursor-default rounded-md">
                Previous
              </span>
            @else
              <a href="{{ $deposits->previousPageUrl() }}" class="relative inline-flex items-center px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md hover:bg-gray-50 dark:hover:bg-gray-600">
                Previous
              </a>
            @endif

            @if ($deposits->hasMorePages())
              <a href="{{ $deposits->nextPageUrl() }}" class="relative inline-flex items-center px-4 py-2 ml-3 text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md hover:bg-gray-50 dark:hover:bg-gray-600">
                Next
              </a>
            @else
              <span class="relative inline-flex items-center px-4 py-2 ml-3 text-sm font-medium text-gray-500 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 cursor-default rounded-md">
                Next
              </span>
            @endif
          </div>

          <div class="pagination-desktop">
            <div>
              <p class="text-sm text-gray-700 dark:text-gray-400">
                Showing
                <span class="font-medium">{{ $deposits->firstItem() }}</span>
                to
                <span class="font-medium">{{ $deposits->lastItem() }}</span>
                of
                <span class="font-medium">{{ $deposits->total() }}</span>
                results
              </p>
            </div>
            <div>
              <nav class="relative z-0 inline-flex rounded-md shadow-sm -space-x-px" aria-label="Pagination">
                {{-- Previous Page Link --}}
                @if ($deposits->onFirstPage())
                  <span class="relative inline-flex items-center px-2 py-2 rounded-l-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm font-medium text-gray-500 cursor-default">
                    <svg class="h-5 w-5" fill="currentColor" viewBox="0 0 20 20">
                      <path fill-rule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clip-rule="evenodd" />
                    </svg>
                  </span>
                @else
                  <a href="{{ $deposits->previousPageUrl() }}" class="relative inline-flex items-center px-2 py-2 rounded-l-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm font-medium text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-600">
                    <svg class="h-5 w-5" fill="currentColor" viewBox="0 0 20 20">
                      <path fill-rule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clip-rule="evenodd" />
                    </svg>
                  </a>
                @endif

                {{-- Pagination Elements --}}
                @foreach ($deposits->links()->elements[0] as $page => $url)
                  @if ($page == $deposits->currentPage())
                    <span class="relative inline-flex items-center px-4 py-2 border border-blue-500 dark:border-blue-600 bg-blue-50 dark:bg-blue-900 text-sm font-medium text-blue-600 dark:text-blue-200">
                      {{ $page }}
                    </span>
                  @else
                    <a href="{{ $url }}" class="relative inline-flex items-center px-4 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm font-medium text-gray-700 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-600">
                      {{ $page }}
                    </a>
                  @endif
                @endforeach

                {{-- Next Page Link --}}
                @if ($deposits->hasMorePages())
                  <a href="{{ $deposits->nextPageUrl() }}" class="relative inline-flex items-center px-2 py-2 rounded-r-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm font-medium text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-600">
                    <svg class="h-5 w-5" fill="currentColor" viewBox="0 0 20 20">
                      <path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd" />
                    </svg>
                  </a>
                @else
                  <span class="relative inline-flex items-center px-2 py-2 rounded-r-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm font-medium text-gray-500 cursor-default">
                    <svg class="h-5 w-5" fill="currentColor" viewBox="0 0 20 20">
                      <path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd" />
                    </svg>
                  </span>
                @endif
              </nav>
            </div>
          </div>
        </div>
      </div>
      @endif
    </div>
  </div>
</main>

<script>
function toggleAdvancedSearch() {
  const filters = document.getElementById('advancedFilters');
  const toggleText = document.getElementById('toggleText');
  const toggleIcon = document.getElementById('toggleIcon');
  
  if (filters.classList.contains('hidden')) {
    filters.classList.remove('hidden');
    toggleText.textContent = 'Hide Filters';
    toggleIcon.classList.add('rotate-180');
  } else {
    filters.classList.add('hidden');
    toggleText.textContent = 'Show Filters';
    toggleIcon.classList.remove('rotate-180');
  }
}

// Auto-expand filters if any advanced filter is active
document.addEventListener('DOMContentLoaded', function() {
  const hasActiveFilters = {{ 
    request()->filled('username') || 
    request()->filled('email') || 
    request()->filled('payment_id') || 
    request()->filled('date_from') || 
    request()->filled('date_to') || 
    request()->filled('amount_min') || 
    request()->filled('amount_max') ? 'true' : 'false' 
  }};
  
  if (hasActiveFilters) {
    toggleAdvancedSearch();
  }
});
</script>

@endsection