@extends('admin.layouts.main-layout')
@section('css-content')
<style>
.deposit-summary{
    margin-bottom:30px;
}

.summary-main-card{
    background:#2f76ea;
    color:#fff;
    padding:25px;
    border-radius:6px;
    box-shadow:0 2px 8px rgba(0,0,0,.12);
}

.summary-title{
    font-size:18px;
    font-weight:600;
}

.summary-amount{
    font-size:38px;
    font-weight:700;
    margin:5px 0;
}

.summary-count{
    font-size:14px;
    opacity:.9;
}

.summary-box{
    background:#fff;
    border-radius:6px;
    padding:20px;
    box-shadow:0 2px 8px rgba(0,0,0,.12);
    height:100%;
}

.summary-box h5{
    margin-bottom:10px;
    font-size:16px;
    font-weight:600;
}

.summary-box h3{
    margin-bottom:10px;
    font-size:30px;
    font-weight:700;
}

.summary-box p{
    margin:0;
    color:#6c757d;
}
</style>
@endsection
 @section('content')
<div class="card mx-auto">
      
        <?php
$date = dateYYYYMMDD(request('date')) ?? '';
?>
        <!-- /.card-header -->
        <div class="card-body">
            
            
                  @php
                    $totalAmount = $lists->sum('amount');
                    $totalTransactions = $lists->count();
                
                    $manualAmount = $lists->filter(function ($item) {
                        return stripos($item->remark, 'admin') !== false;
                    })->sum('amount');
                
                    $manualCount = $lists->filter(function ($item) {
                        return stripos($item->remark, 'admin') !== false;
                    })->count();
                
                    $autoAmount = $lists->filter(function ($item) {
                        return stripos($item->remark, 'admin') === false;
                    })->sum('amount');
                
                    $autoCount = $lists->filter(function ($item) {
                        return stripos($item->remark, 'admin') === false;
                    })->count();
                @endphp
                
                <div class="deposit-summary mb-4">
                
                    <div class="d-flex justify-content-between align-items-center mb-3 mx-5">
                        <h4 class="mb-0">Fund Requests</h4>
                    
                    @php
                        $defaultDateRange =
                            request('date_range') ??
                            now()->startOfMonth()->format('m/d/Y') . ' - ' .
                            now()->endOfMonth()->format('m/d/Y');
                    @endphp
                        <form method="GET" id="filterForm">
                             <div class="d-flex gap-2">
                            <input type="text"
                                   name="date_range"
                                   id="date_range"
                                   value="{{ $defaultDateRange }}"
                                   class="form-control"
                                   style="width: 250px;">
                                   
                                </div>
                        </form>
                    </div>
                
                    
                
                </div>
            
            <div id="example1_wrapper" class=" dt-bootstrap4">
                <div class="row">
                    <div class="col-sm-12">
                          <div class='tablescroll'>
                            <div class="table-responsive">
                        <table class="table table-bordered text-center">
                <thead>
                   <tr role="row">
                                <th class="sorting_asc" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-sort="ascending"
                                    aria-label="Rendering engine: activate to sort column descending"
                                    style="width: 60px;">S.No
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                    Mobile Number
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                    UserName
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                    Deposit Mode
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                    Amount
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                    Transaction ID
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                    Date
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                    Action
                                </th>
                                
                               
                            </tr>
                </thead>
                <tbody>
                             
                  @forelse($lists as $key => $list)
                
                        <tr>
                          <td>{{ $key+1 }}</td>
                          <td>
                            <a>{{isset($list->username) ? $list->username->mobile_number : ''}}</a>
                          </td>
                          <td>
                            <a>{{isset($list->username) ? $list->username->name : ''}}</a>
                          </td>
                          <td>
                                @if(isset($list->order_id))
                                <a>Payment Gateway</a>
                                @else
                                <a>Manual</a>
                                @endif
                            
                                 
                          </td>
                         
                          <td>
                                
                            <a>{{$list->amount}}</a>
                                 
                          </td>
                         
                          <td>
                                
                            <a>{{$list->order_id}}</a>
                                 
                          </td>
                          <td>
                          {{$list->created_at}}
                          </td>
                          </td>
                             <td>
                             <button type="button" class="btn btn-info btn-lg" data-toggle="modal" onclick="openModal({{$list->id}})">Change Status</button>

                          </td>
                        
                        </tr>
                         @empty
                  <tr>
                    <td colspan="6">Record not found </td>
                  </tr>
                  @endforelse
                            </tbody>
            </table>

                   </div>
                   </div>
                    <div class="row">
              <div class="col-md-6 text-left" style="margin: 20px 0px;">
                Showing  {{$lists->firstItem()}} to {{$lists->lastItem()}} of {{$lists->total()}}
              </div>
              <div class="col-md-6 text-right">
                {!! $lists->appends(request()->input())->links() !!}
              </div>
            </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          
          
          <!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
     <!--  <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div> -->
      <div class="modal-body">
       <div class="container">
        <div class="justify-content-center">
            <div class="">
                <div class="card">
                    <div class="card-header">Fund Request <button type="button" class="close" data-dismiss="modal">&times;</button></div>
                    <div class="card-body">
                        @if ($errors->any())
                            <div class="alert alert-danger">
                                <ul>
                                    @foreach ($errors->all() as $error)
                                        <li>{{ $error }}</li>
                                    @endforeach
                                </ul>
                            </div>
                        @endif
                        <form method="post" action="{{ url('/admin/fund') }}" autocomplete="off" enctype="multipart/form-data">
                            @csrf
                            
                            <div class="form-group">
                                <label for="title">Are you sure you want to accept the fund?</label>
                            </div>

                          
                            <br>
                            <input type="hidden" name="fund_id" value=""> 
                            <div class="form-group">
                                <button type="submit"  class="btn btn-primary" name="type" value="accept">Accept</button>
                                <button type="submit"  class="btn btn-danger" name="type"  value="reject" >Reject</button>
                            </div>

                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>


 @endsection
@section('js-content')

<script>
$(function () {

    $('#date_range').daterangepicker({
        autoUpdateInput: false,
        locale: {
            cancelLabel: 'Clear',
            format: 'MM/DD/YYYY'
        },
        ranges: {
           'Today': [moment(), moment()],
           'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
           'Last 7 Days': [moment().subtract(6, 'days'), moment()],
           'Last 30 Days': [moment().subtract(29, 'days'), moment()],
           'This Month': [moment().startOf('month'), moment().endOf('month')],
           'Last Month': [
               moment().subtract(1, 'month').startOf('month'),
               moment().subtract(1, 'month').endOf('month')
           ]
        }
    });

    $('#date_range').on('apply.daterangepicker', function(ev, picker) {
        $(this).val(
            picker.startDate.format('MM/DD/YYYY') + ' - ' +
            picker.endDate.format('MM/DD/YYYY')
        );

        $('#filterForm').submit();
    });

    $('#date_range').on('cancel.daterangepicker', function(ev, picker) {
        $(this).val('');
        $('#filterForm').submit();
    });

});

 function openModal(id){
  $('input[name="fund_id"]').val(id);
    $('#myModal').modal();
} 
</script>
@endsection