@extends('layouts.app')

<style>
    .profile-form {
        width: 100%;
        float: left;
    }
    #selectprofile {
        width: 80%;

    }
    .panel-heading{
        margin-bottom: 5%;
    }

    #nameTask{
        width: 35%;
    }
    #formBtEB{
       display: flex;
        width: 110%;
    }
    #bteditar{
        margin-bottom:0 ;
        margin-right: 15px;
        width:27%;
    }

    #btborrar{
        margin-bottom:0;
        width:27%;
    }
</style>

@section('content')

    <div class="container">
        @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

        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="text-center text-primary font-italic">Panel de tareas por perfil</h4>
            </div>
            <div class="panel-body">
                <div class="panel-heading">
                    @if(isset($allProfile))

                        <form class="form-inline profile-form" action="{{URL::to('/') }}/tasks/selectbyProfile" method="post">
                            <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
                            <div class="form-group mx-sm-3 mb-2">
                                <label for="inputPassword2" class="sr-only">Perfiles</label>
                                <select class="js-example-placeholder-single" id="selectprofile" name="profile_id">

                                    <option></option>
                                    @foreach($allProfile as $profile)
                                        <option  value="{{$profile->id}}">{{$profile->area}}</option>
                                    @endforeach

                                </select>
                            </div>
                            <button type="submit" class="btn btn-secundary mb-2">seleccionar</button>
                        </form>

                    @endif

                </div>


                @if(isset($allTasksbyProfile))

                       @if (is_countable($allTaskbyProfile))
                        <div class="table-responsive-md"  >

                            <div class="breadcrumb">
                                <h4 class=" text-center">{{$profileSl->area}}</h4>
                            </div>
                            <hr>
                            <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($allTasksbyProfile as $t)


                                    <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 )
                                            <td><span style="background:#f00;color:#fff;padding:4px;border-radius:4px;font-size:12px;">Borrador</span></td>
                                        @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 )
                                            <td>
                                                <div id="formBtEB" >

                                                    <form id="bteditar" action="{{ URL::to('/') }}/forms/{{$t->type }}/{{$t->id}}/edit">
                                                        <input class="btn btn-primary btn-xs" type="submit" value="Editar">

                                                    </form >
                                                    <form id="btborrar" onclick="return confirm('Desea eliminar?')" action="{{ URL::to('/') }}/forms/{{$t->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>
                                            </td>
                                            @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>
                    @endif

                @endif

            </div>
        </div>
    </div>

@endsection

@section('scripts')
    <script>

        $(document).ready(function() {


            $('.js-example-placeholder-single').select2({
                placeholder: 'Seleccione un perfil'
            });

        });
    </script>

@endsection
