<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgo=">
    <title>Captcha</title>
    <script src="https://www.google.com/recaptcha/enterprise.js" async defer></script>
    <style>
      html, body {
        padding: 0;
        margin: 0;
      }

      @media screen and (min-width: 414px) and (max-width: 736px) {
          body > div {
          left: 0px !important;
        }
      }
      .g-recaptcha, h2 {
        width: 100vw;
        height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
      }

      h2 {
        color: rgb(204, 0, 0);
        text-align: center;
        font-family: sans-serif;
        display: none;
      }
    </style>
  </head>
  <body>
    <div class="g-recaptcha" data-sitekey="6LeJswgdAAAAAL3PDFqvhbmZQzNYxFg1Sbb0jnj-" data-callback="callback" data-action="redirect"></div>
    <h2>Please note, you didn't pass captcha verification</h2>
  </body>
  <script>
    function handleError() {
      document.querySelector('.g-recaptcha').style.display='none';
      document.querySelector('h2').style.display='flex';
    }

    async function callback(token) {
      try {
        const response = await fetch('/captcha', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json;charset=utf-8'
          },
          body: JSON.stringify({ token })
        });

        const result = await response.json();

        if (result.ok) {
          window.location.reload();
        } else {
          handleError();
        }
      } catch {
        handleError();
      }
    }
  </script>
</html>
