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

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

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