@extends('layouts.client')

@section('content')



    <div class="task-single">
        <div class="task-header">
            <div class="task-panel ">
                <div class="task-panel-main panel">
                    <h4>{{ $task->taskdata->title }}</h4>

                    <h5 style="font-weight: 600">Descripción:</h5>
                    <div class="task-description">
                        {!!  $task->taskdata->description !!}

                    </div>
                </div>
                <div class="task-panel-secondary ">


                    <div class="task-panel-secondary-inside panel">
                        <div class="task-creator">
                            <h5>Reponsable de area: <a
                                        href="mailto:{{$task->profile->email}}"> {{ $task->profile->name }} {{ $task->profile->surname }}</a>
                            </h5>
                            <h5>Area: {{ $task->profile->area }}</h5>
                            <h5>Contacto: <a
                                        href="mailto:{{ $task->createdBy->email }}">{{ $task->createdBy->name }} {{ $task->createdBy->surname }}</a>
                            </h5>
                        </div>
                        <div class="task-date">
                            <h5>Fecha de creación: {{ $task->created_at }}</h5>
                        </div>


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

        </div>
        <br>

    {{-- @if($task->pipeline->first()->system != 1) --}}
    {{-- @if(!$user->isApplicant()) --}}
{{--    @if(!$user->isApplicant() || ($user->isApplicant() && $task->pipeline->first() == 1))--}}
        <div class="task-bottom">
            <div class="comments-container">
                @include('comments::comments-react', [
                    'content_type' => App\Task::class,
                    'content_id' => $task->id,
                    
                ])
            </div>


            <div class="task-sidebar">


                <?php $exist_entregados = false;  ?>

                {{-- mostrar archivos entregados --}}

                <div class="sidebar-container panel">
                    <div class="no-content task_element">
                        @if (is_countable($task->attachments))

                            <h5 style="font-weight: 600">Archivos Adjuntos:</h5>
                            @foreach($task->attachments as $attach)


                                <?php

                                $desdesub = null;
                                $isdeliver = "";

                                if($attach->pivot->active == "1"){

                                $desdesub = ($attach->delivered) ? "desdesub" : "";

                                if ($attach->delivered) {

                                    $isdeliver = '<i title="Archivo entregado desde subtarea" alt="Archivo entregado desde subtarea" class="fa fa-arrow-up delivered stack_newed elementTheTask nowdeliver_' . $attach->id . '" aria-hidden="true"></i>';

                                }

                                ?>
                                    <?php if ($user->isTeamLeaderAtAnyUnit() == false && $user->isTeamMemberAtAnyUnit() == false && $attach->pivot->delivered_final == 0 && $attach->user_id != Auth::user()->id)
                                        {
                                            $display = "display:none";
                                        } else {
                                            $display = '';
                                        }
                                    ?>
                                <div  class="bdn subattachtask_element {{ $desdesub }} subattachtask_{{$attach->id}} elementTheTask" style="<?php echo $display; ?>">
                                    <a href='{{URL::to('/')}}/uploads/{{$attach->filename}}'
                                       target='_blank'>{{ $attach->original_name}}<span
                                                class='minidatetask_{{$attach->id}}'
                                                style='margin-left: 6px;font-size: 11px !important;font-style: inherit;'>{{ date('d/m/Y', strtotime($attach->created_at))}}</span></a><?php echo $isdeliver; ?>
                                </div>

                                <?php

                                }else{ ?>

                                <div class="datin bdn subattachtask_element subattachtask_{{$attach->id}}"
                                     style="color: #979797">{{ $attach->original_name}}<span
                                            style='margin-left: 6px;font-size: 11px !important;font-style: inherit;color: #979797;'>{{ date('d/m/Y', strtotime($attach->created_at))}}</span>
                                </div>

                                <?php
                                }
                                ?>


                                <?php /*
                                <a href="{{URL::to('/')}}/uploads/{{$attach->filename}}" target="_blank">{{ $attach->original_name }}</a><br>

*/  ?>


                            @endforeach
                        @else
                            <div class="task_text_borrador">
                                No se encontraron archivos Adjuntos
                            </div>
                        @endif
                    </div>


                    <div class="form-group flex center box_supArchivo" style="text-align:-webkit-center">

                        <div class="task_temporal_progress">
                            <progress class="barProgress_task" max="100" value="0"
                                      style="display: none;margin-bottom: 6px;margin-left: 12%;margin-right: 12%"><span
                                        id="textProgress_task">22</span></progress>
                            <ul id="file-upload-list" class="list-unstyled file-upload-list_task" data-type="task">
                            </ul>
                            <ul id="file-upload-progress_task" class="list-unstyled"></ul>
                        </div>
                        <input type="hidden" name="jsonIdAttachments" id="jsonIdAttachments_task" value="">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
                        <input type="hidden" id="task_id" name="task_id" value="{{ $task->id }}">

                    </div>


                    <div class="nuevo_div">

                        <div>
                            <button type="button" id="buttonDownload" style="width: 90px;display:none"
                                    class="btn btn-primary">Descargar
                            </button>
                            @if ($task->status_id != 3 && $task->status_id != 6)
                            <span class="btn btn-success fileinput-button box_elegirArchivo" style="visibility: hidden">
                                <i class="icon-plus icon-white"></i>
                                <span>Subir Archivos</span>
                                <input id="fileupload" class="fileupload" data-type="task" multiple type="file"
                                       name="file" data-url="{{ url('upload') }}" style="display: inline;">

                            </span>
                            @endif
                        </div>
                    </div>
                    <br>
                    <br>
                    <br>

                    @if ($task->status_id != 3 && $task->status_id != 6)
                    <div class="alternative-upload-container" style="text-align: center">
                        <div class="alternative-upload-trigger btn btn-warning" style="text-align: center;font-size:14px;">
                            Upload Alternativo
                        </div>
                        <div class="alternative-upload-form" style="display: none">
                            <br>

                            <form action="{{ URL::to('/') }}/alternative-upload" id="alternative_upload" method="post" enctype="multipart/form-data">
                                {{ csrf_field() }}

                                <input type="file" name="uploadfile" class="uploadfile">
                                <input type="hidden" name="task_id" value="{{ $task->id }}">
                                <input type="hidden" name="user_id" value="{{ $user->id }}">
                                <input type="hidden" name="type" value="task">
                                <br>
                                <input type="submit" value="Enviar Archivo" class="btn btn-warning">
                            </form>
                        </div>

                    </div>
                    @endif



                </div>
            </div>

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

    <style>/*
    .subattach:last-child{

        margin-bottom: 20px;

    }*/

        .bdn {
            color: red;
            height: 20px;
            font-size: 11px !important;
        }

        .stack_deleted {

            position: absolute !important;
            margin-left: 20px;
            line-height: 8px;
            height: 14px;
            font-size: 11px;
            width: 14px;
            padding-left: 3px;

        }

        .datin {
            margin-left: 2px;
            font-size: 14px;
            font-style: inherit;
            color: #979797;
            opacity: 0.7;
        }

        .stack_newed {
            color: white;
            float: none;
            height: 16px;
            /*      background-color: orange;  */
            left: 40px;
            line-height: 2px;
            padding-left: 2.5px;
            top: -1.5px;
            /*      font-weight: bold;  */
            height: 14px;
            margin-left: -2px;
            width: 14px;
            position: relative;
        }

        .not_deliver {
            background-color: #FF8000;
            border-color: #FF8000;
            color: white;
        }

        .delivered {
            /*      background-color: #549E54;
                    border-color: #549E54;  */
            color: #549E54;
        }

        .not_deliver:hover {
            background-color: #FF8000;
            border-color: #FF8000;
            color: white;
        }

        .delivered:hover {
            /*      background-color: #549E54;
                    border-color: #549E54;  */
            color: #549E54;
        }

        .opt_delivered {
            color: #BCBCBC;
            background-color: #FFFFD2;
        }

        .stack_newed:focus {
            color: white;
        }

    </style>
    <!-- Button trigger modal -->


    <!-- Modal -->




