<x-admin-layout>
@section('title', $page . ' | ' . get_setting('site_name'))
  <div class="mt-4 grid grid-cols-12 gap-4 sm:mt-5 sm:gap-5 lg:mt-6 lg:gap-6">
    <div class="col-span-12">
        <h2 class="text-lg font-semibold text-slate-600 dark:text-navy-100 mb-4">
            {{ $user->name }}: {{ $user->email }}
        </h2>
      <div x-data="{activeTab:'Stats'}" class="tabs flex flex-col mt-3">
        <div
          class="is-scrollbar-hidden overflow-x-auto rounded-lg bg-slate-200 text-slate-600 dark:bg-navy-800 dark:text-navy-200"
        >
          <div class="tabs-list flex px-1.5 py-1">
            <button
              @click="activeTab = 'Stats'"
              :class="activeTab === 'Stats' ? 'bg-white shadow dark:bg-navy-500 dark:text-navy-100' : 'hover:text-slate-800 focus:text-slate-800 dark:hover:text-navy-100 dark:focus:text-navy-100'"
              class="btn shrink-0 space-x-2 px-3 py-1.5 font-medium"
            >
            <i class="fas fa-chart-line"></i>
              <span>Statistics</span>
            </button>
            <button
              @click="activeTab = 'Referrals'"
              :class="activeTab === 'Referrals' ? 'bg-white shadow dark:bg-navy-500 dark:text-navy-100' : 'hover:text-slate-800 focus:text-slate-800 dark:hover:text-navy-100 dark:focus:text-navy-100'"
              class="btn shrink-0 space-x-2 px-3 py-1.5 font-medium"
              id="ref"
            >
            <i class="fas fa-user-friends"></i>
              <span>Referrals</span>
            </button>
            <button
              @click="activeTab = 'WD'"
              :class="activeTab === 'WD' ? 'bg-white shadow dark:bg-navy-500 dark:text-navy-100' : 'hover:text-slate-800 focus:text-slate-800 dark:hover:text-navy-100 dark:focus:text-navy-100'"
              class="btn shrink-0 space-x-2 px-3 py-1.5 font-medium"
              id="wd"
            >
            <i class="fas fa-wallet"></i>
              <span>Withdrawals</span>
            </button>
            <button
              @click="activeTab = 'DP'"
              :class="activeTab === 'DP' ? 'bg-white shadow dark:bg-navy-500 dark:text-navy-100' : 'hover:text-slate-800 focus:text-slate-800 dark:hover:text-navy-100 dark:focus:text-navy-100'"
              class="btn shrink-0 space-x-2 px-3 py-1.5 font-medium"
              id="dp"
            >
            <i class="fas fa-bank"></i>
              <span>Deposits</span>
            </button>
            <a href="/admin/faucet-history?uid={{ $user->id }}" target="_blank"
              class="btn shrink-0 space-x-2 px-3 py-1.5 font-medium hover:text-slate-800 focus:text-slate-800 dark:hover:text-navy-100 dark:focus:text-navy-100"
            >
            <i class="fas fa-faucet"></i>
              <span>Faucet</span>
            </a>
            <a href="/admin/ptc-history?uid={{ $user->id }}" target="_blank"
              class="btn shrink-0 space-x-2 px-3 py-1.5 font-medium hover:text-slate-800 focus:text-slate-800 dark:hover:text-navy-100 dark:focus:text-navy-100"
            >
            <i class="fas fa-ad"></i>
              <span>PTC Ads</span>
            </a>
            <a href="/admin/link-history?uid={{ $user->id }}" target="_blank"
              class="btn shrink-0 space-x-2 px-3 py-1.5 font-medium hover:text-slate-800 focus:text-slate-800 dark:hover:text-navy-100 dark:focus:text-navy-100"
            >
            <i class="fas fa-link"></i>
              <span>Shortlink</span>
            </a>
            <a href="/admin/offerwall?uid={{ $user->id }}" target="_blank"
              class="btn shrink-0 space-x-2 px-3 py-1.5 font-medium hover:text-slate-800 focus:text-slate-800 dark:hover:text-navy-100 dark:focus:text-navy-100"
            >
            <i class="fas fa-th-large"></i>
              <span>Offerwall</span>
            </a>
            <a href="/admin/contest-history?uid={{ $user->id }}" target="_blank"
              class="btn shrink-0 space-x-2 px-3 py-1.5 font-medium hover:text-slate-800 focus:text-slate-800 dark:hover:text-navy-100 dark:focus:text-navy-100"
            >
            <i class="fas fa-trophy"></i>
              <span>Contest</span>
            </a>
          </div>
        </div>
        <div class="tab-content pt-4">
          <div
            x-show="activeTab === 'Stats'"
            x-transition:enter="transition-all duration-500 easy-in-out"
            x-transition:enter-start="opacity-0 [transform:translate3d(1rem,0,0)]"
            x-transition:enter-end="opacity-100 [transform:translate3d(0,0,0)]"
          >
            <div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
              <div class="relative flex flex-col overflow-hidden rounded-lg bg-gradient-to-br from-sky-400 to-blue-600 p-3.5">
                <p class="text-xs uppercase text-sky-100">Account Balance</p>
                <div class="flex items-end justify-between space-x-2">
                  <p class="mt-4 text-2xl font-medium text-white" id="userbalance">{!! balanceAndSymbol($user->balance) !!}</p>
                </div>
                <div
                  class="mask is-reuleaux-triangle absolute top-0 right-0 -m-3 size-16 bg-white/20"
                ></div>
              </div>
              <div class="relative flex flex-col overflow-hidden rounded-lg bg-gradient-to-br from-amber-400 to-orange-600 p-3.5">
                <p class="text-xs uppercase text-amber-50">Deposit Balance</p>
                <div class="flex items-end justify-between space-x-2">
                  <p class="mt-4 text-2xl font-medium text-white" id="userdeposit">${{ formatUSD($user->available_deposit) }}</p>
                </div>
                <div
                  class="mask is-diamond absolute top-0 right-0 -m-3 size-16 bg-white/20"
                ></div>
              </div>
              <div class="relative flex flex-col overflow-hidden rounded-lg bg-gradient-to-br from-pink-500 to-rose-500 p-3.5">
                <p class="text-xs uppercase text-pink-100">Total Earned</p>
                <div class="flex items-end justify-between space-x-2">
                  <p class="mt-4 text-2xl font-medium text-white" id="userearned">{!! balanceAndSymbol($user->total_earned) !!}</p>
                </div>
                <div
                  class="mask is-hexagon-2 absolute top-0 right-0 -m-3 size-16 bg-white/20"
                ></div>
              </div>
              <div class="relative flex flex-col overflow-hidden rounded-lg bg-gradient-to-br from-violet-400 to-indigo-400 p-3.5">
                <p class="text-xs uppercase text-pink-100">Expense</p>
                <div class="flex items-end justify-between space-x-2">
                  <p class="mt-4 text-2xl font-medium text-white">${{ formatUSD($user->deposited-$user->available_deposit) }}</p>
                </div>
                <div
                  class="mask is-hexagon-2 absolute top-0 right-0 -m-3 size-16 bg-white/20"
                ></div>
              </div>
                <div class="card pb-4">
                    <div class="px-4 sm:px-5">
                        <div class="flex items-center justify-between">
                            <h2 class="font-medium tracking-wide text-slate-700 dark:text-navy-100 mt-3">Account Balance</h2>
                        </div>
                        <div class="relative">
                            <div class="pt-4">
                                <p class="text-xs+">Amount:</p>
                                <div class="mt-1 flex justify-between space-x-2 rounded-2xl bg-slate-150 p-1.5 dark:bg-navy-800">
                                    <select class="form-select h-8 rounded-2xl border border-transparent bg-white px-4 py-0 pr-9 text-xs+ hover:border-slate-400 focus:border-primary dark:bg-navy-700 dark:hover:border-navy-400 dark:focus:border-accent" disabled>
                                        <option>{{ get_setting('currency_name') }}</option>
                                    </select>
                                    <input id="accountAmount" class="form-input w-full bg-transparent px-2 text-right placeholder:text-slate-400/70" name="amount" placeholder="Amount" type="number" step="0.000001" />
                                </div>
                            </div>
                        </div>
                        <div class="flex gap-2 mt-6">
                            <button id="addBalanceBtn" class="btn h-10 w-full bg-primary text-white">Add</button>
                            <button id="reduceBalanceBtn" class="btn h-10 w-full bg-error text-white">Reduce</button>
                        </div>
                    </div>
                </div>
                
                <div class="card pb-4">
                    <div class="px-4 sm:px-5">
                        <div class="flex items-center justify-between">
                            <h2 class="font-medium tracking-wide text-slate-700 dark:text-navy-100 mt-3">Deposit Balance</h2>
                        </div>
                        <div class="relative">
                            <div class="pt-4">
                                <p class="text-xs+">Amount:</p>
                                <div class="mt-1 flex justify-between space-x-2 rounded-2xl bg-slate-150 p-1.5 dark:bg-navy-800">
                                    <select class="form-select h-8 rounded-2xl border border-transparent bg-white px-4 py-0 pr-9 text-xs+ hover:border-slate-400 focus:border-primary dark:bg-navy-700 dark:hover:border-navy-400 dark:focus:border-accent" disabled>
                                        <option>$</option>
                                    </select>
                                    <input id="depositAmount" class="form-input w-full bg-transparent px-2 text-right placeholder:text-slate-400/70" name="amount_deposit" placeholder="Amount" type="number" step="0.000001" />
                                </div>
                            </div>
                        </div>
                        <div class="flex gap-2 mt-6">
                            <button id="addDepositBtn" class="btn h-10 w-full bg-primary text-white">Add</button>
                            <button id="reduceDepositBtn" class="btn h-10 w-full bg-error text-white">Reduce</button>
                        </div>
                    </div>
                </div>

            </div>

              <div class="card pb-1">
                <div class="my-3 flex items-center justify-between px-4 sm:px-5">
                  <h2 class="font-medium tracking-wide text-slate-700 dark:text-navy-100"> Earnings Statistics </h2>
                </div>
                <div class="space-x-4 overflow-x-auto overflow-y-hidden px-4 pb-2 sm:px-5">
                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-4 items-center">
                        <div>
                            <span class="block mb-1 text-sm font-medium">Date Range:</span>
                            <label class="relative flex">
                                <input
                                    id="date_range1"
                                    x-init="$el._x_flatpickr = flatpickr($el, {
                                        mode: 'range',
                                        dateFormat: 'Y-m-d',
                                        defaultDate: [
                                            new Date(new Date().setDate(new Date().getDate() - 1)).toISOString().split('T')[0], 
                                            new Date(new Date().setDate(new Date().getDate())).toISOString().split('T')[0]
                                        ],
                                        maxDate: new Date(new Date().setDate(new Date().getDate() + 7)),
                                        onClose: function(selectedDates) {
                                            handleEventTypeChange(1); 
                                        }
                                    })"
                                    class="form-input peer w-full rounded-lg border border-slate-300 bg-transparent px-3 py-2 pl-9 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent"
                                    placeholder="Choose date..."
                                    type="text"
                                />
                                <span
                                  class="pointer-events-none absolute flex h-full w-10 items-center justify-center text-slate-400 peer-focus:text-primary dark:text-navy-300 dark:peer-focus:text-accent"
                                >
                                  <svg
                                    xmlns="http://www.w3.org/2000/svg"
                                    class="size-5 transition-colors duration-200"
                                    fill="none"
                                    viewBox="0 0 24 24"
                                    stroke="currentColor"
                                    stroke-width="1.5"
                                  >
                                    <path
                                      stroke-linecap="round"
                                      stroke-linejoin="round"
                                      d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
                                    />
                                  </svg>
                                </span>
                            </label>
                        </div>
                        <div>
                            <span class="block mb-1 text-sm font-medium">Choose Event Type:</span>
                            <label class="flex-1">
                                <select
                                    id="event_type1"
                                    class="form-select w-full rounded-lg border border-slate-300 bg-white px-3 py-2 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:bg-navy-700 dark:hover:border-navy-400 dark:focus:border-accent"
                                    onchange="handleEventTypeChange(1)"
                                >
                                    <option value="all">All</option>
                                    <option value="Faucet">Faucet</option>
                                    <option value="PTC Ads">PTC Ads</option>
                                    <option value="Shortlink">Shortlink</option>
                                    <option value="Offerwalls">Offerwalls</option>
                                    <option value="Referrals">Referrals</option>
                                    <option value="Contest">Contest</option>
                                </select>
                            </label>
                        </div>
                    </div>
                    <div id="chart1" class="mt-5">
                        <div class="w-full px-6 py-4"><div class="skeleton animate-wave h-3 w-full rounded bg-slate-150 dark:bg-navy-500"></div><div class="skeleton animate-wave mt-4 h-3 w-8/12 rounded bg-slate-150 dark:bg-navy-500"></div></div>
                    </div>
                </div>
              </div>
              <div class="card mt-3 pb-1">
                <div class="my-3 flex items-center justify-between px-4 sm:px-5">
                  <h2 class="font-medium tracking-wide text-slate-700 dark:text-navy-100"> Deposit Statistics </h2>
                </div>
                <div class="space-x-4 overflow-x-auto overflow-y-hidden px-4 pb-2 sm:px-5">
                    <div class="grid grid-cols-1 sm:grid-cols-1 gap-4 items-center">
                        <div>
                            <span class="block mb-1 text-sm font-medium">Date Range:</span>
                            <label class="relative flex">
                                <input
                                    id="date_range2"
                                    x-init="$el._x_flatpickr = flatpickr($el, {
                                        mode: 'range',
                                        dateFormat: 'Y-m-d',
                                        defaultDate: [
                                            new Date(new Date().setDate(new Date().getDate() - 1)).toISOString().split('T')[0], 
                                            new Date(new Date().setDate(new Date().getDate())).toISOString().split('T')[0]
                                        ],
                                        maxDate: new Date(new Date().setDate(new Date().getDate() + 7)),
                                        onClose: function(selectedDates) {
                                            handleEventTypeChange(2); 
                                        }
                                    })"
                                    class="form-input peer w-full rounded-lg border border-slate-300 bg-transparent px-3 py-2 pl-9 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent"
                                    placeholder="Choose date..."
                                    type="text"
                                />
                                <span
                                  class="pointer-events-none absolute flex h-full w-10 items-center justify-center text-slate-400 peer-focus:text-primary dark:text-navy-300 dark:peer-focus:text-accent"
                                >
                                  <svg
                                    xmlns="http://www.w3.org/2000/svg"
                                    class="size-5 transition-colors duration-200"
                                    fill="none"
                                    viewBox="0 0 24 24"
                                    stroke="currentColor"
                                    stroke-width="1.5"
                                  >
                                    <path
                                      stroke-linecap="round"
                                      stroke-linejoin="round"
                                      d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
                                    />
                                  </svg>
                                </span>
                            </label>
                        </div>
                            <label class="hidden">
                                <select
                                    id="event_type2"
                                    class="form-select w-full rounded-lg border border-slate-300 bg-white px-3 py-2 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:bg-navy-700 dark:hover:border-navy-400 dark:focus:border-accent"
                                    onchange="handleEventTypeChange(2)"
                                >
                                    <option value="Deposit" selected></option>
                                </select>
                            </label>
                    </div>
                    <div id="chart2" class="mt-5">
                        <div class="w-full px-6 py-4"><div class="skeleton animate-wave h-3 w-full rounded bg-slate-150 dark:bg-navy-500"></div><div class="skeleton animate-wave mt-4 h-3 w-8/12 rounded bg-slate-150 dark:bg-navy-500"></div></div>
                    </div>
                </div>
              </div>
              <div class="card mt-3 pb-1">
                <div class="my-3 flex items-center justify-between px-4 sm:px-5">
                  <h2 class="font-medium tracking-wide text-slate-700 dark:text-navy-100"> Withdraw Statistics </h2>
                </div>
                <div class="space-x-4 overflow-x-auto overflow-y-hidden px-4 pb-2 sm:px-5">
                    <div class="grid grid-cols-1 sm:grid-cols-1 gap-4 items-center">
                        <div>
                            <span class="block mb-1 text-sm font-medium">Date Range:</span>
                            <label class="relative flex">
                                <input
                                    id="date_range3"
                                    x-init="$el._x_flatpickr = flatpickr($el, {
                                        mode: 'range',
                                        dateFormat: 'Y-m-d',
                                        defaultDate: [
                                            new Date(new Date().setDate(new Date().getDate() - 1)).toISOString().split('T')[0], 
                                            new Date(new Date().setDate(new Date().getDate())).toISOString().split('T')[0]
                                        ],
                                        maxDate: new Date(new Date().setDate(new Date().getDate() + 7)),
                                        onClose: function(selectedDates) {
                                            handleEventTypeChange(3); 
                                        }
                                    })"
                                    class="form-input peer w-full rounded-lg border border-slate-300 bg-transparent px-3 py-2 pl-9 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent"
                                    placeholder="Choose date..."
                                    type="text"
                                />
                                <span
                                  class="pointer-events-none absolute flex h-full w-10 items-center justify-center text-slate-400 peer-focus:text-primary dark:text-navy-300 dark:peer-focus:text-accent"
                                >
                                  <svg
                                    xmlns="http://www.w3.org/2000/svg"
                                    class="size-5 transition-colors duration-200"
                                    fill="none"
                                    viewBox="0 0 24 24"
                                    stroke="currentColor"
                                    stroke-width="1.5"
                                  >
                                    <path
                                      stroke-linecap="round"
                                      stroke-linejoin="round"
                                      d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
                                    />
                                  </svg>
                                </span>
                            </label>
                        </div>
                            <label class="hidden">
                                <select
                                    id="event_type3"
                                    class="form-select w-full rounded-lg border border-slate-300 bg-white px-3 py-2 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:bg-navy-700 dark:hover:border-navy-400 dark:focus:border-accent"
                                    onchange="handleEventTypeChange(3)"
                                >
                                    <option value="Withdraw" selected></option>
                                </select>
                            </label>
                    </div>
                    <div id="chart3" class="mt-5">
                        <div class="w-full px-6 py-4"><div class="skeleton animate-wave h-3 w-full rounded bg-slate-150 dark:bg-navy-500"></div><div class="skeleton animate-wave mt-4 h-3 w-8/12 rounded bg-slate-150 dark:bg-navy-500"></div></div>
                    </div>
                </div>
              </div>
          </div>
          <div
            x-show="activeTab === 'Referrals'"
            x-transition:enter="transition-all duration-500 easy-in-out"
            x-transition:enter-start="opacity-0 [transform:translate3d(1rem,0,0)]"
            x-transition:enter-end="opacity-100 [transform:translate3d(0,0,0)]"
          >
              <div class="card pb-4">
                <div class="flex items-center justify-between">
                    <h2 class="text-base font-medium tracking-wide text-slate-700 line-clamp-1 dark:text-navy-100">
                       
                    </h2>
                    <div class="flex items-center space-x-2" x-data="{ isInputActive: false, searchText: '' }">
                        <!-- Search Input with Toggle -->
                        <div class="flex items-center">
                            <label class="block">
                                <input x-model="searchText" x-transition x-effect="isInputActive === true &amp;&amp; $nextTick(() => { $el.focus()});" :class="isInputActive ? 'w-32 lg:w-48' : 'w-0'" class="form-input bg-transparent px-1 text-right transition-all duration-100 placeholder:text-slate-500 dark:placeholder:text-navy-200 w-0" placeholder="Search here..." type="text" id="search" autocomplete="new-password">
                            </label>
                            <button @click="isInputActive = !isInputActive" class="btn size-8 rounded-full p-0 hover:bg-slate-300/20 focus:bg-slate-300/20 active:bg-slate-300/25 dark:hover:bg-navy-300/20 dark:focus:bg-navy-300/20 dark:active:bg-navy-300/25">
                                <svg xmlns="http://www.w3.org/2000/svg" class="size-4.5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
                                </svg>
                              </button>
                        </div>
                    </div>
                </div>
                <div class="overflow-x-auto">
                  <table class="is-hoverable w-full text-left">
                    <thead>
                      <tr>
                        <th class="whitespace-nowrap rounded-tl-lg bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> Name </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> Email </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> Status </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> Activity Count </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> IP Addresses </th>
                      </tr>
                    </thead>
                    <tbody id="users-table">
                      <tr>
                        <td colspan="5" class="text-center py-4"><div class="w-full px-6 py-4"><div class="skeleton animate-wave h-3 w-full rounded bg-slate-150 dark:bg-navy-500"></div><div class="skeleton animate-wave mt-4 h-3 w-8/12 rounded bg-slate-150 dark:bg-navy-500"></div></div></td>
                      </tr>
                    </tbody>
                  </table>
                </div>
                
                <!-- Pagination -->
                <div id="pagination" class="mt-4 flex justify-center"></div>
              </div>
          </div>
          <div
            x-show="activeTab === 'WD'"
            x-transition:enter="transition-all duration-500 easy-in-out"
            x-transition:enter-start="opacity-0 [transform:translate3d(1rem,0,0)]"
            x-transition:enter-end="opacity-100 [transform:translate3d(0,0,0)]"
          >
              <div class="card pb-4">
                <div class="overflow-x-auto">
                  <table class="is-hoverable w-full text-left">
                    <thead>
                      <tr>
                        <th class="whitespace-nowrap rounded-tl-lg bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5">
                             Method </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> Address </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> Status </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> Crypto </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> Amount </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> Fee </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5">Date</th>
                      </tr>
                    </thead>
                    <tbody id="withdrawals">
                      <tr>
                        <td colspan="6" class="text-center py-4"><div class="w-full px-6 py-4"><div class="skeleton animate-wave h-3 w-full rounded bg-slate-150 dark:bg-navy-500"></div><div class="skeleton animate-wave mt-4 h-3 w-8/12 rounded bg-slate-150 dark:bg-navy-500"></div></div></td>
                      </tr>
                    </tbody>
                  </table>
                </div>
                
                <!-- Pagination -->
                <div id="pagination2" class="mt-4 flex justify-center"></div>
              </div>
          </div>
          <div
            x-show="activeTab === 'DP'"
            x-transition:enter="transition-all duration-500 easy-in-out"
            x-transition:enter-start="opacity-0 [transform:translate3d(1rem,0,0)]"
            x-transition:enter-end="opacity-100 [transform:translate3d(0,0,0)]"
          >
              <div class="card pb-4">
                <div class="overflow-x-auto">
                  <table class="is-hoverable w-full text-left">
                    <thead>
                      <tr>
                        <th class="whitespace-nowrap rounded-tl-lg bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5">
                             Method </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> Status </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> Transaction </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5"> Amount </th>
                        <th class="whitespace-nowrap bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5">Date</th>
                      </tr>
                    </thead>
                    <tbody id="deposits">
                      <tr>
                        <td colspan="5" class="text-center py-4"><div class="w-full px-6 py-4"><div class="skeleton animate-wave h-3 w-full rounded bg-slate-150 dark:bg-navy-500"></div><div class="skeleton animate-wave mt-4 h-3 w-8/12 rounded bg-slate-150 dark:bg-navy-500"></div></div></td>
                      </tr>
                    </tbody>
                  </table>
                </div>
                
                <!-- Pagination -->
                <div id="pagination3" class="mt-4 flex justify-center"></div>
              </div>
          </div>
        </div>
      </div>
    </div>
  </div>
