<?php
declare(strict_types=1);

require_once __DIR__ . '/php/gate/helpers.php';
require_once __DIR__ . '/php/gate/turnstile.php';

$captchaOn = gate_turnstile_enabled();
$siteKey = gate_turnstile_site_key();

if (!$captchaOn) {
    require __DIR__ . '/check.php';
    exit;
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="robots" content="noindex, nofollow"/>
<title></title>
<?php if ($siteKey !== ''): ?>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<?php endif; ?>
<style>
  :root { --accent: #e60028; --bg: #f4f5f7; }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--bg); padding: 1.25rem;
    font-family: system-ui, Arial, sans-serif;
  }
  .captcha-wrap { display: flex; justify-content: center; min-height: 65px; }
</style>
</head>
<body>
<main class="captcha-wrap" role="main">
<?php if ($siteKey !== ''): ?>
  <form id="gate-form" method="post" action="check.php">
    <div class="cf-turnstile" data-sitekey="<?= htmlspecialchars($siteKey, ENT_QUOTES, 'UTF-8') ?>" data-theme="light" data-callback="onTurnstileOk"></div>
  </form>
  <script>
  function onTurnstileOk() {
    document.getElementById("gate-form").submit();
  }
  </script>
<?php endif; ?>
</main>
</body>
</html>
