<?php $title = 'Quick Links'; ?>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-white font-weight-bold"><i class="fas fa-link mr-2"></i>Quick Links</h1>
    <?php if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin'): ?>
    <a href="<?= $baseUrl ?>/links/create" class="glass-btn glass-btn-primary"><i class="fas fa-plus mr-1"></i>Add Link</a>
    <?php endif; ?>
</div>
<div class="row">
    <?php if (!empty($links)): ?>
        <?php foreach ($links as $link): ?>
        <div class="col-lg-4 col-md-6 mb-4">
            <div class="glass-card h-100 d-flex flex-column">
                <div class="d-flex align-items-center mb-3">
                    <div class="mr-3" style="width: 48px; height: 48px; background: rgba(78,115,223,0.2); border-radius: 12px; display: flex; align-items: center; justify-content: center;">
                        <i class="<?= htmlspecialchars($link->icon) ?>" style="color: #4e73df;"></i>
                    </div>
                    <div>
                        <h5 class="mb-0"><?= htmlspecialchars($link->title) ?></h5>
                        <?php if ($link->category): ?><small style="color: rgba(255,255,255,0.5);"><?= htmlspecialchars($link->category) ?></small><?php endif; ?>
                    </div>
                </div>
                <?php if ($link->description): ?><p style="color: rgba(255,255,255,0.6); font-size: 0.9rem;"><?= htmlspecialchars($link->description) ?></p><?php endif; ?>
                <div class="mt-auto d-flex justify-content-between align-items-center">
                    <a href="<?= htmlspecialchars($link->url) ?>" target="<?= $link->target ?>" class="glass-btn btn-sm">Visit <i class="fas fa-external-link-alt ml-1"></i></a>
                    <?php if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin'): ?>
                    <div>
                        <a href="<?= $baseUrl ?>/links/<?= $link->id ?>/edit" class="btn btn-sm btn-primary"><i class="fas fa-edit"></i></a>
                        <form method="POST" action="<?= $baseUrl ?>/links/<?= $link->id ?>/delete" style="display:inline;" onsubmit="return confirm('Delete this link?');">
                            <button type="submit" class="btn btn-sm btn-danger"><i class="fas fa-trash"></i></button>
                        </form>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        <?php endforeach; ?>
    <?php else: ?>
    <div class="col-12"><div class="empty-state"><i class="fas fa-link"></i><p>No links yet</p></div></div>
    <?php endif; ?>
</div>
