<?php
/**
 * WebinHost - Official Blog & Hosting Guides Hub
 * High-authority technical tutorials & guides for Google SERPs & Social Traffic
 */

require_once __DIR__ . '/includes/blog-data.php';

$all_posts = get_all_blog_posts();

$page_title = 'Web Hosting Blog, WordPress Guides & Server Tutorials - WebinHost';
$page_description = 'Learn web hosting tutorials, WordPress speed optimization tips, NVMe server architectures, and reseller business guides on the official WebinHost blog.';
$page_keywords = 'web hosting blog, wordpress tutorials, webinhost guides, cpanel tips, server tutorials, cheap hosting blog, nvme hosting guide';

require_once __DIR__ . '/includes/header.php';
?>

<!-- PAGE HERO -->
<?php 
render_page_hero(
    'WebinHost Knowledge Hub & Guides',
    'Stay ahead with the latest web hosting innovations, WordPress speed optimization masterclasses, and server security guides.',
    'Official Blog & Resources',
    render_breadcrumbs('Blog', 'Resources', 'blog.php')
); 
?>

<!-- BLOG MAIN LISTING SECTION -->
<section class="section-padding" style="position: relative; padding-top: 40px;">
    <div class="container">
        
        <!-- Category Filter Tabs -->
        <div style="display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 45px;">
            <button class="filter-tab active" onclick="filterBlogCategory('all')"><i class="fas fa-th-large"></i> All Articles</button>
            <button class="filter-tab" onclick="filterBlogCategory('Hosting Guide')"><i class="fas fa-server"></i> Hosting Guides</button>
            <button class="filter-tab" onclick="filterBlogCategory('WordPress')"><i class="fab fa-wordpress"></i> WordPress</button>
            <button class="filter-tab" onclick="filterBlogCategory('Reseller')"><i class="fas fa-users-cog"></i> Reseller Business</button>
            <button class="filter-tab" onclick="filterBlogCategory('Technology')"><i class="fas fa-microchip"></i> Server Tech</button>
        </div>

        <!-- Blog Articles Grid -->
        <div class="blog-cards-grid" style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 30px;">
            
            <?php foreach ($all_posts as $slug => $post): 
                $post_url = 'blog-post.php?slug=' . urlencode($slug);
                $share_text = urlencode($post['title'] . ' - ' . SITE_URL . '/' . $post_url);
            ?>
                <article class="blog-card-item" data-category="<?= htmlspecialchars($post['category']) ?>" style="background: rgba(15, 23, 42, 0.65); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 18px; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; transition: all 0.3s ease; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);">
                    
                    <div>
                        <!-- Thumbnail Cover -->
                        <div style="position: relative; overflow: hidden; height: 210px;">
                            <a href="<?= $post_url ?>">
                                <img src="<?= $post['image'] ?>" alt="<?= htmlspecialchars($post['title']) ?>" style="width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s ease;" class="blog-thumb">
                            </a>
                            <span style="position: absolute; top: 15px; left: 15px; background: rgba(15, 23, 42, 0.85); color: <?= $post['category_color'] ?? '#fd9009' ?>; border: 1px solid <?= $post['category_color'] ?? '#fd9009' ?>; padding: 4px 12px; border-radius: 50px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; backdrop-filter: blur(8px);">
                                <?= htmlspecialchars($post['category']) ?>
                            </span>
                        </div>

                        <!-- Card Content -->
                        <div style="padding: 24px;">
                            
                            <!-- Meta Row -->
                            <div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-size: 0.82rem; color: var(--text-muted);">
                                <span><i class="far fa-calendar-alt" style="color: #fd9009; margin-right: 5px;"></i> <?= $post['date'] ?></span>
                                <span><i class="far fa-clock" style="color: #38bdf8; margin-right: 5px;"></i> <?= $post['read_time'] ?></span>
                            </div>

                            <!-- Post Title -->
                            <h2 style="font-size: 1.25rem; font-weight: 700; line-height: 1.4; margin-bottom: 12px;">
                                <a href="<?= $post_url ?>" style="color: #ffffff; text-decoration: none; transition: color 0.2s;" class="blog-title-link">
                                    <?= htmlspecialchars($post['title']) ?>
                                </a>
                            </h2>

                            <!-- Post Excerpt -->
                            <p style="color: var(--text-muted); font-size: 0.92rem; line-height: 1.6; margin-bottom: 18px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;">
                                <?= htmlspecialchars($post['excerpt']) ?>
                            </p>
                        </div>
                    </div>

                    <!-- Card Footer & Quick Actions -->
                    <div style="padding: 16px 24px; background: rgba(255, 255, 255, 0.02); border-top: 1px solid rgba(255, 255, 255, 0.06); display: flex; align-items: center; justify-content: space-between;">
                        <a href="<?= $post_url ?>" class="btn btn-primary btn-sm" style="padding: 8px 16px; font-size: 0.85rem; font-weight: 700; border-radius: 8px;">
                            Read Full Guide <i class="fas fa-arrow-right" style="margin-left: 5px;"></i>
                        </a>

                        <!-- Direct 1-Click WhatsApp & Social Share -->
                        <div style="display: flex; gap: 8px;">
                            <a href="https://api.whatsapp.com/send?text=<?= $share_text ?>" target="_blank" style="width: 32px; height: 32px; border-radius: 50%; background: rgba(37, 211, 102, 0.15); color: #25d366; display: flex; align-items: center; justify-content: center; text-decoration: none; font-size: 0.9rem; transition: transform 0.2s;" title="Share on WhatsApp">
                                <i class="fab fa-whatsapp"></i>
                            </a>
                            <a href="https://www.facebook.com/sharer/sharer.php?u=<?= urlencode(SITE_URL . '/' . $post_url) ?>" target="_blank" style="width: 32px; height: 32px; border-radius: 50%; background: rgba(24, 119, 242, 0.15); color: #38bdf8; display: flex; align-items: center; justify-content: center; text-decoration: none; font-size: 0.9rem; transition: transform 0.2s;" title="Share on Facebook">
                                <i class="fab fa-facebook-f"></i>
                            </a>
                        </div>
                    </div>

                </article>
            <?php endforeach; ?>

        </div>

    </div>
</section>

<!-- FREQUENTLY ASKED QUESTIONS -->
<?php render_faq_section(); ?>

<style>
/* Filter Buttons */
.filter-tab {
    padding: 10px 20px;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    border-radius: 50px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}
.filter-tab:hover, .filter-tab.active {
    background: #fd9009;
    color: #000000;
    border-color: #fd9009;
    font-weight: 700;
    box-shadow: 0 6px 18px rgba(253, 144, 9, 0.35);
}

/* Hover effects */
.blog-card-item:hover {
    transform: translateY(-5px);
    border-color: rgba(253, 144, 9, 0.35);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
}
.blog-card-item:hover .blog-thumb {
    transform: scale(1.05);
}
.blog-card-item:hover .blog-title-link {
    color: #fd9009 !important;
}
</style>

<script>
function filterBlogCategory(cat) {
    document.querySelectorAll('.filter-tab').forEach(el => el.classList.remove('active'));
    event.currentTarget.classList.add('active');

    var cards = document.querySelectorAll('.blog-card-item');
    cards.forEach(function(card) {
        if (cat === 'all' || card.getAttribute('data-category') === cat) {
            card.style.display = 'flex';
        } else {
            card.style.display = 'none';
        }
    });
}
</script>

<?php require_once __DIR__ . '/includes/footer.php'; ?>