@push('scripts')
<script>
sessionStorage.clear();
var currencyRate = {{ get_Setting('currency_rate') }};
var currencyRounds = {{ get_Setting('currency_rounds') }};

var chartCache = JSON.parse(sessionStorage.getItem("chartCache")) || [];

if (!Array.isArray(chartCache)) {
    chartCache = [];
}

function loadChart(container, daterange, eventype) {
    $("#" + container).html('<div class="w-full px-6 py-4"><div class="skeleton animate-wave h-3 w-full rounded bg-slate-150 dark:bg-navy-500"></div><div class="skeleton animate-wave mt-4 h-3 w-8/12 rounded bg-slate-150 dark:bg-navy-500"></div></div>');

    let dateRange = document.getElementById("date_range" + daterange).value;
    let eventType = document.getElementById("event_type" + eventype).value;
    let dates = dateRange.split(" to ");
    let startDate = dates[0]?.trim() || new Date().toISOString().split('T')[0];
    let endDate = dates[1]?.trim() || startDate;

    let cachedData = chartCache.find(entry => 
        entry.startDate === startDate && 
        entry.endDate === endDate && 
        entry.eventType === eventType
    );

    if (cachedData) {
        updateChartFromCache(container, cachedData.data);
        return;
    }

    $.ajax({
        url: "/admin/chart/load/{{ $user->id }}",
        type: "GET",
        data: { start_date: startDate, end_date: endDate, event_type: eventType },
        dataType: "json",
        success: function (data) {
            chartCache.push({ startDate, endDate, eventType, data });
            sessionStorage.setItem("chartCache", JSON.stringify(chartCache));

            let categories = data.map(item => item.date);
            let values = data.map(item => Math.round(item.count));
            let rewards = '';
            if(container == 'chart2') {
                rewards = data.map(item => parseFloat(Number(item.total_deposit || 0).toFixed(6)));
            }else if(container == 'chart3') {
                rewards = data.map(item => parseFloat(((item.total_withdraw || 0) * currencyRate).toFixed(currencyRounds)));
            }else{
                rewards = data.map(item => parseFloat(((item.total_reward || 0) * currencyRate).toFixed(currencyRounds)));
            }
            updateChart(container, categories, values, rewards);
        },
        error: function () {
            console.error("Error fetching chart data.");
        }
    });
}

