@extends('layouts.client')

@section('content')
    @if($user->isAdmin() || $user->isApplicant())
    <div class="container">
        <div class="row" style="width:100%;">
            <div class="col-md-10 col-md-offset-1">

                @if(session()->has('message'))
                    <div class="alert alert-success alert-dismissable">
                        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>

                        {{ session()->get('message') }}
                    </div>
                @endif
                @if ($errors->any())
                    <div class="alert alert-danger">
                        <ul>
                            @foreach ($errors->all() as $error)
                                <li>{{ $error }}</li>
                            @endforeach
                        </ul>
                    </div>
                @endif

                <div class="panel panel-default">



                    <div class="panel-heading">Panel de {{ $user->name }} {{ $user->surname }}</div>

                    <div class="panel-body">

                            @if (is_countable($profiles))
                            <table class="table" id="table1" class="large-only table table-condensed">
                                <thead>
                                <tr>
                                    <th>Nombre</th>
                                    <th>Área/Departamento/Carrera/Posgrado</th>
                                    <th>Email</th>
                                    <th>Acciones</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($profiles as $profile)
                                    <tr>

                                        <td>{{ $profile->name }} {{ $profile->surname }}</td>
                                        <td>{{ $profile->area }} </td>
                                        <td>{{ $profile->email }} </td>
                                        <td>
                                            <div style="display: flex">
                                                @if($profile->userCreateProfile() || $user->isAdmin() )
                                                    <form style="margin-bottom:0;width:27%;" action="{{ URL::to('/') }}/profile/{{$profile->id}}/edit">
                                                        <input class="btn btn-primary btn-xs" type="submit" value="Editar"></input>
                                                    </form>

                                                {{--<form  style="margin-bottom:0;width:33%;"action="{{ URL::to('/') }}/profile/delete" method="post">--}}
                                                    {{--<input type="hidden" name="_token" value="{{ csrf_token() }}">--}}
                                                    {{--<input type="hidden" name="id" value="{{ $profile->id }}">--}}

                                                    {{--<input  style="margin-left: 1.2em" class="btn btn-primary btn-xs"type="submit" value="Borrar" />--}}

                                                {{--</form>--}}
                                                @endif

                                            </div>
                                        </td>


                                    </tr>


                                @endforeach

                                </tbody>
                            </table>

                        @else
                            No existen perfiles disponibles
                        @endif


                    </div>
                </div>
            </div>
        </div>
    </div>
    @else
        <div class="container">
            <div class="row" style="width:100%;">
                <div class="col-md-10 col-md-offset-1">
                    <div class="panel panel-default" style="width: 120%; padding: 3%">
                        <div>
                            <h5>No tiene permisos para ver este panel,<a href="{{ URL::to('/') }}/home/1" >
                                    <span class="item-text">regresar a <i>"Inicio"</i></span></a>. </h5>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    @endif
@endsection

@section('scripts')
{{--  <script src="https://code.jquery.com/jquery-3.2.1.js" ></script> --}}
<script>
$(document).ready(function(){

        setTimeout(function(){  

            generate_celd();
            generate_celd();
            generate_celd();

        }, 300);




        $('#table1').stacktable({myClass:'stacktable small-only'}); //




        $(window).resize(function() {
        
            generate_celd();

        });

});



function generate_celd(){


      if ($("#table1").is(":visible") == false) { 

        $(".raiz").parent().next().each(function (index, value) { 
    
                yiyi = $(value).children().eq(0).html();

                $(value).children().eq(0).html(yiyi.replace("/", "\n"));            

        });

    }

}

//datatable
var  notdatatable = false;//ejecuta el datatable
</script>
@endsection
<style>
@media (max-width: 1200px) {
  #table1 { display: none; }
  .large-only { display: none; }
  .stacktable.small-only { display: table; }
}

.stacktable.large-only { display: table; }
.small-only { display: none; }

</style>
