<?php
// --- Database connection ---
include "config.php";

// --- Categories and Filter Logic ---
$categories = ['Tools', 'Martin', 'Shock', 'Trend', 'Grid', 'Comprehensive'];
$filter = isset($_GET['category']) && in_array($_GET['category'], $categories) ? $_GET['category'] : 'All';

if ($filter === 'All') {
    $stmt = $dbh->query("SELECT * FROM ea_tools ORDER BY id DESC");
} else {
    $stmt = $dbh->prepare("SELECT * FROM ea_tools WHERE category = :category ORDER BY id DESC");
    $stmt->execute(['category' => $filter]);
}
$eaItems = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>EA and VPS Dashboard</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0; padding: 20px;
            background: #f5f7fa;
        }

        .container {
            display: flex;
            gap: 30px;
            align-items: flex-start;
        }

        .left, .right {
            flex: 1;
        }

        /* --- Navigation --- */
        .nav {
            margin-bottom: 20px;
        }
        .nav a {
            display: inline-block;
            margin-right: 10px;
            padding: 8px 14px;
            background: #E97451;
            color: #fff;
            text-decoration: none;
            border-radius: 6px;
        }
        .nav a.active {
            background: #3659e3;
        }

        /* --- EA Cards --- */
        .ea-container {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
            gap: 20px;
        }
        .ea-card {
            background: white;
            border-radius: 10px;
            padding: 16px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        .ea-card img {
            max-width: 100%;
            border-radius: 8px;
            margin-bottom: 10px;
        }
        .ea-title {
            font-size: 18px;
            font-weight: bold;
            margin: 10px 0 6px;
        }
        .ea-category {
            font-size: 12px;
            color: #777;
            margin-bottom: 8px;
        }
        .ea-description {
            font-size: 14px;
            color: #333;
            margin-bottom: 12px;
        }
        .ea-income {
            font-size: 14px;
            color: #23c0a8;
            margin-bottom: 12px;
        }
        .ea-price {
            font-size: 16px;
            font-weight: bold;
            color: #3659e3;
        }
        .ea-old-price {
            font-size: 14px;
            color: #aaa;
            text-decoration: line-through;
            margin-left: 10px;
        }

        /* --- VPS Cards --- */
        .vps-card {
            background: white;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
            padding: 20px;
            margin-bottom: 20px;
        }
        .vps-card .title {
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 10px;
        }
        .vps-specs {
            font-size: 14px;
            line-height: 1.6;
        }
        .vps-button {
            margin-top: 12px;
            background: #f4c95d;
            padding: 8px 14px;
            font-weight: bold;
            border: none;
            border-radius: 6px;
            cursor: pointer;
        }
    </style>
</head>
<body>

<div class="nav">
    <a href="?category=All" class="<?= ($filter === 'All') ? 'active' : '' ?>">All</a>
    <?php foreach ($categories as $cat): ?>
        <a href="?category=<?= urlencode($cat) ?>" class="<?= ($filter === $cat) ? 'active' : '' ?>">
            <?= htmlspecialchars($cat) ?>
        </a>
    <?php endforeach; ?>
</div>

<div class="container">
    <!-- Left: EA Tools -->
    <div class="left">
        <div class="ea-container">
            <?php foreach ($eaItems as $ea): ?>
                <div class="ea-card">
                    <?php if (!empty($ea['image'])): ?>
                        <img src="<?= htmlspecialchars($ea['image']) ?>" alt="<?= htmlspecialchars($ea['title']) ?>">
                    <?php endif; ?>
                    <div class="ea-title"><?= htmlspecialchars($ea['title']) ?></div>
                    <div class="ea-category"><?= htmlspecialchars($ea['category']) ?></div>
                    <?php if (!empty($ea['income_last_year'])): ?>
                        <div class="ea-income">Income Last Year: <?= htmlspecialchars($ea['income_last_year']) ?></div>
                    <?php endif; ?>
                    <div class="ea-description"><?= nl2br(htmlspecialchars($ea['description'])) ?></div>
                    <div>
                        <span class="ea-price">$<?= number_format($ea['price'], 2) ?></span>
                        <?php if (!empty($ea['old_price']) && $ea['old_price'] > $ea['price']): ?>
                            <span class="ea-old-price">$<?= number_format($ea['old_price'], 2) ?></span>
                        <?php endif; ?>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    </div>

    <!-- Right: VPS Plans -->
    <div class="right">
        <div class="vps-card">
            <div class="title">VPS Ultra</div>
            <div class="vps-specs">
                • 2 CPU<br>
                • 2GB RAM<br>
                • 60GB HDD<br>
                • 2Mbps Bandwidth
            </div>
            <button class="vps-button">Open for Free</button>
        </div>

        <div class="vps-card">
            <div class="title">VPS Standard</div>
            <div class="vps-specs">
                • 1 CPU<br>
                • 1GB RAM<br>
                • 40GB HDD<br>
                • 1Mbps Bandwidth
            </div>
            <button class="vps-button">Open for Free</button>
        </div>
    </div>
</div>

</body>
</html>
