@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>Status</h3>
        </div>
        <div class="col-sm-5">
          <div class="pull-right">
            <div class="input-group">
                <input class="form-control" id="search"
                       value="{{ request()->session()->get('search') }}"
                       onkeydown="if (event.keyCode == 13) ajaxLoad('{{url('status')}}?search='+this.value)"
                       placeholder="Buscar" name="search"
                       type="text" id="search"/>
                <div class="input-group-btn">
                    <a href="{{url('status')}}">
                    <button type="submit" class="btn btn-primary"
                            onclick="ajaxLoad('{{url('/status')}}?search='+$('#search').val())">
                            <i class="fa fa-search" aria-hidden="true"></i>
                    </button>
                    </a>
                </div>
            </div>
          </div>
        </div>
    </div>
    <table class="table">
        <thead>
        <tr>
            <th style="vertical-align: middle"><a href="{{url('status?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('status?field=name&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Nombre</a></th>
                {{request()->session()->get('field')=='name'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th width="160px" style="vertical-align: middle">
              <a href="{{url('status/create')}}"
                 class="btn btn-primary btn-xs"> <i class="fa fa-plus" aria-hidden="true"></i> Nuevo Status</a>
            </th>

        </tr>
        </thead>
        <tbody>
        @php
            $i=1;
        @endphp
        @foreach ($status as $statu)
          <tr>
            <th>{{ $statu->id }}</th>
            <td>{{ $statu->name }}</td>
            <td>
              <a class="btn btn-secondary btn-xs" title="Edit"
                href="{{url('status/update/'.$statu->id)}}">
                <i class="fa fa-pencil"></i>
                </a>
              <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 este status?')) javascript:if(confirm('Usualmente no se deben eliminar status, solo editarlas ¿Estás seguro?')) ajaxDelete('{{url('status/delete/'.$statu->id)}}','{{csrf_token()}}')">
                   <i class="fa fa-trash"></i>
                </a>
            </td>
        </tr>
        @endforeach

        </tbody>
    </table>

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