@extends('layouts.app')

<style>
    /*.panel {*/

        /*width:80%;*/
        /*margin: auto;*/
        /*margin-top: 4%;*/
    /*}*/
    #nameTask{
        width: 35%;
    }

</style>
@section('content')
    <div class="container">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="text-center text-muted font-weight-light">Panel de tareas por perfil</h4>
            </div>
                <div class="panel-body">
                    <div class="panel-heading">
                    <a class="btn btn-outline-info active"  href="{{URL::to('/') }}/tasks/byProfile/1">Abiertas</a>
                    <a class="btn btn-outline-info active" href="{{URL::to('/') }}/tasks/byProfile/5">En espera</a>
                    </div>

                        @if (is_countable($allTaskByProfile))

                        <div class="table-responsive-md"  >

                                @foreach($allTaskByProfile as $tasks)
                                <p>
                                    <button class="btn btn-primary btn-lg btn-block " type="button" title="{{$tasks->first()->profile->area}}" data-toggle="collapse" data-target="#collapseExample-{{$tasks->first()->profile->id}}" aria-expanded="false" aria-controls="collapseExample">
                                        {{ $app['utils']->cutText( $tasks->first()->profile->area,100) }}
                                    </button>
                                </p>


                                    <div class="collapse" id="collapseExample-{{ $tasks->first()->profile->id}}">

                                        <table class="table table-sm" >

                                            <thead>
                                                <tr>

                                                    <th scope="col">Tarea</th>
                                                    <th scope="col">Líneas de producción</th>
                                                    <th scope="col">Unidad</th>
                                                    <th scope="col">Estado</th>
                                                    <th scope="col">Fecha de ingreso</th>
                                                    <th scope="col">Ver tarea</th>
                                                    <th scope="col">Pipelines</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            @foreach($tasks as $t)
                                                {{--{{dd($tasks)}}--}}
                                                <tr>

                                                    <td scope="row" id="nameTask">{{($t->title) ? $t->title : " "}}</td>
                                                    <td scope="row">{{($t->pipeline->first()) ? $t->pipeline->first()->name : " "}}</td>
                                                    <td>{{ ($t->unit) ? $t->unit->name : " " }}</td>

                                                    @if($t->unit_id == null )
                                                        <span style="background:#f00;color:#fff;padding:4px;border-radius:4px;font-size:12px;">Borrador</span>
                                                    @else
                                                    <td>{{ ($t->status) ? $t->status->name : " " }}</td>
                                                    @endif

                                                    <td>{{ ($t->created_at) ? date('d-m-Y', strtotime(str_replace('/', '-', $t->created_at))) : " " }}</td>

                                                    @if(!$user->isApplicant())
                                                        @if($t->unit_id == null )

                                                            <div style="display: flex">

                                                                <form style="margin-bottom:0 ;margin-right: 15px;width:27%;" action="{{ URL::to('/') }}/forms/{{$t->type }}/{{$t->id}}/edit">
                                                                    <input class="btn btn-primary btn-xs" type="submit" value="Editar">

                                                                </form >
                                                                <form style="margin-bottom:0;width:27%;" onclick="return confirm('Desea eliminar?')" action="{{ URL::to('/') }}/forms/{{$task->type }}/delete" method="post">
                                                                    <input type="hidden" name="_token" value="{{ csrf_token() }}">

                                                                    <input type="hidden" name="id" value="{{ $t->id }}">
                                                                    <input class="btn btn-primary btn-xs" type="submit" value="Borrar">
                                                                </form>

                                                            </div>
                                                            @else
                                                        <td><a href="{{URL::to('/')}}/tasks/{{ $t->id }}/unit/{{ $t->unit_id }}/show"><i class="fa fa-pencil-square-o"></td>
                                                        @endif
                                                    @endif
                                                    <td>
                                                        <ul class="pipeline-timeline">
                                                            @if($t->unit_id)
                                                                @foreach($t->pipeline->first()->unitsByRevision($t->pipelineRevision) as $u)
                                                                    <?php
                                                                    $circle = "fa-circle-o";
                                                                    $active = '';
                                                                    if ($u->id == $t->unit->id) {
                                                                        $active = 'active';
                                                                        $circle = "fa-circle";
                                                                    }
                                                                    ?>
                                                                    <li data-unit="{{ $u->name }}" data-toggle="tooltip" title="{{ $u->name }}" class="{{ $active }}">
                                                                        <a href="{{ URL::to('/') }}/tasks/{{ $t->id }}/unit/{{ $u->id }}/show">
                                                                            <i style="color:{{ $u->color }};" class="fa {{ $circle }}" aria-hidden="true"></i>
                                                                        </a>
                                                                    </li>
                                                                @endforeach
                                                            @endif
                                                        </ul>
                                                    </td>




                                                </tr>
                                            @endforeach
                                            </tbody>
                                        </table>
                                    </div>


                                @endforeach

                        </div>
                    @endif

                </div>
            </div>
        </div>
    </div>
@endsection

<script>

</script>