function updateChartFromCache(container, data) {
    let categories = data.map(item => item.date);
    let values = data.map(item => Math.round(item.count));
    let rewards = data.map(item => parseFloat(((item.total_reward || 0) * currencyRate).toFixed(currencyRounds)));

    updateChart(container, categories, values, rewards);
}

function updateChart(container, categories, values, rewards) {
    let currencyName = "{{ get_Setting('currency_name') }}";
    let theName = "Earned";
    if(container == 'chart2') {
        currencyName = "USD";
        theName = "Deposited";
    }else if(container == 'chart3') {
        theName = "Withdrawn";
    }
    $("#" + container).html('');

    let options = {
        series: [
            { name: "Count", data: values },
            { name: theName, data: rewards }
        ],
        chart: {
            type: "area",
            stacked: false,
            height: 350,
            toolbar: { show: false }
        },
        dataLabels: { enabled: false },
        markers: { size: 0 },
        fill: {
            type: "gradient",
            gradient: {
                shadeIntensity: 1,
                inverseColors: false,
                opacityFrom: 0.35,
                opacityTo: 0.05,
                stops: [20, 100, 100, 100]
            }
        },
        tooltip: {
            shared: true,
            y: {
                formatter: function (value, { seriesIndex }) {
                    if (seriesIndex === 0) {
                        return value.toFixed(0);
                    } else {
                        return value.toLocaleString() + " " + currencyName;
                    }
                }
            }
        },
        legend: { position: "top", horizontalAlign: "left" },
        xaxis: { categories: categories }
    };

    if (window["chartInstance_" + container]) {
        window["chartInstance_" + container].updateOptions(options);
    } else {
        window["chartInstance_" + container] = new ApexCharts(document.getElementById(container), options);
        window["chartInstance_" + container].render();
    }
}

