
  @if (Auth::user()->role_id >= 5)
    <div class="container-fluid" style="height:100%">
    <div>
  @else
    <div class="container" style="margin:0 1em">
  @endif

    <div class="row">
        <div class="col-sm-7">
          <h3>Postulaciones</h3>
        </div>
        <div class="col-sm-5">
          <a class="btn btn-secondary btn-xs" title="Ver en Mapa"
            href="{{url('postulations/map')}}">
            <i class="fa fa-map"></i>  Ver en Mapa
          </a>
          <div class="pull-right">
            {!! Form::open(['method'=>'GET','url'=>'postulation','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('postulations?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('postulations?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('postulations?field=category_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Categoría</a></th>
                {{request()->session()->get('field')=='category_id'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('postulations?field=address&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Dirección</a></th>
                {{request()->session()->get('field')=='address'?(request()->session()->get('sort')=='asc'?'':''):''}}

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

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

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

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

            <th style="vertical-align: middle"><a href="{{url('postulations?field=created_at&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Fecha de creación</a></th>
                {{request()->session()->get('field')=='created_at'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('postulations?field=updated_at&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Ultimo incio de sesión</a></th>
                {{request()->session()->get('field')=='updated_at'?(request()->session()->get('sort')=='asc'?'':''):''}}

        </tr>
        </thead>
        <tbody>
        @php
            $i=1;
        @endphp
        @foreach ($postulations as $postulation)
          <tr>
            <th>{{ $postulation->id }}</th>
            <td>{{ $postulation->user->name ?? null }}</td>
            <td>{{ $postulation->categories->name ?? null }}</td>
            <td>{{ $postulation->address }}</td>
            <td>{{ $postulation->references }}</td>
            <td>{{ $postulation->appointment }}</td>
            <td>${{ $postulation->amount }}</td>
            <td>{{ $postulation->details }}</td>
            <td>{{ $postulation->created_at }}</td>
            <td>{{ $postulation->updated_at }}</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 postulación?')) javascript:if(confirm('Usualmente no se deben eliminar postulaciones, ¿Estás seguro?')) ajaxDelete('{{url('postulations/delete/'.$postulation->id)}}','{{csrf_token()}}')">
                   <i class="fa fa-trash"></i>
                </a>
            </td>
        </tr>
        @endforeach

        </tbody>
    </table>

        {{ $postulations->links() }}
</div>
