@extends('layouts.app')

@section('styles')
    <style>
        .dataTables_wrapper,#DataTables_Table_0_wrapper{margin-top: 20px !important;}
</style>
@endsection
    @section('content')

<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  class="porcionhtml" style="padding:16px;">
                        <h3>Mis Tareas</h3>
                        <br>
                        <div >
                            <a href="javascript:" type="button"  onClick=cargarTipo('task',1)   class="btn btn-primary" href="">Tareas <span class="badge">{{$countTas}}</span></a>
                            <a href="javascript:" type="button"  onClick=cargarTipo('subtask',2) class="btn btn-primary" href="">Subtareas <span class="badge">{{$countSub}}</span></a>
                            <a href="javascript:" type="button"  onClick=cargarTipo('tags',1) class="btn btn-primary" href="">Etiquetas <span class="badge">{{$countTags}}</span></a>

                        </div>
                        <br>
                        <br>


                        @if($status != null)
                            @foreach($status as  $id=>$statu)

                                <a href="javascript:" type="button"  onClick=cargarTipo("{{$statu->status_type}}",{{$statu->id}})  class="btn btn-primary" href="{{ url('mytasks',$id)}}">{{$statu->name}}</a>
                            @endforeach
                        @endif
                        <table class="table table-data" data-page-length='30'>
                            <thead style="border-bottom:2px solid #ddd;">
                            <tr>
                                <th>Titulo</th>
                                <th>deadline</th>
                                <th>Estado</th>
                                <th>Acción</th>
                            </tr>
                            </thead>
                            <tbody>

                            {{---@if($countTas == 0 || $countSub == 0 || $countTags ==0)
                                <tr><td>No tiene tareas ó subtareas pendientes.</td></tr>

                            @endif--}}

                            @if($arrayTasks)

                                @foreach($arrayTasks as $index=>$t )



                                        @if($t['statu']== $statuName or $statuName == 'tags' )
                                            {{--si es igual al estado inicial muestro el estado pedido ,inicialmente es abierta(1)--}}
                                            <tr>
                                            <td style="padding:10px 4px;"> {{ $t['title'] }}</td>
                                                @if($t['deadline'] != null)
                                            <td>{{ date('d-m-Y', strtotime(str_replace('/', '-', $t['deadline']))) }}</td>

                                                @else
                                                    <td></td>
                                                @endif
                                            <td>{{$t['statu']}}</td>

                                            <td>

                                                <a href="{{URL::to('/')}}/{{$t['tipo']}}/{{ $t['id'] }}/show"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>
                                                    @if($t['tipo']=='subtasks')
                                                        &nbsp;Ver subtarea
                                                    @else
                                                        &nbsp;Ver tarea
                                                    @endif
                                                </a>
                                            </td>
                                            </tr>
                                        @endif

                                @endforeach

                            @else
                                <td>No tiene tareas ó subtareas pendientes.</td>
                                <td></td>
                                <td></td>
                                <td></td>
                            @endif

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="demo"></div>
@endsection

@section('scripts')
<script>


    function cargarTipo(tipoTarea,status) {

        var data = {
            "type" : tipoTarea,
            "status" : status,
        };
        console.log(data);
        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            // dataType: 'json',
            url: "{{ URL::to('/') }}/mytasks",
            data: data,
            type: 'POST',
            success: function(data) {


                $('.porcionhtml').html(jQuery(data).find('.porcionhtml').html());

                //        $("#task").html("");//limpia primero
                //        $("#task").html(data);
//                console.log(data);
                $('.table').DataTable();

            }
        });


    }



</script>
@endsection