@extends('user_type.auth', ['parentFolder' => '', 'childFolder' => ''])

@section('content')
<div class="row">
  <div class="col-12">
    <div class="card">
      <!-- Card header -->
      <div class="card-header pb-0">
        <div class="d-lg-flex">
          <div>
            <h5 class="mb-0">Payment Records</h5>
          
          <div class="ms-auto my-auto mt-lg-0 mt-4">
            <label class="text-sm  mt-4">Sort Transaction By Subscrition Type: </label>
                <select class="form-control"  onchange="javascript:location.href = this.value;">
                    <option value="/subscriptions/approved?type=1" {{ (request()->get('type') == '1' ) ? 'selected' : ''}} >Approved Payment</option>
                    <option value="/subscriptions/approved?type=2" {{ (request()->get('type') == '2' ) ? 'selected' : ''}} >Rejected Payment</option>
                    
            </select>   
            </div>
          </div>
        </div>
      </div>
      <div class="card-body px-0 pb-0">
        <div class="table-responsive">
          @if($errors->get('msgError'))
          <div class="m-3  alert alert-warning alert-dismissible fade show" role="alert">
            <span class="alert-text text-white">
              {{$errors->first()}}</span>
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
              <i class="fa fa-close" aria-hidden="true"></i>
            </button>
          </div>
          @endif
          @if(session('success'))
          <div class="m-3  alert alert-success alert-dismissible fade show" id="alert-success" role="alert">
            <span class="alert-text text-white">
              {{ session('success') }}</span>
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
              <i class="fa fa-close" aria-hidden="true"></i>
            </button>
          </div>
          @endif
          <table class="table table-flush" id="data-list">
            <thead class="thead-light">
              <tr>
                <th>SELECT</th>
                <th>USER NAME</th>
                <th>SUBSCRIPTION PACKAGE</th>
                <th>TRANSACTION ID</th>
                <th>PAYMENT PROOF</th>
                <th>PAYMENT MODE</th>
                <th>REMARK</th>
                <th>SUBMIT DATE</th>
                <th>UPDATE DATE</th>
                <th>STATUS</th>
                <th>ACTION</th>
              </tr>
            </thead>
            <tbody>
              @if(count($data) > 0)
              @foreach($data as $item)
              <tr id="{{$item->id}}">
                <td class="text-sm">
                  <div class="form-check my-auto">
                  <input class="form-check-input sub_chk" type="checkbox" id="customCheck1" data-id="{{$item->id}}" value="{{$item->id}}">
                  </div>
                </td>
                <td class="text-sm"><a href="{{ url('/user-track/' . $item->user_id) }}" target="_blank" class="text-info text-bold">{{$item->name}}</a></td>
                <td class="text-sm"><span class="badge bg-primary">{{$item->modal_info}}</span></td>
                <td class="text-sm">{{$item->transaction_id}}</td>
                <td class="text-sm">{{$item->payment_modal}}</td>
                <td class="text-sm"><a href="{{ url('images/payment/'.$item->image) }}" target="_blank"><img class="img-square" width="100" height="200" src="{{ url('images/payment/'.$item->image) }}"/></a></td>
                <td class="text-sm">{{$item->remark}}</td>
                <td class="text-sm">{!!date('d-M-y H:i:s',strtotime($item->created_at))!!}</td>
                <td class="text-sm">{!!date('d-M-y H:i:s',strtotime($item->updated_at))!!}</td>
                 <td class="text-sm" >
                  @if($item->status==1)
                  <span class="badge bg-success">Approved</span>
                  @elseif($item->status==2)
                  <span class="badge bg-danger">Rejected</span>
                  @endif
                </td>
                <td class="text-sm">
                  <a href="{{ url('user-track/' . $item->user_id) }}"  target="_blank" class="mx-3" data-bs-toggle="tooltip" data-bs-original-title="Track User">
                    <i class="fas fa-chart-line text-info"></i>
                  </a>
                  
                </td>
              </tr>
              @endforeach
              @else
              <tr>no content </tr>
              @endif
            </tbody>
          </table>
         
          {{$data->links('components.paginate')}}
        </div>
      </div>
    </div>
  </div>
</div>
@include('modal')
@endsection
@push('js')
<script src="{{ URL::asset('assets/js/plugins/datatables.js') }}"></script>
<script src="../../assets/js/plugins/sweetalert.min.js"></script>
<script src="../../assets/js/plugins/action.js"></script>
<script src="../../assets/js/plugins/modal.js"></script>
<script>
  if (document.getElementById('data-list')) {
    const dataTableSearch = new simpleDatatables.DataTable("#data-list", {
      searchable: true,
      fixedHeight: true,
      perPage: 15,
      labels: {
        placeholder: "Search...",
        perPage: "Show {select} entries",
        noRows: "No entries found",
        info: "Showing {{ $data->firstItem() }} to {{$data->lastItem()}} of {{$data->total()}} entries"
      },
    });

    document.querySelectorAll(".export").forEach(function(el) {
      el.addEventListener("click", function(e) {
        var type = el.dataset.type;

        var data = {
          type: type,
          filename: "alias-" + type,
        };

        if (type === "csv") {
          data.columnDelimiter = "|";
        }

        dataTableSearch.export(data);
      });
    });
  };
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
  $(document).ready(function() {
    $("#alert-success").delay(3000).slideUp(300);

  });


</script>
@endpush