<!DOCTYPE html>
<html lang="en">
<head> 
  <meta charset="UTF-8"> 
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"> 
  <title>{{env('APP_NAME')}} | Record</title> 

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui@2.8.17/dist/css/layui.css">
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">

  <style>
    :root {
      --accent-black: #1a1a1a;
      --accent-gradient: linear-gradient(135deg, #1a1a1a 0%, #3a3a3a 100%);
      --bg-light: #f8fafc;
      --text-dark: #1e293b;
      --status-success: #22c55e;
      --status-pending: #f59e0b;
      --status-failed: #ef4444;
    }

    * {
      box-sizing: border-box;
    }

    body {
      font-family: 'Inter', sans-serif;
      background-color: var(--bg-light);
      margin: 0; padding: 0;
      color: var(--text-dark);
      padding-bottom: 30px;
      animation: fadeInBody 0.5s ease;
    }

    @keyframes fadeInBody {
      from { opacity: 0; }
      to { opacity: 1; }
    }

    @keyframes fadeInUp {
      from { opacity: 0; transform: translateY(15px); }
      to { opacity: 1; transform: translateY(0); }
    }

    @keyframes fadeIn {
      from { opacity: 0; }
      to { opacity: 1; }
    }

    @keyframes slideDown {
      from { opacity: 0; transform: translateY(-12px); }
      to { opacity: 1; transform: translateY(0); }
    }

    /* 🔹 Header */
    .top-header {
      padding: 15px 20px;
      background: #fff;
      display: flex;
      align-items: center;
      position: sticky; top: 0; z-index: 100;
      border-bottom: 1px solid #e2e8f0;
      animation: slideDown 0.4s ease both;
    }
    .top-header h2 { flex: 1; text-align: center; font-size: 18px; font-weight: 700; margin: 0; color: #1e293b; }
    .back-btn {
      color: var(--text-dark); font-size: 20px; text-decoration: none; width: 40px;
      transition: transform 0.2s ease;
      display: inline-block;
    }
    .back-btn:hover { transform: translateX(-3px); }

    /* 🔹 Modern Tabs */
    .record-tab {
      display: flex;
      background: #fff;
      padding: 5px 15px;
      margin-bottom: 15px;
      justify-content: space-around;
      animation: fadeInUp 0.4s ease 0.05s both;
    }
    .record-tab a {
      text-decoration: none;
      color: #64748b;
      font-size: 14px;
      font-weight: 600;
      padding: 12px 5px;
      position: relative;
      transition: 0.3s;
    }
    .record-tab a.active {
      color: var(--accent-black);
    }
    .record-tab a.active::after {
      content: "";
      position: absolute;
      bottom: 0; left: 0; right: 0;
      height: 3px;
      background: var(--accent-black);
      border-radius: 10px;
      animation: fadeIn 0.25s ease both;
    }

    /* 🔹 List Cards */
    .history-main { padding: 0 15px; }
    .history-list { animation: fadeIn 0.35s ease both; }

    .list-card {
      background: #fff;
      border-radius: 16px;
      padding: 16px;
      margin-bottom: 12px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.02);
      display: flex;
      justify-content: space-between;
      align-items: center;
      border: 1px solid transparent;
      transition: 0.2s;
      animation: fadeInUp 0.35s ease both;
    }
    .list-card:hover {
      transform: translateY(-2px);
      box-shadow: 0 8px 18px rgba(0,0,0,0.06);
    }
    .list-card:active { transform: scale(0.98); background: #fcfdfe; }

    .card-left h3 { font-size: 14px; font-weight: 600; margin: 0 0 4px; color: #334155; }
    .card-left p { font-size: 11px; color: #94a3b8; margin: 0; }

    .card-right { text-align: right; }
    .amount { font-size: 16px; font-weight: 800; display: block; margin-bottom: 5px; }
    .amount.plus { color: var(--status-success); }
    .amount.minus { color: var(--text-dark); }

    /* 🔹 Status Pills */
    .status-pill {
      font-size: 10px;
      font-weight: 700;
      padding: 3px 10px;
      border-radius: 50px;
      text-transform: uppercase;
    }
    .pill-success { background: #f0fdf4; color: var(--status-success); border: 1px solid #bbfcbd; }
    .pill-pending { background: #fffbeb; color: var(--status-pending); border: 1px solid #fde68a; }
    .pill-failed { background: #fef2f2; color: var(--status-failed); border: 1px solid #fee2e2; }

    /* Empty State */
    .empty-box {
      text-align: center;
      padding: 50px 20px;
      color: #94a3b8;
      animation: fadeInUp 0.4s ease both;
    }
    .empty-box i { font-size: 40px; margin-bottom: 10px; display: block; opacity: 0.3; }
  </style>
</head>

<body>

<div class="top-header">
  <a href="{{route('dashboard')}}" class="back-btn"><i class="fa-solid fa-chevron-left"></i></a>
  <h2>Transaction Records</h2>
</div>

<div class="record-tab">
  <a href="javascript:void(0);" class="active" data-tab="account">Account</a>
  <a href="javascript:void(0);" data-tab="recharge">Recharge</a>
  <a href="javascript:void(0);" data-tab="withdraw">Withdraw</a>
</div>

<div class="history-main">
  
  <div class="history-list" id="account">
    @forelse(\App\Models\UserLedger::where('user_id', auth()->id())->orderByDesc('id')->get() as $element)
    <div class="list-card">
      <div class="card-left">
        <h3>{{ $element->remark }}</h3>
        <p>{{ $element->created_at->format('Y-m-d H:i') }}</p>
      </div>
      <div class="card-right">
        <span class="amount {{ $element->amount >= 0 ? 'plus' : 'minus' }}">
          {{ $element->amount >= 0 ? '+' : '-' }}{{ price(abs($element->amount)) }}
        </span>
      </div>
    </div>
    @empty
    <div class="empty-box"><i class="fa-solid fa-folder-open"></i>No records found</div>
    @endforelse
  </div>

  <div class="history-list" id="recharge" style="display:none;">
    @forelse(\App\Models\Deposit::where('user_id', auth()->id())->orderByDesc('id')->get() as $element)
    <div class="list-card">
      <div class="card-left">
        <h3>Deposit Balance</h3>
        <p>{{ $element->created_at->format('Y-m-d H:i') }}</p>
      </div>
      <div class="card-right">
        <span class="amount plus">+{{ price($element->amount) }}</span>
        <span class="status-pill 
          @if($element->status == 'success') pill-success
          @elseif($element->status == 'pending') pill-pending
          @else pill-failed
          @endif">
          {{ $element->status }}
        </span>
      </div>
    </div>
    @empty
    <div class="empty-box"><i class="fa-solid fa-folder-open"></i>No deposits found</div>
    @endforelse
  </div>

  <div class="history-list" id="withdraw" style="display:none;">
    @forelse(\App\Models\Withdrawal::where('user_id', auth()->id())->orderByDesc('id')->get() as $element)
    <div class="list-card">
      <div class="card-left">
        <h3>Withdrawal Request</h3>
        <p>{{ $element->created_at->format('Y-m-d H:i') }}</p>
      </div>
      <div class="card-right">
        <span class="amount minus">-{{ price($element->amount) }}</span>
        <span class="status-pill 
          @if($element->status == 'success') pill-success
          @elseif($element->status == 'pending') pill-pending
          @else pill-failed
          @endif">
          {{ $element->status }}
        </span>
      </div>
    </div>
    @empty
    <div class="empty-box"><i class="fa-solid fa-folder-open"></i>No withdrawals found</div>
    @endforelse
  </div>

</div>

<script>
  // Tab Switching Logic
  document.querySelectorAll('.record-tab a').forEach(tab => {
    tab.addEventListener('click', function() {
      // Remove active class from all tabs
      document.querySelectorAll('.record-tab a').forEach(a => a.classList.remove('active'));
      // Hide all lists
      document.querySelectorAll('.history-list').forEach(list => list.style.display = "none");
      
      // Add active to clicked tab
      this.classList.add('active');
      // Show relevant list
      const target = this.dataset.tab;
      document.getElementById(target).style.display = "block";
    });
  });
</script>

</body>
</html>
