websiteComponents.loader.define("website.components.form.visitor",[],(()=>(()=>{"use strict";var t={d:(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}function n(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=o(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==o(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function r(t,e,o){i(t,e),e.set(t,o)}function i(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}function s(t,e,o){return t.set(a(t,e),o),o}function l(t,e){return t.get(a(t,e))}function a(t,e,o){if("function"==typeof t?t===e:t.has(e))return arguments.length<3?e:o;throw new TypeError("Private element is not present on this object")}t.r(e),t.d(e,{Visitor:()=>y,default:()=>g});var c=new WeakMap,d=new WeakMap,h=new WeakMap,m=new WeakMap,u=new WeakSet;function p(){l(c,this)&&(s(h,this,(t=>{t.target===l(c,this)&&this.close()})),l(c,this).addEventListener("click",l(h,this)),s(m,this,(t=>{"Escape"===t.key&&l(d,this)&&this.close()})),document.addEventListener("keydown",l(m,this)))}function b(){var t;l(c,this)&&l(h,this)&&l(c,this).removeEventListener("click",l(h,this)),l(m,this)&&document.removeEventListener("keydown",l(m,this));const e=null===(t=l(c,this))||void 0===t?void 0:t.parentElement;e&&e.parentNode&&e.parentNode.removeChild(e),s(c,this,null),s(h,this,null),s(m,this,null),s(d,this,!1),document.body.style.overflow=""}const f=new class{constructor(){var t;i(this,t=u),t.add(this),r(this,c,null),r(this,d,!1),r(this,h,null),r(this,m,null)}open(t){const{wrapper:e,overlay:o}=((t,e)=>{const{wrapper:o,overlay:n}=(()=>{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}})(),r=(()=>{const t=document.createElement("div");return t.className="lightbox-inner",t})(),i=(()=>{const t=document.createElement("div");return t.className="lightbox-background",t})(),s=(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),l=(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&&e.length&&o.classList.add(...t.contentClasses),t.contentDataAttributes&&Object.entries(t.contentDataAttributes).forEach((t=>{let[e,n]=t;o.setAttribute(`data-${e}`,n)})),o})(t);return l.appendChild(s),l.appendChild(t.content),r.appendChild(l),n.appendChild(i),n.appendChild(r),{wrapper:o,overlay:n}})(t,(()=>this.close()));s(c,this,o),document.body.appendChild(e),a(u,this,p).call(this),l(c,this).style.display="flex",s(d,this,!0),document.body.style.overflow="hidden"}close(){a(u,this,b).call(this)}isLightboxOpen(){return l(d,this)}};class y{constructor(t){n(this,"localizedStrings",{}),n(this,"localizedFieldFormats",{}),n(this,"previewSubmissionState",!1),n(this,"useLightbox",!1),this.root=t;const e=this.root.querySelector("script.sqs-form-block-localized-strings");null!=e&&e.textContent&&(this.localizedStrings=JSON.parse(e.textContent));const o=this.getFormContextFromMarkup(),r=this.getDesignFieldsFromMarkup();this.formContext={...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 n=document.createElement("div");return n.className="form-inner-wrapper",e.appendChild(n),{wrapper:t,inner:n}}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"],n={},r=this.root.closest("[data-section-theme]"),i=(null==r?void 0:r.getAttribute("data-section-theme"))||"";i&&(o.push(i),n["section-theme"]=i),f.open({content:t,contentClasses:o,contentDataAttributes:n}),this.renderReactForm(!0,e)}))}updateFormContext(t){this.formContext=t}setPreviewSubmissionState(t){this.previewSubmissionState=t}async renderReactForm(){let t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];const e=(arguments.length>1?arguments[1]:void 0)||this.root.querySelector(".form-wrapper");if(!e)throw new Error("Form wrapper element not found");if(!this.formContext)throw new Error("Form context not initialized");const o=this.generateReactProps();window.Squarespace.renderReactFormForWebsiteComponent(o,e,t)}generateReactProps(){var t;if(!this.formContext)throw new Error("Form context not initialized");return{...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||!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{return{formSubmissionHTML:o,...JSON.parse(t.textContent)}}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||!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}`)}}}const g=t=>new y(t);return e})()));