(()=>{"use strict";function e(e){"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{e.readyInit()},{once:!0}):e.readyInit()}const t=function(t){const n=[];class o extends HTMLElement{connectedCallback(){e(this)}readyInit(){if(this.blockId&&!n[this.blockId]){var e;const t=this.querySelector("template")?.content;if(!t)return;n[this.blockId]={postId:null!==(e=this.postId)&&void 0!==e&&e,template:t,content:void 0,element:this}}}get postId(){return this.getAttribute("post-id")}get blockId(){return this.getAttribute("block-id")}}return window.customElements.define("pwp-block-pwd",o),t.ready=function(){!async function(){const{callApi:e}=PersonalizeWP.utils;Object.keys(n).forEach(t=>{if(!n[t])return;const{postId:o,template:c,content:i,element:a}=n[t];a.append(i||c.cloneNode(!0));const d=a.querySelector("form");d&&d.addEventListener("submit",async c=>{c.preventDefault();const i=a.querySelector("input[type='password']"),d=a.querySelector("[role='alert']");i.setAttribute("aria-invalid",!1),d.hidden=!0;const s=!!o,l=s?"v1":"v2",r={block_id:t,location:location.pathname,password:i.value};s&&(r.post_id=o);const u=await e(`${l}/blocks-pwd`,r);u&&u.success&&u.data?(function(e,t){const{nodeScriptReplace:n}=PersonalizeWP.utils,o=e.parentNode;let c=document.createElement("div");c.innerHTML=t,c=n(c),e.replaceWith(...c.childNodes);const i=new CustomEvent("PWP:parsePlaceholder",{bubbles:!0,cancelable:!0,detail:{container:o}});o.dispatchEvent(i),document.dispatchEvent(new CustomEvent("DOMContentLoaded"));const a=new CustomEvent("PWP:parsedPlaceholders",{bubbles:!0,cancelable:!0});document.dispatchEvent(a)}(a,u.data),n[t]={...n[t],content:u.data}):u&&u.data?(i.setAttribute("aria-invalid",!0),d.hidden=!1):(a.remove(),n[t]=void 0)})})}()},t.readyInit=function(){window.PersonalizeWP&&PersonalizeWP.module("pwd-blocks",this)},t}({});e(t)})();