<?php
// Include the database connection
include('./config/connect.php');

// Check if 'id' is provided in the URL
if (isset($_GET['id'])) {
    $articleId = (int)$_GET['id'];

    // Fetch the main article details
    $articleQuery = "SELECT mainTitle, mainImage, mainDescription, url, DATE_FORMAT(date, '%d-%m-%Y') AS formattedDate, btnName FROM articles WHERE id = ?";
    $stmt = $mysqli->prepare($articleQuery);

    if ($stmt === false) {
        die("MySQL prepare error: " . $mysqli->error);
    }

    $stmt->bind_param("i", $articleId);
    $stmt->execute();
    $stmt->store_result();

    // Bind results
    $stmt->bind_result($mainTitle, $mainImage, $mainDescription, $url, $formattedDate, $btnName);
    if (!$stmt->fetch()) {
        // If no article is found, display an error message
        echo "<div class='bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded text-center my-6'>Article not found!</div>";
        exit;
    }
    $stmt->close();

    // Fetch the dynamic content for the article
    $contentQuery = "SELECT contentTitle, contentDescription FROM article_content WHERE article_id = ?";
    $contentStmt = $mysqli->prepare($contentQuery);

    if ($contentStmt === false) {
        die("MySQL prepare error: " . $mysqli->error);
    }

    $contentStmt->bind_param("i", $articleId);
    $contentStmt->execute();
    $contentResult = $contentStmt->get_result();

    $dynamicContent = [];
    while ($row = $contentResult->fetch_assoc()) {
        $dynamicContent[] = $row;
    }

    $contentStmt->close();

    // Fetch more related articles than needed to ensure we have enough after filtering
    $relatedQuery = "SELECT id, mainTitle, mainImage, mainDescription, DATE_FORMAT(date, '%d-%m-%Y') AS formattedDate FROM articles WHERE id != ? ORDER BY date DESC LIMIT 12";
    $relatedStmt = $mysqli->prepare($relatedQuery);
    
    if ($relatedStmt === false) {
        die("MySQL prepare error: " . $mysqli->error);
    }
    
    $relatedStmt->bind_param("i", $articleId);
    $relatedStmt->execute();
    $relatedResult = $relatedStmt->get_result();
    
    // Initialize arrays for sorting
    $relatedWithImages = [];
    $relatedWithoutImages = [];
    
    // Categorize related posts based on image availability
    while ($row = $relatedResult->fetch_assoc()) {
        if (hasValidImage($row['mainImage'])) {
            // Limit to 3 articles with images
            if (count($relatedWithImages) < 3) {
                $relatedWithImages[] = $row;
            }
        } else {
            // Limit to 3 articles without images
            if (count($relatedWithoutImages) < 3) {
                $relatedWithoutImages[] = $row;
            }
        }
    }
    
    $relatedStmt->close();
} else {
    // If no ID is provided, redirect with an error message
    header("Location: index.php");
    exit;
}

// Helper function to check if image exists and is valid
function hasValidImage($image_path) {
    if (empty($image_path) || $image_path == 'null' || $image_path == 'undefined') {
        return false;
    }
    
    $full_path = './uploads/' . $image_path;
    
    if (file_exists($full_path) && is_file($full_path) && is_readable($full_path)) {
        $file_info = getimagesize($full_path);
        if ($file_info && strpos($file_info['mime'], 'image/') === 0) {
            return true;
        }
    }
    
    return false;
}

