<ul class="list-group">
    <?php if (in_array($_SESSION['usuario']['perfil'], [1, 2, 3])) { ?>
		<li class="list-group-item">
			<form method="get">
				<div class="row filtros-anuncios">
					<div class="col-12">
						<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#modalAnuncioForm" data-id="0"><i class="fas fa-plus"></i> Crear Anuncio</button>
					</div>
				</div>
			</form>
		</li>
    <?php } ?>
    <li class="list-group-item">
        <div class="table-responsive">
            <table class="table table-striped anuncios">
                <thead>
                    <tr>
                        <th>Título</th>
                        <th>Autor</th>
                        <th>Fecha</th>
                        <th>Acciones</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    if (!empty($anuncios)) {
                        foreach($anuncios as $a) {
                            $class = 'sin-lectura';

                            if (isDate($a['fecha_lectura']) || $a['id_usuario'] == $_SESSION['usuario']['id']) {
                                $class = '';
                            }
                            ?>
                            <tr id="anuncio<?php echo $a['id']; ?>" class="<?php echo $class; ?>">
                                <td class="titulo"><a class="clickable" data-id="<?php echo $a['id']; ?>"><?php echo $a['titulo']; ?></a></td>
                                <td class="autor"><?php echo $usuarios[$a['id_usuario']]; ?></td>
                                <td><?php echo fechaHora($a['created']); ?></td>
                                <td>
                                    <button type="button" class="btn btn-primary btn-sm ver-anuncio-<?php echo $a['id']; ?>" data-toggle="modal" data-target="#modalAnuncioDetalle" data-id="<?php echo $a['id']; ?>">
                                        <i class="fas fa-eye"></i>
                                    </button>
                                    <?php
                                    if ($_SESSION['usuario']['admin'] || $a['id_usuario'] == $_SESSION['usuario']['id']) {
                                        ?>
                                            <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#modalAnuncioForm" data-id="<?php echo $a['id']; ?>">
                                                <i class="fas fa-pencil-alt"></i>
                                            </button>
                                        <?php
                                    }
                                    ?>
                                </td>
                            </tr>
                        <?php
                        }
                    } else {
                        echo '<tr><td colspan="7" class="text-center">No hay anuncios</td></tr>';
                    }
                    ?>
                </tbody>
            </table>
        </div>
    </li>
</ul>
<?php $this->load->view('anuncios/modal_form'); ?>
<script src="<?php echo js('anuncios.js'); ?>"></script>
