<?php
/**
 * Template Name: Resource Item
 */

    get_header();

    if (have_posts()):
        while (have_posts()):
            the_post();
?>
<div class="content">
    <?= the_content(); ?>

    <script>
      document.addEventListener("DOMContentLoaded", (event) => {
        const btn = document.querySelector("#submit");
        btn.addEventListener("click", ( event ) => {
          btn.classList.add("btn-loading");
        },false);

        document.addEventListener( 'wpcf7invalid', ( event ) => {
          btn.classList.remove("btn-loading");
        },false);
        
        document.addEventListener( 'wpcf7mailfailed', ( event ) => {
          btn.classList.remove("btn-loading");
        },false);

        document.addEventListener( 'wpcf7mailsent', ( event ) => {
          if (typeof pdfUrl === "undefined") {
            console.warn("please add pdfUrl");
            return;
          }
          btn.classList.remove("btn-loading");
          window.open(pdfUrl, "_blank");
        }, false );
      });
    </script>
</div>

<?php
        endwhile;
    endif;

    get_footer();
