<?php include 'db_connect.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Health Tips | Aastha Padghan Medical</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap" rel="stylesheet">
    <style>body { font-family: 'Poppins', sans-serif; }</style>
</head>
<body class="bg-gray-50 text-gray-800">

   <?php include 'includes/header.php'; ?>

    <div class="bg-green-600 text-white py-12 text-center">
        <h1 class="text-3xl md:text-4xl font-bold">Health Awareness & Tips</h1>
        <p class="mt-2 text-green-100">Expert advice from our doctors for a healthy life.</p>
    </div>

    <section class="container mx-auto px-4 py-16">
        <div class="grid md:grid-cols-3 gap-8">
            <?php
            $sql = "SELECT * FROM health_tips ORDER BY id DESC";
            $result = $conn->query($sql);

            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    // Check image path
                    $imgSrc = (strpos($row['image'], 'assets') === 0) ? $row['image'] : 'assets/logo.png'; 
                    
                    echo '<div class="bg-white rounded-lg shadow-lg overflow-hidden hover:shadow-xl transition">';
                    echo '<img src="' . $imgSrc . '" class="w-full h-48 object-cover">';
                    echo '<div class="p-6">';
                    echo '<h3 class="text-xl font-bold text-gray-800 mb-2">' . $row['title'] . '</h3>';
                    echo '<p class="text-sm text-gray-500 mb-4">' . date('F d, Y', strtotime($row['created_at'])) . '</p>';
                    echo '<p class="text-gray-600 leading-relaxed mb-4">' . nl2br($row['content']) . '</p>';
                    
                    // Share Button (Optional: WhatsApp Share)
                    $shareText = "Read this health tip from Aastha Hospital: " . $row['title'];
                    echo '<a href="https://wa.me/?text=' . urlencode($shareText) . '" target="_blank" class="text-green-600 font-bold text-sm hover:underline">Share on WhatsApp →</a>';
                    
                    echo '</div>';
                    echo '</div>';
                }
            } else {
                echo '<p class="text-center col-span-3 text-gray-500">No health tips published yet.</p>';
            }
            ?>
        </div>
    </section>

<?php include 'includes/footer.php'; ?>

</body>
</html>