@extends('layouts.app')

<style>
    .profile-form {
        width: 100%;
        float: left;
    }
    .taskdata-form {
        margin-top: 5%;
        margin-left: 3%;

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

    #regresar1 {
        float: right;
        margin-right: 3%;
    }
    .selecttaskdata{
        margin-left: 2%;
    }
    .contenedor-BA{
        padding: 1%;

    }

    .BA-form {

        height: auto;

    }
    .form-groupBA{
        width: 80%;
        float: left;
        margin: 1%;
    }

</style>
<head>

    <link rel="stylesheet"
          href="https://cdn.jsdelivr.net/npm/animate.css@3.5.2/animate.min.css">
    <!-- or -->
    <link rel="stylesheet"
          href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
</head>
@section('content')

    @if(isset($error))

        <div class="alert alert-danger alert-dismissable animated  bounce">
            <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>

            {!!  $error !!}
        </div>

    @endif


    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="text-center text-primary font-italic">Tareas creadas</h4>
        </div>
        <h5 id="regresar1">
            <ul class="nav flex-column ">
                <li class="nav-item ">
                    <a class="nav-link active" href="{{ URL::to('/') }}/home/1"><i>Regresar a tareas creadas</i></a>
                </li>
            </ul>
        </h5>
        @if(isset($alltaskdata))


            <form class="form-inline taskdata-form" action="{{URL::to('/') }}/home/select-taskdata" method="post">
                <h6>Ver tareas relacionadas.</h6>
                <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
                <input type="hidden" name="view" value="select"/>
                <div class="form-group mx-sm-3 mb-2">
                    <label for="inputaskdata" class="sr-only">Tarea</label>
                    <select class="js-example-placeholder-single" id="selectTaskdata" name="taskdata_id">

                        <option></option>
                        @foreach ($alltaskdata as $td)


                            <option  value="{{$td->id}}">{{ $app['utils']->cutText( $td->title,40) }}</option>
                        @endforeach

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

        @endif

    <div class="contenedor-BA">

        <p class="selecttaskdata">
            <a class="text-info busquedaAvanzada" data-toggle="collapse" href="#collapseExampleBA" role="button" aria-expanded="false" aria-controls="collapseExampleBA">
                <i>Búsqueda avanzada</i>
            </a>
        </p>
        <span class="border border-info" >
            <div class="collapse border" id="collapseExampleBA" >
                <nav class="navbar navbar-default">
                    <div class="container-fluid">
                    <!-- Brand and toggle get grouped for better mobile display -->
                        <div class="navbar-header" id="formBA">
                            <form class="form-inline BA-form" action="{{URL::to('/') }}/home/select-taskdata" method="post">
                                <div class="containerFr">
                                    <input type="hidden" name="_token" value="{{ csrf_token() }}"/>

                                    <input type="hidden" name="view" value="select"/>

                                <div class="form-groupBA">
                                    <label for="exampleFormControlSelect1">Tareas :</label>
                                    <select class="form-control" id="selectTaskdata2" name="taskdata_id">
                                        <option></option>
                                        @foreach ($alltaskdata as $td)
                                            <option  value="{{$td->id}}">{{ $app['utils']->cutText( $td->title,40) }}</option>
                                        @endforeach
                                    </select>
                                </div>

                                <div class="form-groupBA">
                                    <label for="exampleFormControlSelect1">Perfiles :</label>
                                    <select class="form-control" id="selectprofile" name="id_profile">
                                        <option></option>
                                        @foreach ($profiles as $pf)
                                            <option  value="{{$pf->id}}">{{ $app['utils']->cutText( $pf->area,40) }}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="form-groupBA" id="">
                                    <label for="exampleFormControlSelect1">Estado :</label>
                                    <select class="form-control" id="selectstatu" name="id_statu">
                                        <option></option>
                                        @foreach ($status as $st)
                                            <option  value="{{$st->id}}">{{ $st->name }}</option>
                                        @endforeach
                                    </select>
                                </div>

                                     <div class="form-groupBA" id="">
                                <button type="submit" class="btn btn-secundary mb-2 groupBA">Buscar</button>
                                     </div>
                            </div>
                        </form>
                            {{----}}
                </div><!-- /.navbar-collapse -->
              </div><!-- /.container-fluid -->
            </nav>
        </div>
        </span>
    </div>

        <div class="panel-body">


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

                @if(isset($taskdatas))

                    <div class="breadcrumb">
                        <h4 class=" text-center" data-toggle="collapse" href="#collapseExampleTD" role="button" aria-expanded="false" aria-controls="collapseExample">{{$taskdatas->title}} <span class="glyphicon glyphicon-chevron-down" aria-hidden="true" style="float:right"></span></h4>
                    </div>

                    <hr>

                    <span class="border border-info">
                        <div class="collapse border" id="collapseExampleTD" >
                        <table class="table table-sm" >

                            <thead>
                            <tr>
                                <th scope="col">Líneas de producción</th>
                                <th scope="col">Unidad</th>
                                <th scope="col">Fecha de ingreso</th>
                                <th scope="col">Estado</th>
                                <th scope="col">Acciones</th>
                                <th scope="col">Pipelines</th>

                            </tr>
                            </thead>
                            <tbody>


                            @foreach($taskdatas->tasksRel as $key => $t)

                                <tr>

                                <td scope="row">{{($t->pipeline->first()) ? $t->pipeline->first()->name : " "}}</td>
                                <td>{{ ($t->unit) ? $t->unit->name : " " }}</td>
                                <td>{{ ($t->created_at) ? date('d-m-Y', strtotime(str_replace('/', '-', $t->created_at))) : " " }}</td>

                                @if(!$user->isApplicant())


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

                                            <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/{{$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>{{ ($t->status) ? $t->status->name : " " }}</td>
                                            <td><a href="{{URL::to('/')}}/tasks/{{ $t->id }}/unit/{{ $t->unit_id }}/show"><i class="fa fa-pencil-square-o"></i></a></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>
                </span>

                @elseif(isset($arraytaskdata) && count($arraytaskdata)>0)

                    @foreach($arraytaskdata as $taskdatas)

                        <div class="breadcrumb">
                            <h4 class=" text-center" data-toggle="collapse" href="#collapseExample{{$taskdatas->id}}" role="button" aria-expanded="false" aria-controls="collapseExample">{{$taskdatas->title}} <span class="glyphicon glyphicon-chevron-down" aria-hidden="true" style="float:right"></span></h4>
                        </div>


                        <span class="border border-info">
                            <div class="collapse border" id="collapseExample{{$taskdatas->id}}" >
                            <table class="table table-sm" >

                                <thead>
                                <tr>
                                    <th scope="col">Líneas de producción</th>
                                    <th scope="col">Unidad</th>
                                    <th scope="col">Fecha de ingreso</th>
                                    <th scope="col">Estado</th>
                                    <th scope="col">Acciones</th>
                                    <th scope="col">Pipelines</th>
                                </tr>
                                </thead>
                                <tbody>


                            @foreach($taskdatas->tasksRel as $key => $t)

                            <tr>
                                <td scope="row">{{($t->pipeline->first()) ? $t->pipeline->first()->name : " "}}</td>
                                <td>{{ ($t->unit) ? $t->unit->name : " " }}</td>
                                <td>{{ ($t->created_at) ? date('d-m-Y H:i', strtotime(str_replace('/', '-', $t->created_at))) : " " }}</td>

                                @if(!$user->isApplicant())


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

                                            <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/{{$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>{{ ($t->status) ? $t->status->name : " " }}</td>
                                        <td><a href="{{URL::to('/')}}/tasks/{{ $t->id }}/unit/{{ $t->unit_id }}/show"><i class="fa fa-pencil-square-o"></i></a></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>
                </span>
                    @endforeach

                @else
                    <div class="panel">
                        <h5>No se encontraron resultados.</h5>
                    </div>

                @endif


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

    @endsection


@section('scripts')
    <script>


        $(document).ready(function() {


            $('.js-example-placeholder-single').select2({
                placeholder: 'Seleccione una tarea'
            });
            $('#selectTaskdata2').select2({
                placeholder: 'Seleccione una tarea'
            });
            $('#selectprofile').select2({
                placeholder: 'Seleccione un perfil'
            });
            $('#selectstatu').select2({
                placeholder: 'Seleccione un estado'
            });

            $('.busquedaAvanzada').click(function (e) {

                if($("#collapseExampleBA").is(":visible"))
                {
                    $('.taskdata-form').show();
                }
                else
                {
                    $('.taskdata-form').hide();
                }




            })
        });
    </script>

@endsection
