<?php if (!empty($news)): ?>
    <div class="inhalt">
    <div class="content-container">
        <div class="news-header">
            <h2>Alle Infos</h2>
            <?php if (isset($_SESSION['is_admin']) && $_SESSION['is_admin']): ?>
                <a href="?controller=News&do=createNewsForm" class="admin-btn">News erstellen</a>
            <?php endif; ?>
        </div>
    <div class="news-cards">
        <?php foreach ($news as $item): ?>
            <div class="card">
                <h3><?=htmlspecialchars($item['name'])?></h3>
                <div class="news-date"><?=date('d.m.Y', strtotime($item['date']))?></div>
                <div class="news-desc">
                    <?php
                        $desc = htmlspecialchars($item['description']);
                        if (mb_strlen($desc) > 255) {
                            $short = mb_substr($desc, 0, 255) . '...';
                            echo nl2br($short) . ' <a href="?controller=News&do=showNewsDetail&id=' . $item['news_id'] . '">mehr lesen</a>';
                        } else {
                            echo nl2br($desc);
                        }
                    ?>
                </div>
                <?php if (isset($_SESSION['is_admin']) && $_SESSION['is_admin']): ?>
                    <div class="news-card-actions">
                        <a href="?controller=News&do=editNewsForm&id=<?=$item['news_id']?>" class="admin-btn">Bearbeiten</a>
                        <a href="?controller=News&do=deleteNews&id=<?=$item['news_id']?>" class="admin-btn" onclick="return confirm('Wirklich löschen?');">Löschen</a>
                    </div>
                <?php endif; ?>
            </div>
        <?php endforeach; ?>
    </div>
<?php else: ?>
    <p>Derzeit sind keine News verfügbar.</p>
<?php endif; ?>
</div>
    </div>
    </div>  