<?php


include "../classes/database.php";
include "../classes/sets.php";
include "../classes/sessie.php";


$sessie = Sessie::vindActieveSessie();
if ($sessie == null) {
    header("location: index.php");
    exit;
}
$user_id = $sessie->userId;




if (isset($_GET["id"])) {
    $geenIdee = $_GET["id"];
} else {
    $geenIdee = 1;
}




$totalitems = 0;

$delen = 10;


$pagina = 0;
$hamburger = 0;

$setss = Sets::setsLatenZienInDeIndex();
foreach ($setss as $set) {
    $totalitems = $totalitems + 1;
}

$pagina = $totalitems / $delen;




if ($geenIdee == 1) {
    $hamburger = 0;
} else {
    $hamburger = $geenIdee * 10 - 10;
}



$ietss = Sets::hoi($hamburger);




?>


<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Sets overzicht</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
</head>

<body class="bg-light">
    <!-- Navbar -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary shadow">
        <div class="container-fluid">
            <a class="navbar-brand fw-bold" href="home.php">Dashboard</a>
            <div class="collapse navbar-collapse">
                <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                    <li class="nav-item"><a class="nav-link active" href="setsadmin.php">Sets</a></li>
                    <li class="nav-item"><a class="nav-link" href="themeadmin.php">Themes</a></li>
                    <li class="nav-item"><a class="nav-link" href="brandadmin.php">Brands</a></li>
                    <li class="nav-item"><a class="nav-link" href="voegtoesets.php">Voeg toe</a></li>
                </ul>
                <a href="index.php" class="btn btn-outline-light">
                    Logout <i class="bi bi-box-arrow-right"></i>
                </a>
            </div>
        </div>
    </nav>

    <!-- Content -->
    <div class="container my-5">
        <h2 class="mb-4 text-center">Overzicht van Sets</h2>
        <div class="row g-4">
            <?php foreach ($ietss as $set): ?>
                <div class="col-sm-6 col-lg-4">
                    <div class="card shadow-sm h-100 border-0">
                        <a href="detail.php?id=<?= $set->setId; ?>" class="text-decoration-none text-dark">
                            <img src="../images/sets/<?= $set->setImage; ?>" 
                                 alt="geen foto" 
                                 onerror="this.src='../images/sets/stock.png'" 
                                 class="card-img-top" 
                                 style="max-height: 180px; object-fit: contain; padding: 1rem; background:#f8f9fa;">
                            <div class="card-body">
                                <h5 class="card-title fw-semibold"><?= htmlspecialchars($set->setName); ?></h5>
                                <p class="card-text text-muted mb-2">Prijs: €<?= htmlspecialchars($set->setPrice); ?></p>
                            </div>
                        </a>
                        <div class="card-footer bg-white border-0 d-flex justify-content-between">
                            <a href="./bewerk/bewerksets.php?id=<?= $set->setId; ?>" class="btn btn-sm btn-outline-primary">
                                <i class="bi bi-pencil"></i> Bewerken
                            </a>
                            <a href="./groetjes/groetjesSets.php?id=<?= $set->setId; ?>" class="btn btn-sm btn-outline-danger">
                                <i class="bi bi-trash"></i> Verwijderen
                            </a>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>

        <!-- Pagination -->
        <nav aria-label="Page navigation" class="mt-5">
            <ul class="pagination justify-content-center">
                <?php for ($i = 1; $i <= round($pagina); $i++): ?>
                    <li class="page-item <?= ($geenIdee == $i) ? 'active' : '' ?>">
                        <a class="page-link" href="setsadmin.php?id=<?= $i; ?>"><?= $i; ?></a>
                    </li>
                <?php endfor; ?>
            </ul>
        </nav>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"></script>
</body>

</html>