@extends('layouts.app')

@section('content')
  @if (Auth::user()->role_id >= 5)
    <div class="container-fluid" style="height:100%">
    @include('sidebar')
    <div style="width:90%; float: left; margin:1em 0 0 1em">
  @else
    <div class="container" style="margin:0 1em">
  @endif

    <div class="row">
        <div class="col-sm-7">
          <h3>Tarjetas</h3>
        </div>
        <div class="col-sm-5">
          <div class="pull-right">
            {!! Form::open(['method'=>'GET','url'=>'cards','class'=>'navbar-form navbar-left','role'=>'search'])  !!}
            <div class="input-group">
                <input class="form-control" id="search"
                       value="{{ request()->session()->get('search') }}"
                       placeholder="Buscar" name="search"
                       type="text" id="search"/>
                <div class="input-group-btn">
                    <button type="submit" class="btn btn-primary">
                            <i class="fa fa-search" aria-hidden="true"></i>
                    </button>
                </div>
            </div>
            {!! Form::close() !!}
          </div>
        </div>
    </div>
    <table class="table">
        <thead>
        <tr>
            <th style="vertical-align: middle"><a href="{{url('cards?field=id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">ID</a></th>
                {{request()->session()->get('field')=='id'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('cards?field=user_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Usuario</a></th>
                {{request()->session()->get('field')=='user_id'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('cards?field=user_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Openpay ID</a></th>
                {{request()->session()->get('field')=='user_id'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('cards?field=token&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Token</a></th>
                {{request()->session()->get('field')=='token'?(request()->session()->get('sort')=='asc'?'':''):''}}

        </tr>
        </thead>
        <tbody>
        @php
            $i=1;
        @endphp
        @foreach ($cards as $card)
          <tr>
            <th>{{ $card->id }}</th>
            <th>{{ $card->user->name }}</th>
            <td>{{ $card->user->openpay_id }}</td>
            <td>{{ $card->token}}</td>
            <td>
              <input type="hidden" name="_method" value="delete"/>
                <a class="btn btn-danger btn-xs" title="Delete"
                   href="javascript:if(confirm('¿Estás seguro de que quieres eliminar esta tarjeta?')) javascript:if(confirm('Usualmente no se deben eliminar tarjetas, ¿Estás seguro?')) ajaxDelete('{{url('cards/delete/'.$card->id)}}','{{csrf_token()}}')">
                   <i class="fa fa-trash"></i>
                </a>
            </td>
        </tr>
        @endforeach

        </tbody>
    </table>

        <ul class="pagination">
            {{ $cards->links() }}
        </ul>
</div>
@endsection
