!function(){"use strict";const e=window.puffergoComments;if(!e)return;const t=e.i18n||{};function o(e){return t[e]||e}function n(e){const t=("; "+document.cookie).split("; "+e+"=");return 2===t.length?t.pop().split(";").shift():""}function r(e){if(!e)return;e.classList.remove("error");const t=e.parentNode.querySelector(".field-error-message");t&&t.remove()}function c(e,t){r(e),e.classList.add("error");const o=document.createElement("div");o.className="field-error-message",o.textContent=t,e.parentNode.appendChild(o)}function i(e,t){return!e||(e.value.trim()?(r(e),!0):(c(e,o(t)),!1))}function s(e){if(!e)return!0;const t=e.value.trim();return t?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)?(r(e),!0):(c(e,o("emailInvalid")),!1):(c(e,o("emailRequired")),!1)}function a(){document.querySelectorAll(".comment-message").forEach(function(e){e.remove()})}function m(e,t,o){a();const n=document.createElement("div");n.className="comment-message "+e,n.innerHTML='<span class="message-icon">'+({success:"✓",error:"✕",info:"ℹ"}[e]||"ℹ")+'</span><span class="message-text">'+t+"</span>";const r=document.querySelector(".blog-detail-page .comment-form-wrapper");r&&(r.insertBefore(n,r.firstChild),void 0===o&&(o=5e3),o>0&&setTimeout(function(){n.style.opacity="0",setTimeout(function(){n.remove()},300)},o))}function u(e,t){if(!e)return;const o=document.querySelector(".blog-detail-page .comment-list");if(!o)return;const n=document.createElement("div");n.innerHTML=e;const r=n.firstElementChild;if(r){if(t&&"0"!==t){const e=document.getElementById("comment-"+t);if(e){let t=e.querySelector(".children");t||(t=document.createElement("ol"),t.className="children",e.appendChild(t)),t.appendChild(r)}}else o.insertBefore(r,o.firstChild);var c;(c=r).classList.add("new-comment"),setTimeout(function(){c.classList.remove("new-comment")},3e3)}}async function l(t){t.preventDefault(),t.stopPropagation();const n=t.target,r=n.querySelector(".submit-button");if(!function(e){let t=!0;i(e.querySelector("#author"),"nameRequired")||(t=!1),s(e.querySelector("#email"))||(t=!1),i(e.querySelector("#comment"),"commentRequired")||(t=!1);const n=e.querySelector("#comment");return n&&n.value.trim().length<5&&(c(n,o("commentTooShort")),t=!1),t}(n))return;const l=new FormData(n);l.append("action",e.action),l.append("_wp_nonce",e.nonce),r.disabled=!0;const d=r.textContent;r.textContent=o("submitting"),r.classList.add("loading"),a();try{const t=await fetch(e.ajaxUrl,{method:"POST",body:l,credentials:"same-origin"}),r=await t.json();if(r.success){const t=n.querySelector("#author"),c=n.querySelector("#email");t&&c&&function(t,o){const n=new Date;n.setFullYear(n.getFullYear()+1);const r="; expires="+n.toUTCString()+"; path=/; SameSite=Lax";document.cookie="comment_author_"+e.cookieHash+"="+encodeURIComponent(t)+r,document.cookie="comment_author_email_"+e.cookieHash+"="+encodeURIComponent(o)+r}(t.value,c.value);m("success",r.data.is_moderated?o("commentAwaitingModeration"):o("commentSuccess"),0),n.reset(),u(r.data.comment_html,r.data.comment_parent),setTimeout(function(){const e=document.querySelector(".comment-message.success");e&&e.scrollIntoView({behavior:"smooth",block:"center"})},100)}else m("error",r.data||o("submitFailed"))}catch(e){console.error("Comment submit error:",e),m("error",o("networkError"))}finally{r.disabled=!1,r.textContent=d,r.classList.remove("loading")}}function d(){const t=document.querySelector(".blog-detail-page .comment-form");if(!t)return;t.setAttribute("action","javascript:void(0);"),function(t){const o=n("comment_author_"+e.cookieHash),r=n("comment_author_email_"+e.cookieHash),c=t.querySelector("#author"),i=t.querySelector("#email");o&&c&&!c.value&&(c.value=decodeURIComponent(o)),r&&i&&!i.value&&(i.value=decodeURIComponent(r))}(t),t.addEventListener("submit",l);const o=t.querySelector("#author"),r=t.querySelector("#email"),c=t.querySelector("#comment");o&&o.addEventListener("blur",function(){i(o,"nameRequired")}),r&&r.addEventListener("blur",function(){s(r)}),c&&c.addEventListener("blur",function(){i(c,"commentRequired")})}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",d):d()}();