<?php
// Get related articles from the same category
$current_category = isset($article_category) ? $article_category : 'Industry Insights';
$current_slug = isset($article_slug) ? $article_slug : '';

// Define related articles for different categories
$related_articles = [
    'Industry Insights' => [
        [
            'title' => 'UK Property Market Data Trends 2024',
            'slug' => 'uk-property-market-data-trends',
            'category' => 'Industry Insights',
            'read_time' => '8 min read'
        ],
        [
            'title' => 'E-commerce Trends UK 2025',
            'slug' => 'ecommerce-trends-uk-2025',
            'category' => 'Industry Insights',
            'read_time' => '6 min read'
        ],
        [
            'title' => 'Manufacturing Supply Chain Optimization',
            'slug' => 'manufacturing-supply-chain-optimization',
            'category' => 'Industry Insights',
            'read_time' => '10 min read'
        ]
    ],
    'Technology' => [
        [
            'title' => 'Python Data Pipeline Tools 2025',
            'slug' => 'python-data-pipeline-tools-2025',
            'category' => 'Technology',
            'read_time' => '12 min read'
        ],
        [
            'title' => 'Selenium vs Playwright Comparison',
            'slug' => 'selenium-vs-playwright-comparison',
            'category' => 'Technology',
            'read_time' => '8 min read'
        ],
        [
            'title' => 'Python Scrapy Enterprise Guide',
            'slug' => 'python-scrapy-enterprise-guide',
            'category' => 'Technology',
            'read_time' => '15 min read'
        ]
    ],
    'Web Scraping' => [
        [
            'title' => 'Web Scraping Compliance UK Guide',
            'slug' => 'web-scraping-compliance-uk-guide',
            'category' => 'Web Scraping',
            'read_time' => '10 min read'
        ],
        [
            'title' => 'Handling CAPTCHAs in Web Scraping',
            'slug' => 'handling-captchas-scraping',
            'category' => 'Web Scraping',
            'read_time' => '7 min read'
        ],
        [
            'title' => 'JavaScript Heavy Sites Scraping',
            'slug' => 'javascript-heavy-sites-scraping',
            'category' => 'Web Scraping',
            'read_time' => '9 min read'
        ]
    ],
    'Data Analytics' => [
        [
            'title' => 'Real-time Analytics with Streaming Data',
            'slug' => 'real-time-analytics-streaming-data',
            'category' => 'Data Analytics',
            'read_time' => '11 min read'
        ],
        [
            'title' => 'SQL Analytics Advanced Techniques',
            'slug' => 'sql-analytics-advanced-techniques',
            'category' => 'Data Analytics',
            'read_time' => '13 min read'
        ],
        [
            'title' => 'Predictive Analytics for Customer Churn',
            'slug' => 'predictive-analytics-customer-churn',
            'category' => 'Data Analytics',
            'read_time' => '9 min read'
        ]
    ]
];

// Get articles for current category, exclude current article
$category_articles = isset($related_articles[$current_category]) ? $related_articles[$current_category] : $related_articles['Industry Insights'];
$filtered_articles = array_filter($category_articles, function($article) use ($current_slug) {
    return $article['slug'] !== $current_slug;
});

// Limit to 3 articles
$display_articles = array_slice($filtered_articles, 0, 3);
?>

<section class="related-articles">
    <h2>Related Articles</h2>
    <div class="related-grid">
        <?php foreach ($display_articles as $article): ?>
        <article class="related-card">
            <span class="category"><?php echo htmlspecialchars($article['category']); ?></span>
            <h4><a href="/blog/articles/<?php echo htmlspecialchars($article['slug']); ?>.php"><?php echo htmlspecialchars($article['title']); ?></a></h4>
            <span class="read-time"><?php echo htmlspecialchars($article['read_time']); ?></span>
        </article>
        <?php endforeach; ?>
    </div>
    <div class="category-links">
        <a href="/blog/categories/<?php echo strtolower(str_replace(' ', '-', $current_category)); ?>.php" class="btn">More <?php echo htmlspecialchars($current_category); ?> Articles</a>
        <a href="/blog/" class="btn btn-secondary">All Blog Articles</a>
    </div>
</section>