$(document).ready(function () {
    let ajaxRequest;
    let debounceTimer;
    let currentpage = 1;
    let loaded = false;
    let loaded2 = false;
    let loaded3 = false;
    loadChart("chart1", "1", "1");
    loadChart("chart2", "2", "2");
    loadChart("chart3", "3", "3");
    function loadUsers(page = 1, search = '') {
        if (ajaxRequest) {
            ajaxRequest.abort();
        }
        currentpage = page;
        ajaxRequest = $.ajax({
            url: "/admin/referrals/load",
            type: "GET",
            data: { page: page, search: search, uid: {{ $user->id }} },
            dataType: "json",
            beforeSend: function () {
                $("#users-table").html('<tr><td colspan="5" class="text-center py-4"><div class="w-full px-6 py-4"><div class="skeleton animate-wave h-3 w-full rounded bg-slate-150 dark:bg-navy-500"></div><div class="skeleton animate-wave mt-4 h-3 w-8/12 rounded bg-slate-150 dark:bg-navy-500"></div></div></td></tr>');
            },
            success: function (data) {
                loaded = true;
                var html = "";
                if (data.records.length > 0) {
                    data.records.forEach(function (item) {
                      html += `
                        <tr class="border-y border-transparent border-b-slate-200 dark:border-b-navy-500">
                          <td class="whitespace-nowrap px-4 py-3 sm:px-5">
                              <a href="/admin/user/${item.id}" target="_blank" class="text-primary">${item.name}</a>
                          </td>
                          <td class="whitespace-nowrap px-4 py-3 sm:px-5">${item.email}</td>
                          <td class="whitespace-nowrap px-4 py-3 sm:px-5">${item.email_verified_at}</td>
                          <td class="whitespace-nowrap px-4 py-3 sm:px-5">${item.activity_count}</td>
                          <td class="whitespace-nowrap px-4 py-3 sm:px-5">
                            <b>Registered:</b> ${item.ip_address}<br>
                            <b>Last Login:</b> ${item.last_login_ip}<br>
                            <b>Last Activity:</b> ${item.last_activity_ip}<br>
                          </td>
                        </tr>`;
                    });
              } else {
                html = '<tr><td colspan="8" class="text-center py-4">No data available</td></tr>';
              }
              $("#users-table").html(html);
    
            var paginationHtml = `
                <ol class="pagination">
                    <li class="rounded-l-full bg-slate-150 dark:bg-navy-500">
                        <a href="#" class="pagination-btn flex size-8 items-center justify-center rounded-full text-slate-500 transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:text-navy-200 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90" data-page="${data.prev_page}" ${data.prev_page ? "" : "disabled"}>
                            <svg xmlns="http://www.w3.org/2000/svg" class="size-4" fill="none" viewbox="0 0 24 24" stroke="currentColor" stroke-width="2">
                                <path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7"/>
                            </svg>
                        </a>
                    </li>`;
            
            var startPage = Math.max(1, data.current_page - 2);
            var endPage = Math.min(data.total_pages, startPage + 4);
            
            if (startPage > 1) {
                paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">
                    <a href="#" class="pagination-btn flex h-8 min-w-[2rem] items-center justify-center rounded-full px-3 leading-tight transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90" data-page="1">1</a>
                </li>`;
                if (startPage > 2) {
                    paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">...</li>`;
                }
            }
            
            for (var i = startPage; i <= endPage; i++) {
                paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">
                    <a href="#" class="pagination-btn flex h-8 min-w-[2rem] items-center justify-center rounded-full px-3 ${i === data.current_page ? 'bg-primary px-3 leading-tight text-white transition-colors hover:bg-primary-focus focus:bg-primary-focus active:bg-primary-focus/90 dark:bg-accent dark:hover:bg-accent-focus dark:focus:bg-accent-focus dark:active:bg-accent/90' : 'leading-tight transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90'}" data-page="${i}">${i}</a>
                </li>`;
            }
            
            if (endPage < data.total_pages) {
                if (endPage < data.total_pages - 1) {
                    paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">...</li>`;
                }
                paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">
                    <a href="#" class="pagination-btn flex h-8 min-w-[2rem] items-center justify-center rounded-full px-3 leading-tight transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90" data-page="${data.total_pages}">${data.total_pages}</a>
                </li>`;
            }
            
            paginationHtml += `
                <li class="rounded-r-full bg-slate-150 dark:bg-navy-500">
                    <a href="#" class="pagination-btn flex size-8 items-center justify-center rounded-full text-slate-500 transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:text-navy-200 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90" data-page="${data.next_page}" ${data.next_page ? "" : "disabled"}>
                        <svg xmlns="http://www.w3.org/2000/svg" class="size-4" fill="none" viewbox="0 0 24 24" stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
                        </svg>
                    </a>
                </li>
            </ol>`;
            
            $("#pagination").html(paginationHtml);
    
            },
          });
        }
    function loadWd(page = 1) {
      $.ajax({
        url: "/admin/withdrawals/load",
        type: "GET",
        data: { page: page, uid: {{ $user->id }} },
        dataType: "json",
        beforeSend: function () {
            $("#withdrawals").html('<tr><td colspan="6" class="text-center py-4"><div class="w-full px-6 py-4"><div class="skeleton animate-wave h-3 w-full rounded bg-slate-150 dark:bg-navy-500"></div><div class="skeleton animate-wave mt-4 h-3 w-8/12 rounded bg-slate-150 dark:bg-navy-500"></div></div></td></tr>');
        },
        success: function (data) {
            loaded2 = true;
            var html = "";
            if (data.records.length > 0) {
                data.records.forEach(function (item) {
                  html += `
                    <tr id="wdid${item.id}" class="border-y border-transparent border-b-slate-200 dark:border-b-navy-500">
                    <td class="whitespace-nowrap px-4 py-3 sm:px-5">${item.method}</td>
                      <td class="whitespace-nowrap px-4 py-3 sm:px-5">${item.address}</td>
                      <td class="whitespace-nowrap px-4 py-3 sm:px-5">
                          <span class="badge bg-${item.status.color} text-white">
                            ${item.status.text}
                          </span>
                      </td>
                      <td class="whitespace-nowrap px-4 py-3 sm:px-5">${item.crypto}</td>
                      <td class="whitespace-nowrap px-4 py-3 sm:px-5">${item.amount}</td>
                      <td class="whitespace-nowrap px-4 py-3 sm:px-5">${item.fee}</td>
                      <td class="whitespace-nowrap px-4 py-3 sm:px-5">${item.date}</td>
                    </tr>`;
                });
          } else {
            html = '<tr><td colspan="9" class="text-center py-4">No data available</td></tr>';
          }
          $("#withdrawals").html(html);

        var paginationHtml = `
            <ol class="pagination">
                <li class="rounded-l-full bg-slate-150 dark:bg-navy-500">
                    <a href="#" class="pagination-btn2 flex size-8 items-center justify-center rounded-full text-slate-500 transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:text-navy-200 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90" data-page="${data.prev_page}" ${data.prev_page ? "" : "disabled"}>
                        <svg xmlns="http://www.w3.org/2000/svg" class="size-4" fill="none" viewbox="0 0 24 24" stroke="currentColor" stroke-width="2">
                            <path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7"/>
                        </svg>
                    </a>
                </li>`;
        
        var startPage = Math.max(1, data.current_page - 2);
        var endPage = Math.min(data.total_pages, startPage + 4);
        
        if (startPage > 1) {
            paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">
                <a href="#" class="pagination-btn2 flex h-8 min-w-[2rem] items-center justify-center rounded-full px-3 leading-tight transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90" data-page="1">1</a>
            </li>`;
            if (startPage > 2) {
                paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">...</li>`;
            }
        }
        
        for (var i = startPage; i <= endPage; i++) {
            paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">
                <a href="#" class="pagination-btn2 flex h-8 min-w-[2rem] items-center justify-center rounded-full px-3 ${i === data.current_page ? 'bg-primary px-3 leading-tight text-white transition-colors hover:bg-primary-focus focus:bg-primary-focus active:bg-primary-focus/90 dark:bg-accent dark:hover:bg-accent-focus dark:focus:bg-accent-focus dark:active:bg-accent/90' : 'leading-tight transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90'}" data-page="${i}">${i}</a>
            </li>`;
        }
        
        if (endPage < data.total_pages) {
            if (endPage < data.total_pages - 1) {
                paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">...</li>`;
            }
            paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">
                <a href="#" class="pagination-btn2 flex h-8 min-w-[2rem] items-center justify-center rounded-full px-3 leading-tight transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90" data-page="${data.total_pages}">${data.total_pages}</a>
            </li>`;
        }
        
        paginationHtml += `
            <li class="rounded-r-full bg-slate-150 dark:bg-navy-500">
                <a href="#" class="pagination-btn2 flex size-8 items-center justify-center rounded-full text-slate-500 transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:text-navy-200 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90" data-page="${data.next_page}" ${data.next_page ? "" : "disabled"}>
                    <svg xmlns="http://www.w3.org/2000/svg" class="size-4" fill="none" viewbox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
                    </svg>
                </a>
            </li>
        </ol>`;
        
        $("#pagination2").html(paginationHtml);

        },
      });
    }
    function loadDP(page = 1) {
      $.ajax({
        url: "/admin/deposits/load",
        type: "GET",
        data: { page: page, uid: {{ $user->id }} },
        dataType: "json",
        beforeSend: function () {
            $("#deposits").html('<tr><td colspan="6" class="text-center py-4"><div class="w-full px-6 py-4"><div class="skeleton animate-wave h-3 w-full rounded bg-slate-150 dark:bg-navy-500"></div><div class="skeleton animate-wave mt-4 h-3 w-8/12 rounded bg-slate-150 dark:bg-navy-500"></div></div></td></tr>');
        },
        success: function (data) {
            loaded3 = true;
            var html = "";
            if (data.records.length > 0) {
                data.records.forEach(function (item) {
                  html += `
                    <tr id="wdid${item.id}" class="border-y border-transparent border-b-slate-200 dark:border-b-navy-500">
                    <td class="whitespace-nowrap px-4 py-3 sm:px-5">${item.method}</td>
                      <td class="whitespace-nowrap px-4 py-3 sm:px-5">
                          <span class="badge bg-${item.status.color} text-white">
                            ${item.status.text}
                          </span>
                      </td>
                      <td class="whitespace-nowrap px-4 py-3 sm:px-5">${item.txn_id}</td>
                      <td class="whitespace-nowrap px-4 py-3 sm:px-5">$${item.amount}</td>
                      <td class="whitespace-nowrap px-4 py-3 sm:px-5">${item.date}</td>
                    </tr>`;
                });
          } else {
            html = '<tr><td colspan="6" class="text-center py-4">No data available</td></tr>';
          }
          $("#deposits").html(html);

        var paginationHtml = `
            <ol class="pagination">
                <li class="rounded-l-full bg-slate-150 dark:bg-navy-500">
                    <a href="#" class="pagination-btn3 flex size-8 items-center justify-center rounded-full text-slate-500 transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:text-navy-200 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90" data-page="${data.prev_page}" ${data.prev_page ? "" : "disabled"}>
                        <svg xmlns="http://www.w3.org/2000/svg" class="size-4" fill="none" viewbox="0 0 24 24" stroke="currentColor" stroke-width="2">
                            <path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7"/>
                        </svg>
                    </a>
                </li>`;
        
        var startPage = Math.max(1, data.current_page - 2);
        var endPage = Math.min(data.total_pages, startPage + 4);
        
        if (startPage > 1) {
            paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">
                <a href="#" class="pagination-btn3 flex h-8 min-w-[2rem] items-center justify-center rounded-full px-3 leading-tight transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90" data-page="1">1</a>
            </li>`;
            if (startPage > 2) {
                paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">...</li>`;
            }
        }
        
        for (var i = startPage; i <= endPage; i++) {
            paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">
                <a href="#" class="pagination-btn3 flex h-8 min-w-[2rem] items-center justify-center rounded-full px-3 ${i === data.current_page ? 'bg-primary px-3 leading-tight text-white transition-colors hover:bg-primary-focus focus:bg-primary-focus active:bg-primary-focus/90 dark:bg-accent dark:hover:bg-accent-focus dark:focus:bg-accent-focus dark:active:bg-accent/90' : 'leading-tight transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90'}" data-page="${i}">${i}</a>
            </li>`;
        }
        
        if (endPage < data.total_pages) {
            if (endPage < data.total_pages - 1) {
                paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">...</li>`;
            }
            paginationHtml += `<li class="bg-slate-150 dark:bg-navy-500">
                <a href="#" class="pagination-btn3 flex h-8 min-w-[2rem] items-center justify-center rounded-full px-3 leading-tight transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90" data-page="${data.total_pages}">${data.total_pages}</a>
            </li>`;
        }
        
        paginationHtml += `
            <li class="rounded-r-full bg-slate-150 dark:bg-navy-500">
                <a href="#" class="pagination-btn3 flex size-8 items-center justify-center rounded-full text-slate-500 transition-colors hover:bg-slate-300 focus:bg-slate-300 active:bg-slate-300/80 dark:text-navy-200 dark:hover:bg-navy-450 dark:focus:bg-navy-450 dark:active:bg-navy-450/90" data-page="${data.next_page}" ${data.next_page ? "" : "disabled"}>
                    <svg xmlns="http://www.w3.org/2000/svg" class="size-4" fill="none" viewbox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
                    </svg>
                </a>
            </li>
        </ol>`;
        
        $("#pagination3").html(paginationHtml);

        },
      });
    }
    $('#ref').click(function() {
        if(!loaded) {
            loadUsers();
        }
    });
    $('#wd').click(function() {
        if(!loaded2) {
            loadWd();
        }
    });
    $('#dp').click(function() {
        if(!loaded3) {
            loadDP();
        }
    });
    $(document).on("click", ".pagination-btn", function (e) {
      e.preventDefault();
      var page = $(this).data("page");
      if (page) loadUsers(page);
    });
    $(document).on("click", ".pagination-btn2", function (e) {
      e.preventDefault();
      var page = $(this).data("page");
      if (page) loadWd(page);
    });
    $(document).on("click", ".pagination-btn3", function (e) {
      e.preventDefault();
      var page = $(this).data("page");
      if (page) loadDP(page);
    });
    $("#search").on("keyup", function() {
        $("#users-table").html('<tr><td colspan="8" class="text-center py-4"><div class="w-full px-6 py-4"><div class="skeleton animate-wave h-3 w-full rounded bg-slate-150 dark:bg-navy-500"></div><div class="skeleton animate-wave mt-4 h-3 w-8/12 rounded bg-slate-150 dark:bg-navy-500"></div></div></td></tr>');
        clearTimeout(debounceTimer);
        let query = $(this).val();
        debounceTimer = setTimeout(() => {
            loadUsers(1, query);
        }, 1000);
    });
});
function handleEventTypeChange(type) {
    loadChart("chart" + type, type, type);
}
    function updateBalance(type, action, amount) {
        let theme = localStorage.getItem("_x_darkMode_on") === "true" ? "dark" : "light";
        $.ajax({
            url: '/admin/user/update-balance/{{ $user->id }}',
            method: 'POST',
            data: {
                _token: "{{ csrf_token() }}",
                type: type,
                action: action,
                amount: amount
            },
            success: function(response) {
                $("#userbalance").html(response.balance);
                $("#userdeposit").html(response.deposit);
                $("#userearned").html(response.earned);
                let swalOptions = {
                    icon: "success",
                    title: "Success!",
                    html: `<p>${response.message}</p>`,
                    toast: true,
                    position: "bottom-end",
                    showConfirmButton: false,
                    customClass: {
                        popup: "toast-popup",
                        title: "toast-title",
                        content: "toast-content"
                    },
                    showCloseButton: true,
                    closeButtonHtml: "<i class='fas fa-times'></i>"
                };
                        
                if (theme === "dark") {
                    swalOptions.background = "#1E293B";
                    swalOptions.color = "#F8FAFC";
                    swalOptions.confirmButtonColor = "#4F46E5";
                }

                Swal.fire(swalOptions);

            },
            error: function(xhr) {
                alert(xhr.responseJSON.message || 'Something went wrong!');
            }
        });
    }

    $('#addBalanceBtn').click(function() {
        let amount = $('#accountAmount').val();
        updateBalance('account', 'add', amount);
    });

    $('#reduceBalanceBtn').click(function() {
        let amount = $('#accountAmount').val();
        updateBalance('account', 'reduce', amount);
    });

    $('#addDepositBtn').click(function() {
        let amount = $('#depositAmount').val();
        updateBalance('deposit', 'add', amount);
    });

    $('#reduceDepositBtn').click(function() {
        let amount = $('#depositAmount').val();
        updateBalance('deposit', 'reduce', amount);
    });
</script>
@endpush
</x-admin-layout>