<ul class="list-group">
    <li class="list-group-item">
        <?php
            $this->load->view('tareas/navigation');
        ?>
    </li>
    <li class="list-group-item detalle-tarea">
        <div class="row">
            <div class="col-12 col-sm-8">
                <h3 class="detalle-tarea-titulo"><?php echo $tarea['titulo'];?></h3>
                <h6>Descripción</h6>
                <div class="detalle-tarea-descripcion"><?php echo $tarea['descripcion'];?></div>
                <div class="overflow-hidden p-1">
                    <form id="formComentario" class="collapse">
                        <input type="hidden" id="idTarea" name="id_tarea" value="<?php echo $tarea['id'];?>"/>
                        <textarea id="nuevoComentario" class="form-control text-nuevo-comentario" name="comentario" rows="8"></textarea>
                    </form>
                    <button type="button" class="btn btn-primary btn-comentar float-right mt-3" data-toggle="collapse" href="#formComentario">Comentar</button>
                </div>

                <?php if (!empty($tarea['comentarios'])) { ?>
                <h5 class="mb-3">Comentarios <span class="cantidad-comentarios badge badge-pill badge-success"><?php echo count($tarea['comentarios'])?></span></h5>
                <div class="lista-comentarios">
                    <?php
                    foreach($tarea['comentarios'] as $c) {
                        ?>
                        <div class="comentario-contenedor mb-4">
                            <div class="comentario-izquierda">
                                <div class="comentario-avatar"><?php echo substr($usuarios[$c['id_usuario']], 0, 1); ?></div>
                            </div>
                            <div class="comentario-derecha">
                                <p class="mb-1"><strong><?php echo $usuarios[$c['id_usuario']];?></strong><span class="comentario-fecha"><?php echo fechaHora($c['created']); ?></span></p>
                                <div class="comentario-contenido"><?php echo $c['comentario']?></div>
                            </div>
                        </div>
                    <?php
                    }
                    ?>
                </div>
                <?php } ?>

                <?php
                    /*
                    foreach($comentarios as $c) {


                    }
                    */
                ?>
            </div>
            <div class="col-12 col-sm-4">
                <div class="row">
                    <div class="col-12 mb-4">
                        <select name ="id_estado_tarea" 
                            class="form-control select-id-estado-tarea estado-tarea-<?php echo $tarea['id_estado_tarea']; ?>">
                            <?php
                                foreach($estadosTareas as $k => $v) {
                                    $selected = ($tarea['id_estado_tarea'] == $k) ? ' selected="selected"' : '';
                                    $disabled = '';
                                    if (!$_SESSION['usuario']['admin'] &&
                                        $k == 4 &&
                                        $tarea['id_responsable'] == $_SESSION['usuario']['id'] &&
                                        $tarea['id_solicitante'] != $_SESSION['usuario']['id']
                                        
                                    ) {
                                        $disabled = ' disabled="disabled"';
                                    }
                                    echo '<option value="' . $k . '"' . $selected . $disabled . ' >' . $v . '</option>';
                                }
                            ?>
                        </select>
                    </div>
                    <label class="col-5 pl-4">Responsable</label>
                    <div class="col-7 detalle-tarea-responsable"><?php echo $usuarios[$tarea['id_responsable']];?></div>

                    <label class="col-5 pl-4">Solicitante</label>
                    <div class="col-7"><?php echo $usuarios[$tarea['id_solicitante']];?></div>

                    <label class="col-5 pl-4">Prioridad</label>
                    <div class="col-7"><span class="badge badge-pill prioridad-tarea prioridad-tarea-<?php echo $tarea['prioridad']; ?>"><?php echo $prioridades[$tarea['prioridad']]; ?><span></div>

                    <label class="col-5 pl-4">Fecha creación</label>
                    <div class="col-7"><?php echo fechaHora($tarea['created']);?></div>

                    <label class="col-5 pl-4">Fecha límite</label>
                    <div class="col-7"><?php echo fecha($tarea['fecha_limite']);?></div>

                    <label class="col-5 pl-4">Fecha inicio</label>
                    <div class="col-7"><?php echo fechaHora($tarea['fecha_inicio']);?></div>

                    <label class="col-5 pl-4">Fecha finalizada</label>
                    <div class="col-7"><?php echo fechaHora($tarea['fecha_fin']);?></div>

                    <?php
                    if ($_SESSION['usuario']['admin'] || $tarea['id_solicitante'] == $_SESSION['usuario']['id']) {
                        ?>
                        <div class="col-12 mt-4 text-right">
                            <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#modalTareaForm" data-id="<?php echo $tarea['id']; ?>">
                                <i class="fas fa-pencil-alt"></i> Editar Tarea
                            </button>
                        </div>
                        <?php
                    }
                    ?>
                </div>
            </div>
        </div>
    </li>
</ul>

<?php $this->load->view('tareas/modal_form'); ?>
<script src="<?php echo js('tareas.js'); ?>"></script>

<script>
    tinymce.init({
        selector: "#nuevoComentario",
        language: 'es',
        branding: false,
        menubar: false,
        plugins: [
            'advlist', 'autolink', 'lists', 'link', 'image', 'charmap', 'preview',
            'anchor', 'searchreplace', 'visualblocks', 'fullscreen',
            'insertdatetime', 'media', 'table', 'code', 'help', 'wordcount'
        ],
        toolbar: 'code forecolor bold italic underline link ' +
            'alignleft aligncenter alignright alignjustify ' +
            'bullist numlist table image media blocks help',
        automatic_uploads: true,
        file_picker_types: 'image',
        automatic_uploads: true,
        images_upload_url: '/tareas/cargar_imagen',
    });
</script>