(function($){
    'use strict';

    var minigolfCustom = {

        init: function() {
            this.toggleForm();
            this.videoPopup();
        },

        toggleForm: function() {
            $("#formButton").on("click", function(){
                $("#form1").toggle();
            });
        },

        videoPopup: function() {

            const playBtn = document.getElementById("video-pop");
            const popup = document.getElementById("popup");
            const closeBtn = document.getElementById("closePopup");
            const iframe = document.getElementById("videoIframe");

            if(playBtn && popup && closeBtn && iframe){

                playBtn.addEventListener("click", function(e){
                    e.preventDefault();
                    popup.classList.add("show");
                    iframe.src = iframe.dataset.src;
                });

                const minigolfClosePopup = function(){
                    popup.classList.remove("show");
                    iframe.src = "";
                };

                closeBtn.addEventListener("click", minigolfClosePopup);

                popup.addEventListener("click", function(e){
                    if(e.target === popup) minigolfClosePopup();
                });

                document.addEventListener("keydown", function(e){
                    if(e.key === "Escape") minigolfClosePopup();
                });
            }
        }
    };

    $(document).ready(function(){
        minigolfCustom.init();
    });

})(jQuery);