@php
  $records = $records ?? collect();
  $viewMode = $viewMode ?? 'pending';
@endphp

<div class="table-responsive">
  <table class="table table-striped table-hover" id="tableExport" style="width:100%;">
    <thead>
      <tr>
        <th>S.No.</th>
        <th>User Name</th>
        <th>Withdraw Amount</th>
        <th>Payment Method</th>
        <th>UPI / Mobile</th>
        <th>Created</th>
        <th>Action</th>
      </tr>
    </thead>
    <tbody>
      @forelse($records as $withdrawRecord)
        <tr>
          <td>{{ $loop->iteration }}</td>
          <td>{{ $withdrawRecord->username }}</td>
          <td>Rs. {{ number_format((float) $withdrawRecord->withdrawamt, 2) }}</td>
          <td>{{ $withdrawRecord->paymenttype ?: '-' }}</td>
          <td>{{ $withdrawRecord->mobilenumber ?: '-' }}</td>
          <td>{{ optional($withdrawRecord->createdtime)->format('d M Y h:i A') ?? '-' }}</td>
          <td>
            @if($viewMode === 'pending')
              <form action="{{ route('admin.changewithdrawstatus', ['id' => $withdrawRecord->id]) }}" method="post" class="d-inline-block">
                @csrf
                <input type="hidden" name="status" value="1">
                <button type="submit" class="btn btn-success btn-sm deletedata" data-toggle="tooltip" data-placement="top" title="Approve Withdraw" data-confirm-message="Are you sure you want to approve this withdraw request?">
                  <i class="fas fa-check"></i>
                </button>
              </form>
              <form action="{{ route('admin.changewithdrawstatus', ['id' => $withdrawRecord->id]) }}" method="post" class="d-inline-block">
                @csrf
                <input type="hidden" name="status" value="3">
                <button type="submit" class="btn btn-danger btn-sm deletedata" data-toggle="tooltip" data-placement="top" title="Decline Withdraw" data-confirm-message="Are you sure you want to cancel this withdraw request?">
                  <i class="fas fa-times"></i>
                </button>
              </form>
            @elseif($viewMode === 'accepted')
              <form action="{{ route('admin.changewithdrawstatus', ['id' => $withdrawRecord->id]) }}" method="post" class="d-inline-block">
                @csrf
                <input type="hidden" name="status" value="3">
                <button type="submit" class="btn btn-danger btn-sm deletedata" data-toggle="tooltip" data-placement="top" title="Decline Withdraw" data-confirm-message="Are you sure you want to cancel this withdraw request?">
                  <i class="fas fa-times"></i>
                </button>
              </form>
            @else
              <form action="{{ route('admin.changewithdrawstatus', ['id' => $withdrawRecord->id]) }}" method="post" class="d-inline-block">
                @csrf
                <input type="hidden" name="status" value="1">
                <button type="submit" class="btn btn-success btn-sm deletedata" data-toggle="tooltip" data-placement="top" title="Approve Withdraw" data-confirm-message="Are you sure you want to approve this withdraw request?">
                  <i class="fas fa-check"></i>
                </button>
              </form>
            @endif
          </td>
        </tr>
      @empty
        <tr>
          <td colspan="7" class="text-center text-muted">No withdraw requests found in this status.</td>
        </tr>
      @endforelse
    </tbody>
  </table>
</div>
