
<?php
 include "./header.php";
$postsFile = __DIR__ . '/admin/posts.json';
$posts = file_exists($postsFile) ? json_decode(file_get_contents($postsFile), true) : [];
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="google-adsense-account" content="ca-pub-3429299386991375">
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>CryptoBitSense</title>
  <link rel="stylesheet" href="./assets/home.css" />  
  <link href="https://fonts.googleapis.com/css2?family=Anton&display=swap" rel="stylesheet">
  <style>
      .privacy{
          text-decoration: none;
          font-size: 16px; 
          color: #333;
      }
  </style>
</head>
<body>
<div class="flex-box">
    <div class="homewrap">
        <?php if (empty($posts)): ?>
        <div class="no-posts">No posts available.</div>
        <?php else: ?>
        <?php foreach (array_reverse($posts) as $index => $post): ?>
            <div class="post-card">
                <div class="imagePart">
                    <?php if (!empty($post['imageurl'])): ?>
                        <img class="image" src="../<?= htmlspecialchars($post['imageurl']) ?>" alt="Post image">
                    <?php endif; ?>
                </div>
            
                <div class="infoPart">
                        <h2 class="posttit"><?= htmlspecialchars($post['title']) ?></h2>
                    <div class="info">
                        BY: <?= htmlspecialchars($post['author'] ?? 'Admin') ?> — <?= htmlspecialchars($post['published_at']) ?>
                    </div>
                    <div class="tags">
                        <?php if (!empty($post['tags'])): ?>
                        <?php foreach ($post['tags'] as $tag): ?>
                            <span>#<?= htmlspecialchars($tag) ?></span>
                        <?php endforeach; ?>
                        <?php endif; ?> 
                    </div>

                    <p class="post-meta"><?= htmlspecialchars($post['summary']) ?></p>
                    <div class="actions">
                        <a href="postDetail?id=<?= urlencode($post['id']) ?>">Read More</a>
                    </div>
                </div>
            </div>
            <?php endforeach; ?>
            <?php endif; ?>
    </div>

    <div class="sideContent">
    </div>
</div>



<br>
<br>
<br>
<br>
<?php include "footer.php"; ?>
</body>
</html>