// Get shortened text with ellipsis
function shortenText($text, $length) {
    if (strlen($text) <= $length) {
        return $text;
    }
    
    return substr($text, 0, $length) . '...';
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo htmlspecialchars($mainTitle); ?> - Mamta Music Banaras</title>
    
    <!-- Favicon -->
    <link rel="icon" type="image/png" href="./image/logo.png">
    
    <!-- Tailwind CSS -->
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    
    <!-- Font Awesome for icons -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    
      <script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js" crossorigin="anonymous"></script>
   <script>
  window.googletag = window.googletag || { cmd: [] };

  googletag.cmd.push(function () {
    // ✅ Slot 1
    googletag.defineSlot(
      '/21952429235,23013544364/be_mamatamusicbanaras_300x250',
      [300, 250],
      'div-gpt-ad-1750150538756-0'
    ).addService(googletag.pubads());

    // ✅ Slot 2 (different div ID)
    googletag.defineSlot(
      '/21952429235,23013544364/be_mamatamusicbanaras_300x250_1',
      [300, 250],
      'div-gpt-ad-1750150625318-0'
    ).addService(googletag.pubads());

    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
  });
</script>
      <!-- Google Analytics -->
      <script async src="https://www.googletagmanager.com/gtag/js?id=G-44TWGSSRXK"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        gtag('config', 'G-44TWGSSRXK');
    </script>
    
    <style>
        body {
            font-family: 'Poppins', sans-serif;
            background-color: #f8f9fa;
            color: #333;
            line-height: 1.6;
        }
        
        /* Article content styling */
        .article-content p {
            margin-bottom: 1.5rem;
        }
        
        .article-content h2 {
            font-size: 1.75rem;
            font-weight: 600;
            margin-top: 2rem;
            margin-bottom: 1rem;
            color: #374151;
        }
        
        .article-content h3 {
            font-size: 1.5rem;
            font-weight: 600;
            margin-top: 1.75rem;
            margin-bottom: 0.75rem;
            color: #374151;
        }
        
        .article-content ul {
            list-style-type: disc;
            margin-left: 1.5rem;
            margin-bottom: 1.5rem;
        }
        
        .article-content ol {
            list-style-type: decimal;
            margin-left: 1.5rem;
            margin-bottom: 1.5rem;
        }
        
        .article-content li {
            margin-bottom: 0.5rem;
        }
        
        .article-content a {
            color: #4F46E5;
            text-decoration: none;
            transition: color 0.3s;
        }
        
        .article-content a:hover {
            color: #4338CA;
            text-decoration: underline;
        }
        
        /* Related article card styling */
        .related-card {
            transition: all 0.3s ease;
            opacity: 0;
            animation: fadeInUp 0.5s ease-out forwards;
        }
        
        .related-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0,0,0,0.1);
        }
        
        /* Dynamic content styling */
        .dynamic-content-item {
            transition: all 0.3s ease;
            animation: fadeIn 0.6s ease-out;
            border-left: 4px solid #6366F1;
        }
        
        .dynamic-content-item:hover {
            background-color: #F9FAFB;
        }
        
        /* Image container aspect ratio */
        .img-container {
            position: relative;
            padding-top: 56.25%; /* 16:9 aspect ratio */
            overflow: hidden;
        }
        
        .img-container img {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        
        /* Animations */
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translate3d(0, 30px, 0);
            }
            to {
                opacity: 1;
                transform: translate3d(0, 0, 0);
            }
        }
        
        @keyframes fadeIn {
            from {
                opacity: 0;
            }
            to {
                opacity: 1;
            }
        }
        
        /* Custom button styles */
        .custom-button {
            transition: all 0.3s ease;
        }
        
        .custom-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        
        /* Ad container styling */
        .ad-container {
            background: linear-gradient(135deg, #f6f8fa, #e9ecef);
            border: 1px dashed #adb5bd;
            transition: all 0.3s ease;
        }
        
        /* Section divider */
        .section-divider {
            height: 1px;
            background: linear-gradient(to right, rgba(99, 102, 241, 0), rgba(99, 102, 241, 0.5), rgba(99, 102, 241, 0));
            margin: 2rem 0;
        }
        
        /* Quote style for no-image articles */
        .quote-style:before {
            content: '"';
            font-size: 3rem;
            font-family: Georgia, serif;
            position: absolute;
            top: 10px;
            left: 10px;
            line-height: 1;
            opacity: 0.1;
        }
    </style>
</head>

<body>
    <?php include('./header.php'); ?>
    
    <main class="pt-24 pb-12">
        <div class="container mx-auto px-4">
            <!-- Top Ad Space -->
  <div class="flex justify-center items-center py-4">

<div id="div-gpt-ad-1750150538756-0">
  <script>
    googletag.cmd.push(function () {
      googletag.display('div-gpt-ad-1750150538756-0');
    });
  </script>
</div>
            </div>
            
            <!-- Article Content Container -->
            <div class="bg-white rounded-xl overflow-hidden shadow-md mb-8">
                <!-- Article Header Section -->
                <div class="p-6 md:p-8">
                    <div class="flex items-center text-sm text-gray-500 mb-4">
                        <span class="flex items-center mr-4">
                            <i class="far fa-calendar-alt mr-2"></i>
                            <?php echo htmlspecialchars($formattedDate); ?>
                        </span>
                        <a href="javascript:history.back()" class="text-indigo-600 hover:text-indigo-800 flex items-center no-underline">
                            <i class="fas fa-arrow-left mr-1"></i> Back
                        </a>
                    </div>
                    
                    <h1 class="text-3xl md:text-4xl font-bold text-gray-800 leading-tight mb-6">
                        <?php echo htmlspecialchars($mainTitle); ?>
                    </h1>
                    
                    <!-- Main Article Image -->
                    <?php if (hasValidImage($mainImage)): ?>
                    <div class="rounded-lg overflow-hidden mb-6 shadow-sm">
                        <img src="./uploads/<?php echo htmlspecialchars($mainImage); ?>" alt="<?php echo htmlspecialchars($mainTitle); ?>" class="w-full h-auto max-h-96 object-cover">
                    </div>
                    <?php endif; ?>
                    
                    <!-- Main Article Content -->
                    <div class="article-content text-gray-700 text-lg leading-relaxed mb-8">
                        <?php echo nl2br(htmlspecialchars($mainDescription)); ?>
                    </div>
                    
                    <!-- Download Button (if URL is available) -->
                    <?php if (!empty($url)): ?>
                    <div class="my-8 flex justify-center">
                        <a href="<?php echo htmlspecialchars($url); ?>" class="bg-indigo-600 hover:bg-indigo-700 text-white font-semibold py-3 px-8 rounded-lg transition-all duration-300 no-underline custom-button flex items-center">
                            <i class="fas fa-download mr-2"></i>
                            <?php echo !empty($btnName) ? htmlspecialchars($btnName) : 'Download'; ?>
                        </a>
                    </div>
                    <?php endif; ?>
                </div>
                
                <!-- Mid Ad Space -->
             <div class="flex justify-center items-center py-4">

                  <div id="div-gpt-ad-1750150625318-0">
  <script>
    googletag.cmd.push(function () {
      googletag.display('div-gpt-ad-1750150625318-0');
    });
  </script>
                </div>
</div>
                
                <!-- Dynamic Content Section -->
                <?php if (!empty($dynamicContent)): ?>
                <div class="px-6 md:px-8 pb-8">
                    <h2 class="text-2xl font-bold text-gray-800 mb-6 relative inline-block">
                        Additional Information
                        <span class="absolute bottom-0 left-0 w-full h-1 bg-indigo-500 rounded"></span>
                    </h2>
                    
                    <div class="space-y-6">
                        <?php 
                        $contentCount = 0;
                        foreach ($dynamicContent as $content): 
                            $contentCount++;
                        ?>
                            <div class="dynamic-content-item bg-indigo-50 p-5 rounded-lg">
                                <h3 class="text-xl font-semibold text-gray-800 mb-3">
                                    <?php echo htmlspecialchars($content['contentTitle']); ?>
                                </h3>
                                <div class="text-gray-700">
                                    <?php echo nl2br(htmlspecialchars($content['contentDescription'])); ?>
                                </div>
                            </div>
                                                  <?php endforeach; ?>
                    </div>
                </div>
                <?php endif; ?>
            </div>
            
            <!-- Related Articles Section -->
            <?php if (!empty($relatedWithImages) || !empty($relatedWithoutImages)): ?>
            <div class="bg-white rounded-xl overflow-hidden shadow-md p-6 md:p-8 mb-8">
                <h2 class="text-2xl font-bold text-gray-800 mb-6 relative inline-block">
                    Related Articles
                    <span class="absolute bottom-0 left-0 w-full h-1 bg-indigo-500 rounded"></span>
                </h2>
                
                              
                <!-- SECTION 1: ARTICLES WITH IMAGES -->
                <?php if (!empty($relatedWithImages)): ?>
                <div class="mb-8">
                    <h3 class="text-xl font-semibold text-gray-800 mb-4 pb-2 border-b border-gray-200 section-heading">
                        Trending Articles
                    </h3>
                    
                    <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
                        <?php foreach ($relatedWithImages as $index => $post): ?>
                            <div class="related-card article-card-with-image rounded-lg overflow-hidden shadow-sm" 
                                 style="animation-delay: <?php echo $index * 0.1; ?>s"
                                 onclick="window.location.href='show_article.php?id=<?php echo $post['id']; ?>'">
                                
                                <div class="img-container">
                                    <img src="./uploads/<?php echo htmlspecialchars($post['mainImage']); ?>" alt="<?php echo htmlspecialchars($post['mainTitle']); ?>">
                                </div>
                                
                                <div class="p-4">
                                    <h3 class="text-lg font-semibold text-gray-800 mb-2 line-clamp-2 leading-tight">
                                        <?php echo htmlspecialchars(shortenText($post['mainTitle'], 60)); ?>
                                    </h3>
                                    <div class="text-xs text-gray-500 mb-3 flex items-center">
                                        <i class="far fa-calendar-alt mr-1"></i> <?php echo htmlspecialchars($post['formattedDate']); ?>
                                    </div>
                                    <p class="text-gray-600 mb-4 line-clamp-3 text-sm leading-relaxed">
                                        <?php echo nl2br(htmlspecialchars(shortenText($post['mainDescription'], 100))); ?>
                                    </p>
                                    <a href="show_article.php?id=<?php echo $post['id']; ?>" class="inline-block bg-indigo-600 hover:bg-indigo-700 text-white text-sm font-medium py-2 px-4 rounded-lg transition-colors duration-300 no-underline read-more-btn">
                                        Read Article <i class="fas fa-chevron-right text-xs ml-1"></i>
                                    </a>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                </div>
                
                <!-- Section divider between the two article types -->
                <?php if (!empty($relatedWithoutImages)): ?>
                <div class="section-divider"></div>
                <?php endif; ?>
                <?php endif; ?>
                
                <!-- SECTION 2: ARTICLES WITHOUT IMAGES -->
                <?php if (!empty($relatedWithoutImages)): ?>
                <div>
                    <h3 class="text-xl font-semibold text-gray-800 mb-4 pb-2 border-b border-gray-200 section-heading">
                        Expert Insights
                    </h3>
                    
                    <!-- Mobile vertical layout for articles without images -->
                    <div class="block md:hidden space-y-6">
                        <?php foreach ($relatedWithoutImages as $index => $post): ?>
                            <div class="related-card article-card-no-image rounded-lg overflow-hidden cursor-pointer bg-white border border-gray-200 shadow-sm" 
                                 style="animation-delay: <?php echo $index * 0.1; ?>s"
                                 onclick="window.location.href='show_article.php?id=<?php echo $post['id']; ?>'">
                                
                                <div class="p-5 relative quote-style">
                                    <span class="inline-block bg-gray-100 text-gray-600 rounded px-3 py-1 text-xs font-medium mb-3">
                                        <i class="far fa-calendar-alt mr-1"></i> <?php echo htmlspecialchars($post['formattedDate']); ?>
                                    </span>
                                    
                                    <h5 class="text-lg font-semibold text-gray-800 mt-2 mb-3 line-clamp-2 leading-tight">
                                        <?php echo htmlspecialchars(shortenText($post['mainTitle'], 70)); ?>
                                    </h5>
                                    
                                    <p class="text-gray-600 mb-4 line-clamp-4 text-sm leading-relaxed">
                                        <?php echo nl2br(htmlspecialchars(shortenText($post['mainDescription'], 120))); ?>
                                    </p>
                                    
                                    <a href="show_article.php?id=<?php echo $post['id']; ?>" class="inline-block bg-white border border-indigo-600 text-indigo-600 hover:bg-indigo-50 text-sm font-medium py-2 px-4 rounded-lg transition-colors duration-300 no-underline read-more-btn">
                                        Read Article <i class="fas fa-chevron-right text-xs ml-1"></i>
                                    </a>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                    
                    <!-- Desktop layout for articles without images -->
                    <div class="hidden md:block">
                        <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
                            <?php foreach ($relatedWithoutImages as $index => $post): ?>
                                <div class="related-card article-card-no-image rounded-lg overflow-hidden cursor-pointer bg-white border border-gray-200 shadow-sm hover:shadow-lg" 
                                     style="animation-delay: <?php echo $index * 0.1; ?>s"
                                     onclick="window.location.href='show_article.php?id=<?php echo $post['id']; ?>'">
                                    
                                    <div class="p-6 flex flex-col relative quote-style" style="min-height: 250px;">
                                        <span class="inline-block bg-gray-100 text-gray-600 rounded px-3 py-1 text-xs font-medium mb-3">
                                            <i class="far fa-calendar-alt mr-1"></i> <?php echo htmlspecialchars($post['formattedDate']); ?>
                                        </span>
                                        
                                        <h5 class="text-xl font-semibold text-gray-800 mb-3 line-clamp-2 leading-tight">
                                            <?php echo htmlspecialchars(shortenText($post['mainTitle'], 60)); ?>
                                        </h5>
                                        
                                        <p class="text-gray-600 mb-4 flex-grow line-clamp-4 leading-relaxed">
                                            <?php echo nl2br(htmlspecialchars(shortenText($post['mainDescription'], 150))); ?>
                                        </p>
                                        
                                        <div class="mt-auto pt-3 border-t border-gray-100">
                                            <a href="show_article.php?id=<?php echo $post['id']; ?>" 
                                               onclick="event.stopPropagation();"
                                               class="inline-block bg-white border border-indigo-600 text-indigo-600 hover:bg-indigo-50 font-medium py-2 px-5 rounded-lg transition-all duration-300 no-underline read-more-btn">
                                                Read Article <i class="fas fa-arrow-right text-xs ml-1"></i>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    </div>
                </div>
                <?php endif; ?>
            </div>
            <?php endif; ?>
            
           <!-- Enhanced Share Article Section - Alternative Design -->
<div class="bg-white rounded-xl overflow-hidden shadow-md mb-8">
    <!-- Header with gradient background -->
    <div class="bg-gradient-to-r from-indigo-600 to-purple-600 p-6 text-white">
        <h2 class="text-xl font-bold mb-1">Share This Article</h2>
        <p class="text-white text-opacity-80 text-sm">Help others discover this valuable content</p>
    </div>
    
    <div class="p-6 md:p-8">
        <!-- Share Buttons Grid Layout -->
        <div class="grid grid-cols-2 md:grid-cols-4 gap-4">
            <!-- Facebook -->
            <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode("https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); ?>" 
               target="_blank" 
               class="share-btn flex flex-col items-center justify-center bg-white hover:bg-blue-50 border border-gray-200 rounded-lg p-4 transition-all duration-300 group">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mb-2 group-hover:bg-blue-600 transition-colors duration-300">
                    <i class="fab fa-facebook-f text-blue-600 group-hover:text-white transition-colors duration-300"></i>
                </div>
                <span class="text-gray-700 text-sm group-hover:text-blue-600 transition-colors duration-300">Facebook</span>
            </a>
            
            <!-- Twitter -->
            <a href="https://twitter.com/intent/tweet?url=<?php echo urlencode("https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); ?>&text=<?php echo urlencode($mainTitle); ?>" 
               target="_blank" 
               class="share-btn flex flex-col items-center justify-center bg-white hover:bg-blue-50 border border-gray-200 rounded-lg p-4 transition-all duration-300 group">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mb-2 group-hover:bg-blue-400 transition-colors duration-300">
                    <i class="fab fa-twitter text-blue-400 group-hover:text-white transition-colors duration-300"></i>
                </div>
                <span class="text-gray-700 text-sm group-hover:text-blue-400 transition-colors duration-300">Twitter</span>
            </a>
            
            <!-- WhatsApp -->
            <a href="https://api.whatsapp.com/send?text=<?php echo urlencode($mainTitle . " - https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); ?>" 
               target="_blank" 
               class="share-btn flex flex-col items-center justify-center bg-white hover:bg-green-50 border border-gray-200 rounded-lg p-4 transition-all duration-300 group">
                <div class="w-12 h-12 rounded-full bg-green-100 flex items-center justify-center mb-2 group-hover:bg-green-500 transition-colors duration-300">
                    <i class="fab fa-whatsapp text-green-500 group-hover:text-white transition-colors duration-300"></i>
                </div>
                <span class="text-gray-700 text-sm group-hover:text-green-500 transition-colors duration-300">WhatsApp</span>
            </a>
            
            <!-- Email -->
            <a href="mailto:?subject=<?php echo urlencode($mainTitle); ?>&body=<?php echo urlencode("Check out this article: https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); ?>" 
               class="share-btn flex flex-col items-center justify-center bg-white hover:bg-red-50 border border-gray-200 rounded-lg p-4 transition-all duration-300 group">
                <div class="w-12 h-12 rounded-full bg-red-100 flex items-center justify-center mb-2 group-hover:bg-red-500 transition-colors duration-300">
                    <i class="fas fa-envelope text-red-500 group-hover:text-white transition-colors duration-300"></i>
                </div>
                <span class="text-gray-700 text-sm group-hover:text-red-500 transition-colors duration-300">Email</span>
            </a>
        </div>
        
        <!-- Copy Link Button - Full Width -->
        <div class="mt-4">
            <button onclick="copyArticleLink()" 
                    class="w-full flex items-center justify-center bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-3 px-4 rounded-lg transition-all duration-300 border border-gray-200">
                <i class="fas fa-link mr-2"></i>
                <span id="copyLinkText">Copy Article Link</span>
            </button>
        </div>
    </div>
    
    <!-- Toast notification for link copied -->
    <div id="copyToast" class="fixed bottom-4 right-4 bg-gray-800 text-white px-4 py-2 rounded-lg opacity-0 transition-opacity duration-300 z-50 shadow-lg">
        <div class="flex items-center">
            <i class="fas fa-check-circle mr-2 text-green-400"></i>
            Link copied to clipboard!
        </div>
    </div>
