window.addEventListener("DOMContentLoaded",(function(){function e(e,t){e.classList.contains(t)?e.classList.remove(t):e.classList.add(t)}var t=document.querySelector('input[name="_token"]').value;function n(n){var o=n.querySelector(".submitComment");o.setAttribute("disabled","disabled"),o.value="Sending...";var l=n.querySelector(".comment-message");n.querySelectorAll(".error-message").forEach((function(e){e.classList.add("hidden")})),fetch("/comment/",{headers:{"Content-Type":"application/json",Accept:"application/json, text-plain, */*","X-Requested-With":"XMLHttpRequest","X-CSRF-TOKEN":t},method:"post",credentials:"same-origin",body:JSON.stringify({commentable_id:document.getElementById("commentable_id").value,commentable_type:document.getElementById("commentable_type").value,parent_id:n.querySelectorAll(".parent_id")[0].value,name:n.querySelectorAll(".comment_name")[0].value,email:n.querySelectorAll(".comment_email")[0].value,body:n.querySelectorAll(".comment_body")[0].value})}).then((function(e){return e.json()})).then((function(t){if("success"==t.type)l.innerHTML=t.message,function(t,n,o){e(t,n),e(t,o)}(l,"hidden","inline-block"),n.reset();else if(void 0!==t.errors)for(var r in t.errors){var i=n.querySelectorAll("[name='"+r+"']")[0].nextElementSibling;i.innerHTML=t.errors[r],i.classList.remove("hidden")}o.removeAttribute("disabled"),o.value="Submit Comment"})).catch((function(e){console.log(e),o.removeAttribute("disabled"),o.value="Submit Comment"}))}document.querySelectorAll(".submitComment").forEach((function(e){e.addEventListener("click",(function(t){t.preventDefault(),n(e.closest("form"))}))})),document.querySelectorAll(".reply-toggle").forEach((function(t){t.addEventListener("click",(function(n){e(t.closest(".single-comment-wrap").querySelectorAll(".reply-form")[0],"hidden")}))}))}));