<?php
 include "./header.php";

$filename = 'data/market_analysis.json';
$market = file_exists($filename) ? json_decode(file_get_contents($filename), 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/inder.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($market)): ?>
            <div class="no-posts">No posts available.</div>
            <?php else: ?>
            <?php foreach (array_reverse($market) as $index => $mark): ?>
            <div class="post-card">
                <div class="imagePart">
                    <?php if (!empty($mark['imageurl'])): ?>
                        <img class="image" src="../<?= htmlspecialchars($mark['imageurl']) ?>" alt="Post image">
                    <?php endif; ?>
                </div>
            
                <div class="infoPart">
                        <h2 class="posttit"><?= htmlspecialchars($mark['title']) ?></h2>
                    <div class="info">
                        By <?= htmlspecialchars($mark['author'] ?? 'Admin') ?> — <?= htmlspecialchars($mark['published_at']) ?>
                    </div>
                    <div class="tags">
                        <?php if (!empty($mark['tags'])): ?>
                        <?php foreach ($mark['tags'] as $tag): ?>
                            <span>#<?= htmlspecialchars($tag) ?></span>
                        <?php endforeach; ?>
                        <?php endif; ?> 
                    </div>

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