websiteComponents.loader.define("website.components.form.visitor",[],(()=>(()=>{"use strict";var t={91692:function(t,e,o){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.Visitor=void 0;const n=r(o(4492));class s{constructor(t){this.root=t,this.localizedStrings={},this.localizedFieldFormats={},this.previewSubmissionState=!1,this.useLightbox=!1;const e=this.root.querySelector("script.sqs-form-block-localized-strings");(null==e?void 0:e.textContent)&&(this.localizedStrings=JSON.parse(e.textContent));const o=this.getFormContextFromMarkup(),r=this.getDesignFieldsFromMarkup();this.formContext=Object.assign(Object.assign({},o),r),o.formFieldFormats&&(this.localizedFieldFormats=o.formFieldFormats),this.useLightbox=!!this.root.querySelector(".lightbox-handle"),this.useLightbox?this.setupLightboxHandler():this.renderReactForm(!0)}createLightboxContent(){const t=document.createElement("div");t.className="sqs-block-form sqs-block-form-lightbox sqs-background-enabled";const e=document.createElement("div");if(e.className="form-wrapper sqs-site-style-form",t.appendChild(e),!this.formContext)throw new Error("Form context not initialized");const o=document.createElement("div");o.innerHTML=this.formContext.formName||"",o.classList.add("form-title"),e.appendChild(o);const r=document.createElement("div");return r.className="form-inner-wrapper",e.appendChild(r),{wrapper:t,inner:r}}setupLightboxHandler(){const t=this.root.querySelector(".lightbox-handle");if(!t)throw new Error("Lightbox handle element not found");t.addEventListener("click",(()=>{const{wrapper:t,inner:e}=this.createLightboxContent(),o=["lightbox-form-content-background"],r={},s=this.root.closest("[data-section-theme]"),i=(null==s?void 0:s.getAttribute("data-section-theme"))||"";i&&(o.push(i),r["section-theme"]=i),n.default.open({content:t,contentClasses:o,contentDataAttributes:r}),this.renderReactForm(!0,e)}))}updateFormContext(t){this.formContext=t}setPreviewSubmissionState(t){this.previewSubmissionState=t}async renderReactForm(t=!0,e){const o=e||this.root.querySelector(".form-wrapper");if(!o)throw new Error("Form wrapper element not found");if(!this.formContext)throw new Error("Form context not initialized");const r=this.generateReactProps();window.Squarespace.renderReactFormForWebsiteComponent(r,o,t)}generateReactProps(){var t;if(!this.formContext)throw new Error("Form context not initialized");return Object.assign(Object.assign({},this.formContext),{lightboxHandleText:this.formContext.lightboxHandleText||(null===(t=this.localizedStrings)||void 0===t?void 0:t.lightbox.openForm),previewSubmissionState:this.previewSubmissionState,formFieldFormats:this.localizedFieldFormats,localizedStrings:this.localizedStrings})}getFormContextFromMarkup(){const t=this.root.querySelector("script.sqs-form-block-context");if(!(null==t?void 0:t.textContent))throw new Error("Form context script not found or empty");const e=this.root.querySelector(".sqs-form-block-submission-html"),o=(null==e?void 0:e.getAttribute("data-submission-html"))||void 0;try{const e=JSON.parse(t.textContent);return Object.assign({formSubmissionHTML:o},e)}catch(t){throw new Error(`Error parsing the JSON form context: ${t}`)}}getDesignFieldsFromMarkup(){const t=this.root.querySelector("script.sqs-form-block-design-fields");if(!(null==t?void 0:t.textContent))throw new Error("Design fields script not found or empty");try{return JSON.parse(t.textContent)}catch(t){throw new Error(`Error parsing design fields: ${t}`)}}}e.Visitor=s,e.default=t=>new s(t)},4492:function(t,e){var o,r,n,s,i,a,l,c=this&&this.__classPrivateFieldGet||function(t,e,o,r){if("a"===o&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===o?r:"a"===o?r.call(t):r?r.value:e.get(t)},d=this&&this.__classPrivateFieldSet||function(t,e,o,r,n){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?n.call(t,o):n?n.value=o:e.set(t,o),o};Object.defineProperty(e,"__esModule",{value:!0}),e.Lightbox=void 0;class h{constructor(){o.add(this),r.set(this,null),n.set(this,!1),s.set(this,null),i.set(this,null)}open(t){const{wrapper:e,overlay:s}=((t,e)=>{const{wrapper:o,overlay:r}=(()=>{const t=document.createElement("div");t.className="sqs-modal-lightbox";const e=document.createElement("div");return e.className="sqs-modal-lightbox-content",e.style.cssText="\n display: flex;\n align-items: center;\n justify-content: center;\n ",t.appendChild(e),{wrapper:t,overlay:e}})(),n=(()=>{const t=document.createElement("div");return t.className="lightbox-inner",t})(),s=(()=>{const t=document.createElement("div");return t.className="lightbox-background",t})(),i=(t=>{const e=document.createElement("div");return e.setAttribute("role","button"),e.setAttribute("tabindex","0"),e.setAttribute("aria-label","Close"),e.className="lightbox-close",e.innerHTML="×",e.addEventListener("click",t),e.addEventListener("keydown",(e=>{"Enter"!==e.key&&" "!==e.key||t()})),e})(e),a=(t=>{var e;const o=document.createElement("div");return o.className="lightbox-content",o.style.cssText="\n margin: 50px auto;\n ",(null===(e=t.contentClasses)||void 0===e?void 0:e.length)&&o.classList.add(...t.contentClasses),t.contentDataAttributes&&Object.entries(t.contentDataAttributes).forEach((([t,e])=>{o.setAttribute(`data-${t}`,e)})),o})(t);return a.appendChild(i),a.appendChild(t.content),n.appendChild(a),r.appendChild(s),r.appendChild(n),{wrapper:o,overlay:r}})(t,(()=>this.close()));d(this,r,s,"f"),document.body.appendChild(e),c(this,o,"m",a).call(this),c(this,r,"f").style.display="flex",d(this,n,!0,"f"),document.body.style.overflow="hidden"}close(){c(this,o,"m",l).call(this)}isLightboxOpen(){return c(this,n,"f")}}e.Lightbox=h,r=new WeakMap,n=new WeakMap,s=new WeakMap,i=new WeakMap,o=new WeakSet,a=function(){c(this,r,"f")&&(d(this,s,(t=>{t.target===c(this,r,"f")&&this.close()}),"f"),c(this,r,"f").addEventListener("click",c(this,s,"f")),d(this,i,(t=>{"Escape"===t.key&&c(this,n,"f")&&this.close()}),"f"),document.addEventListener("keydown",c(this,i,"f")))},l=function(){var t;c(this,r,"f")&&c(this,s,"f")&&c(this,r,"f").removeEventListener("click",c(this,s,"f")),c(this,i,"f")&&document.removeEventListener("keydown",c(this,i,"f"));const e=null===(t=c(this,r,"f"))||void 0===t?void 0:t.parentElement;e&&e.parentNode&&e.parentNode.removeChild(e),d(this,r,null,"f"),d(this,s,null,"f"),d(this,i,null,"f"),d(this,n,!1,"f"),document.body.style.overflow=""};const m=new h;e.default=m}},e={};return function o(r){var n=e[r];if(void 0!==n)return n.exports;var s=e[r]={exports:{}};return t[r].call(s.exports,s,s.exports,o),s.exports}(91692)})()));