@endsection


@section('modals')

@endsection


@section('scripts')
    <script>

        noMostrarDelete = 1;

        $(document).ready(function () {


            $("#alternative_upload").submit(function(event) {
        

                if($(".uploadfile").val()==""){

                     event.preventDefault();
                }

             });   


            $('.alternative-upload-trigger').click(function(){
                $('.alternative-upload-form').toggle();
            })

            <?php echo (isset($exist_entregados) && $exist_entregados) ? '$(".entregados").show();' : '$(".entregados").hide();'; ?>

            verifyAttachinTask();


            $("#jsonIdAttachments_subtask").val("");
            $("#jsonIdAttachments_subtask_aux").val("");


            // Al abrir un modal se visualizan los archivos nuevos

            $(".createSubtarea").on("click", function () {

                $("#taskAttach_multiple option:selected").removeAttr("selected");
                verifyAttachinTask();

            });


            $("#buttonDownload").on("click", function () {

                var d = new Date();
                var n = d.getTime();

                location.href = "{{ URL::to('/') }}/tasks/{{ $task->id }}/download?" + n;


            });


            countAtachFiles = parseInt($(".elementTheTask").length);
            {{--   parseInt("{{ count($task->attachments) }}");  --}}

            if (countAtachFiles > 0) {

                seeDownload();

            } else {

                $(".nuevo_div").css("text-align", "center");
                $(".box_elegirArchivo").css("visibility", "visible");

                $(".box_supArchivo").css("margin-top", "12px");
                $(".box_supArchivo").css("text-align", "center");

            }


            $(function () {
                $('#datetimepicker2').datetimepicker({
                    locale: 'ru'
                });
            });


            $('#status-select').select2();


            $('.task-description').readmore({
                speed: 75,
                moreLink: '<a class="readmore more"href="#">Ver más</a>',

                lessLink: '<a class="readmore less"href="#">Ver menos</a>',
                heightMargin: 16,
            });


            $(window).resize(function () {

                ellipses1 = $("#bc1 :nth-child(2)")
                if ($("#bc1 a:hidden").length > 0) {
                    ellipses1.show()
                } else {
                    ellipses1.hide()
                }

                ellipses2 = $("#bc2 :nth-child(2)")
                if ($("#bc2 a:hidden").length > 0) {
                    ellipses2.show()
                } else {
                    ellipses2.hide()
                }

            })

        });

        function verifyAttachinTask() {


            $.ajax({

                data: {task_id:{{ $task->id }}, subtask_id: null},
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
                },
                dataType: 'json',
                url: "{{ URL::to('/') }}/tasks/getAttachTask",
                type: 'POST',
                success: function (data) {

                    if (data.attachs) {

                        //   console.log(data);

                        /*
                        if(!$("#taskAttach_multiple").is(":visible")){

                            $("#taskAttach_multiple").show();
                            $(".alltach").hide();
                            $(".addsubtask").show()
                        }
                        */

                        $("#taskAttach_multiple").html("");

                        linkAttach = "";


                        data.attachs.forEach(function (valor, indice, array) {


                            linkAttach += '<option data-createdAt="' + valor.created_at + '" data-filename="' + valor.filename + '" class="miniAttach attachtask_' + valor.id + '" value="' + valor.id + '">' + valor.original_name + '</option>';


                        });

                        $("#taskAttach_multiple").append(linkAttach);
                        $(".filesforTask").show();

                    } else {

                        $(".filesforTask").hide();

                    }

                }
            });
        }

    </script>
@endsection