<?php
// Test pagination values
if (session_status() !== PHP_SESSION_ACTIVE) session_start();

$page = isset($_GET['page']) ? max(1, (int)($_GET['page'] ?? 1)) : 1;
$perPage = 18;

// Simulate the products count
require_once __DIR__ . '/data/products.json';
$json = file_get_contents(__DIR__ . '/data/products.json');
$products = json_decode($json, true) ?: [];
$totalProducts = count($products);
$totalPages = ceil($totalProducts / $perPage);

?>
<!DOCTYPE html>
<html>
<head>
    <title>Pagination Debug Test</title>
    <style>
        body { font-family: Arial; margin: 20px; }
        .test { padding: 15px; margin: 10px 0; border: 2px solid #ccc; }
        .good { background: #90EE90; border-color: #28a745; }
        .bad { background: #FFB6C6; border-color: #dc3545; }
        code { background: #f5f5f5; padding: 2px 6px; }
    </style>
</head>
<body>
    <h1>🧪 Pagination Debug Test</h1>
    
    <div class="test">
        <strong>URL:</strong> <code><?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?></code>
    </div>
    
    <div class="test">
        <strong>$_GET['page']:</strong> <code><?php echo isset($_GET['page']) ? htmlspecialchars($_GET['page']) : '(not set)'; ?></code>
    </div>
    
    <div class="test <?php echo $page > 1 ? 'good' : 'bad'; ?>">
        <strong>$page value:</strong> <code><?php echo $page; ?></code><br>
        <strong>Is $page > 1?</strong> <code><?php echo $page > 1 ? 'YES ✓' : 'NO ✗'; ?></code><br>
        <em>Previous button should be <?php echo $page > 1 ? 'ENABLED (orange)' : 'DISABLED (grey)'; ?></em>
    </div>
    
    <div class="test">
        <strong>Total products:</strong> <code><?php echo $totalProducts; ?></code><br>
        <strong>Per page:</strong> <code><?php echo $perPage; ?></code><br>
        <strong>Total pages:</strong> <code><?php echo $totalPages; ?></code>
    </div>
    
    <div class="test <?php echo $totalPages > 1 ? 'good' : 'bad'; ?>">
        <strong>$totalPages > 1?</strong> <code><?php echo $totalPages > 1 ? 'YES ✓' : 'NO ✗'; ?></code><br>
        <em>Pagination should <?php echo $totalPages > 1 ? 'SHOW' : 'NOT SHOW'; ?></em>
    </div>
    
    <hr>
    
    <h2>Test URLs:</h2>
    <ul>
        <li><a href="pagination_test.php?page=1">Test page=1</a></li>
        <li><a href="pagination_test.php?page=2">Test page=2</a></li>
        <li><a href="pagination_test.php?page=3">Test page=3</a></li>
    </ul>
    
    <h2>Expected Behavior:</h2>
    <ul>
        <li><strong>page=1:</strong> Previous button DISABLED (grey), Next button ENABLED</li>
        <li><strong>page=2:</strong> Previous button ENABLED (orange), Next button ENABLED</li>
        <li><strong>page=3:</strong> Previous button ENABLED (orange), Next button depends on total pages</li>
    </ul>
</body>
</html>
