<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Profile Report is being built</title>
    <style>
      body {
        display: grid;
        place-content: center;
        margin: 0;
        min-height: 100vh;
        background: #fff;
      }
      .header {
        grid-column: 1;
        grid-row: 1;
        margin-bottom: 20px;
        margin-left: auto;
        margin-right: auto;
        display: flex;
        flex-direction: column;
        text-align: center;
      }
      .header > .title {
        color: #000;
        font: 200 1.5em/ 1.25 sans-serif;
        margin-bottom: 10px;
      }
      .header > .description {
        font: 200 1em/ 1.25 sans-serif;
        font-style: italic;
      }
      .loader {
        grid-column: 1;
        grid-row: 2;
        display: flex;
        align-items: center;
        padding: 6em;
        background: inherit;
        filter: blur(8px) contrast(20);
        mix-blend-mode: multiply;
        animation: colorcycle 5s linear infinite alternate-reverse;
      }
      @keyframes colorcycle {
        from {
          --particle-color: rgb(0, 60, 0);
        }
        33% {
          --particle-color: rgb(0, 40, 20);
        }
        66% {
          --particle-color: rgb(0, 20, 40);
        }
        to {
          --particle-color: rgb(0, 0, 60);
        }
      }
      .particle {
        width: 0;
        padding: 1.5em;
        border-radius: 50%;
        background: var(--particle-color);
      }
      .particle:first-child,
      .particle:last-child {
        padding: 0.75em;
      }
      .particle:nth-child(odd) {
        animation: pulse var(--t) ease-in-out var(--dt) infinite;
      }
      .particle:nth-child(2n) {
        transform: rotate(0deg) translate(3em);
        animation: spin var(--t) linear infinite;
      }
      .particle:nth-child(4n) {
        animation-direction: reverse;
        animation-duration: calc(1.2 * var(--t));
      }
      @keyframes pulse {
        50% {
          transform: scale(1.8);
        }
        70% {
          transform: scale(0.6);
        }
      }
      @keyframes spin {
        to {
          transform: rotate(1turn) translate(3em);
        }
      }
    </style>
  </head>
  <body>
    <div class="header">
      <div class="title">Building profile report</div>
      <div class="description">This may take as long as a few minutes</div>
    </div>
    <div class="loader" style="--t: 2s">
      <div class="particle" style="--dt: -1.44s"></div>
      <div class="particle"></div>
      <div class="particle" style="--dt: -1.11s"></div>
      <div class="particle"></div>
      <div class="particle" style="--dt: -1.41s"></div>
      <div class="particle"></div>
      <div class="particle" style="--dt: -1.46s"></div>
      <div class="particle"></div>
      <div class="particle" style="--dt: -1.44s"></div>
    </div>
    <script type="text/javascript">
      const dataId = window.location.pathname.split("/")[3];
      window.onload = () => {
        fetch(`/node/build-profile-report/${dataId}/`, {
          method: "GET",
          redirect: "follow",
        })
          .then((response) => {
            if (response.redirected) {
              window.location.href = response.url;
            } else {
              throw new Error("Something went wrong");
            }
          })
          .catch((error) => {
            const body = document.querySelector("body");
            body.style.color = "#8B0000";
            body.innerHTML = error.message;
          });
      };
    </script>
  </body>
</html>
