<?php
declare(strict_types=1);

require_once __DIR__ . "/config/db.php";
function e($s): string { return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }

$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($id <= 0) { http_response_code(404); die("Məktub tapılmadı."); }

$stmt = $pdo->prepare("SELECT * FROM `letters` WHERE id=? LIMIT 1");
$stmt->execute([$id]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$row) { http_response_code(404); die("Məktub tapılmadı."); }

$title = (string)($row['title'] ?? 'Məktub');
$body  = (string)($row['body_html'] ?? '');
?>

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

<!-- PAGE HEADER -->
<section class="page-header" style="background-image:url('/v2/img/ortho-bg.jpg');">
  <div class="page-header__overlay"></div>

  <div class="container page-header__content">

    <h1 class="page-title"><?= e($title) ?></h1>

    <nav class="breadcrumb" aria-label="breadcrumb">
      <a class="breadcrumb__link" href="/v2/">Ana səhifə</a>
      <span class="breadcrumb__sep">/</span>
      <a class="breadcrumb__link" href="/v2/#mektublar">Məktublar</a>
      
      <span class="breadcrumb__sep">/</span>
      
    </nav>

  </div>
</section>


<!-- CONTENT -->
<section class="container" style="max-width:960px; padding:40px 0;">

  <div class="content-area">
    <?= $body ?>
  </div>

</section>

<?php include __DIR__ . "/footer.php"; ?>