<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0;">
    <title>View notification</title>
    <style>
        form {
            margin: 0 auto;
            width: 300px;
            padding: 1em;
            border: 1px solid #CCC;
            border-radius: 1em;
        }

        ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        form li + li {
            margin-top: 1em;
        }

        input {
            font: 1em sans-serif;
            width: 250px;
            box-sizing: border-box;
            border: 1px solid #999;
        }

        textarea {
            vertical-align: top;
            height: 5em;
        }

        button {
            margin-left: .5em;
        }

        li {
            text-align: center;
        }

    </style>
</head>
<script>
  function onLoad() {
    document.getElementById("notification-form").addEventListener("submit", function (e) {
      e.preventDefault();
      var http = new XMLHttpRequest();
      var url = '{{ url }}';
      http.open('POST', url, true);
      http.setRequestHeader('Content-type', 'application/json');
      http.setRequestHeader('x-csrf-token', '{{ csrf_token }}');
      http.onreadystatechange = function () {
        if (http.readyState === 4 && http.status === 200) {
          document.getElementById('validation-msg').textContent = '';
          document.body.innerHTML = http.responseText;
        } else if (http.status === 404 || http.status === 400) {
          document.getElementById('validation-msg').textContent = 'Data entered not valid';
        } else if (http.status === 403) {
          document.getElementById('validation-msg').textContent = 'Reached max. retries. Wait one minute and try again.';
        }
      }
      http.send(JSON.stringify({
        number: document.getElementById('number').value,
        identifier: '{{ identifier }}',
      }));
    });
  }
</script>
<body onload="onLoad()">
<form id="notification-form" style="margin-top: 1em;">
    <ul>
        <li><strong>{{ title }} Notification</strong></li>
    </ul>
    <br/>
    <ul>
        <li>
            Last 4 digits of your phone number:
            <input type="text" id="number" name="number">
        </li>
        <li>
            <p id="validation-msg"></p>
        </li>
        <li class="button">
            <button type="submit">View notification</button>
        </li>
    </ul>
</form>
</body>
</html>