</div>

        </div>
    </main>
    
    <?php include('./footer.php'); ?>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Make related article cards clickable
            document.querySelectorAll('.related-card').forEach(card => {
                card.addEventListener('click', function(event) {
                    // Prevent default if the click is on a link
                    if (event.target.tagName === 'A' || event.target.closest('a')) {
                        return;
                    }
                    
                    const link = this.querySelector('a');
                    if (link) {
                        window.location.href = link.getAttribute('href');
                    }
                });
            });
        });

        function copyArticleLink() {
        // Create a temporary input element
        const tempInput = document.createElement('input');
        tempInput.value = window.location.href;
        document.body.appendChild(tempInput);
        
        // Select and copy the link
        tempInput.select();
        document.execCommand('copy');
        
        // Remove the temporary element
        document.body.removeChild(tempInput);
        
        // Update button text temporarily
        const copyLinkText = document.getElementById('copyLinkText');
        if (copyLinkText) {
            const originalText = copyLinkText.innerText;
            copyLinkText.innerText = 'Link Copied!';
            setTimeout(() => {
                copyLinkText.innerText = originalText;
            }, 2000);
        }
        
        // Show toast notification
        const toast = document.getElementById('copyToast');
        toast.style.opacity = '1';
        setTimeout(() => {
            toast.style.opacity = '0';
        }, 2000);
    }
    </script>
</body>
</html>