1"use strict";(self.webpackChunkcrownpeak_opus2=self.webpackChunkcrownpeak_opus2||[]).push([["whitepaper-form-loader"],{"./src/js/opus2/white-paper/form-white.ts"(e,t,n){n.d(t,{FormHandlerAskQuestionWhitePaper:()=>f});var i=n(/*! tslib */"./node_modules/tslib/tslib.es6.mjs"),o=n(/*! ../config/apiConfig */"./src/js/opus2/config/apiConfig.ts"),s=n(/*! ../constants/regex */"./src/js/opus2/constants/regex.ts"),a=n(/*! ../util/loader */"./src/js/opus2/util/loader.ts"),d=n(/*! ../util/locationBasedBrandJson */"./src/js/opus2/util/locationBasedBrandJson.ts"),r=n(/*! ../util/share */"./src/js/opus2/util/share.ts"),l=n(/*! ../util/discovery */"./src/js/opus2/util/discovery.ts"),c=n(/*! ../apiCaching/POST-Requests/apibookingCallWrapper */"./src/js/opus2/apiCaching/POST-Requests/apibookingCallWrapper.ts"),m=n(/*! ../util/domainService */"./src/js/opus2/util/domainService.ts"),u=n(/*! ../location-search-map/getCountryCode */"./src/js/opus2/location-search-map/getCountryCode.ts"),h=n(/*! ../util/hideTermsPolicy */"./src/js/opus2/util/hideTermsPolicy.ts"),p=n(/*! ../util/disclaimerService */"./src/js/opus2/util/disclaimerService.ts"),v=n(/*! ../apiCaching/POST-Requests/apiContactCallWrapper */"./src/js/opus2/apiCaching/POST-Requests/apiContactCallWrapper.ts"),y=n(/*! ../config/cachingConfig */"./src/js/opus2/config/cachingConfig.ts"),g=n(/*! ../apiCaching/apiWrapper */"./src/js/opus2/apiCaching/apiWrapper.ts"),I=n(/*! ../apiCaching/POST-Requests/helperModules/handleBookingSubmit */"./src/js/opus2/apiCaching/POST-Requests/helperModules/handleBookingSubmit.ts");class f{static getInstance(){return f.instance||(f.instance=new f),f.instance}showFieldError(e,t){const n=`${e.id}-error-msg`;let i=document.getElementById(n);if(i)i.classList.remove("hidden"),i.innerHTML=t;else if(null==e?void 0:e.parentNode){const i=document.createElement("span");i.className="error-msg",i.id=n,i.textContent=t,e.classList.add("invalid-field"),e.parentNode.appendChild(i)}}constructor(){var e,t,n,i,o,s;this.form=null,this.mobileNumberInput=null,this.privateSuggestedArray=[],this.clearFields=()=>{(0,I.attachClearFieldListeners)(["send-state"])},this.downloadFormService=document.querySelectorAll('[id*="papers-download-service-reminder"]'),this.init(),this.clearFields(),this.nameInput2=document.getElementById("lname"),this.nameInput=document.getElementById("fname"),this.phoneNumberInput=document.getElementById("phone-number"),this.emailInput=document.getElementById("email"),this.zipCodeInput=document.getElementById("zipcode"),null===(e=this.nameInput)||void 0===e||e.addEventListener("input",this.errorOnName.bind(this)),null===(t=this.nameInput2)||void 0===t||t.addEventListener("input",this.errorOnName2.bind(this)),null===(n=this.emailInput)||void 0===n||n.addEventListener("input",this.emailError.bind(this)),null===(i=this.zipCodeInput)||void 0===i||i.addEventListener("input",this.zipCodeError.bind(this)),null===(o=this.zipCodeInput)||void 0===o||o.addEventListener("focusout",this.handleFocusOut.bind(this));const a=document.querySelector(".thank-you-download .cta-wrapper button");a&&a.addEventListener("click",this.handleBackToFormClick),null===(s=this.downloadFormService)||void 0===s||s.forEach(e=>{e.addEventListener("change",this.handleCheckboxChange.bind(this))})}handleBackToFormClick(){const e=document.getElementById("papers-download-form"),t=document.getElementById("confirmation");e&&(e.style.display="block",t&&(t.style.display="none"),document.querySelector(".thank-you-body").classList.remove("hidden"),document.querySelector(".error-msg-body").classList.remove("hidden"))}validateNameField(e,t){""===e.value||s.REGEX.sendName.test(e.value)?this.hideError(t):this.showFieldError(e,"Invalid name format.")}errorOnName2(){this.validateNameField(this.nameInput2,"lname")}errorOnName(){this.validateNameField(this.nameInput,"fname")}
1emailError(){""==this.emailInput.value||s.REGEX.sendEmail.test(this.emailInput.value)?this.hideError("email"):this.showFieldError(this.emailInput,"Invalid email address, please try again.")}handleMobileInput(e){var t,n;e.preventDefault();const i=s.REGEX.mobileNumberRegex,o=null===(t=this.phoneNumberInput)||void 0===t?void 0:t.value,a=null==o?void 0:o.replace(/\D/g,"").match(i);let d="";if(a){d=`(${a[1]}) ${a[2]}${a[3]?"-"+a[3]:""}`}if(""!=this.phoneNumberInput.value&&(null===(n=this.phoneNumberInput)||void 0===n?void 0:n.value.length)<14&&d.length<14?this.showFieldError(this.phoneNumberInput,"Invalid phone format."):this.hideError.call(this,"phone-number"),a){let e;e=a[2]?`(${a[1]}) ${a[2]}${a[3]?"-"+a[3]:""}`:a[1],this.phoneNumberInput.value=e}}zipCodeError(){this.zipCodeInput&&(""==this.zipCodeInput.value||s.REGEX.sendZip.test(this.zipCodeInput.value.trim())?this.hideError("zipcode"):this.showFieldError(this.zipCodeInput,"Invalid zip code format."))}hideError(e){(0,I.handleHideError)(e)}init(){this.form=document.querySelector("#papers-download-form button"),this.mobileNumberInput=document.getElementById("phone-number");const e=document.getElementById("inline-radio-6"),t=(0,m.DomainIdentifier)(),n=(0,u.getCountryCode)(),i=sessionStorage.getItem("countryCode");"ca"!==t&&"ca"!==n&&"ca"!==i||(0,h.hideTermsPolicy)("#papers-download-form","terms-policy-text"),this.mobileNumberInput&&this.mobileNumberInput.addEventListener("input",this.handleMobileInput.bind(this)),this.form&&(this.form.addEventListener("click",this.handleZipcodeData.bind(this)),e&&(e.checked=!0))}handleZipcodeData(e){const t=document.getElementById("zipcode"),n=null==t?void 0:t.value.trim();this.getFranchiseWebLocationId(e,n)}handleFocusOut(){const e=document.getElementById("zipcode"),t=null==e?void 0:e.value.trim();(0,p.DisclaimerServiceIdentifier)(t),(0,h.toggleTermsPolicyBasedOnCountry)("#papers-download-form",t)}handleCheckboxChange(){if(document.querySelector("#papers-download-form"))return(0,I.handleCheckboxChangeUtility)("#papers-download-form");console.log("Form doesnt exist.")}getFranchiseWebLocationId(e,t){e.preventDefault();const n=t;this.validateForm()&&((0,a.startLoader)(),(0,r.getFranchiseDetails)(n,!1).then(n=>{const i=n;if(i.length>0){const n={franchiseId:i[0].franchiseId,franchiseWebLocationId:i[0].franchiseWebLocationId};this.handleSubmit(e,n,t)}else this.contactUsApiCall(t)}).catch(e=>{this.contactUsApiCall(t)}))}fetchBrandDetails(e){return(0,i.__awaiter)(this,void 0,void 0,function*(){try{const t=window.location.origin,n=`${t}/${(0,d.getBrandJSON)()}`;return(yield(0,g.getCachedAPIResponse)(n,y.apiCaching.BrandJsonConfig,!1)).find(t=>t.id===e)||null}catch(e){throw console.error("Error fetching brand details:",e),e}})}handleFormSuccess(){var e;(0,a.stopLoader)();const t=document.getElementById("papers-download-form"),n=document.getElementById("confirmation");t&&(t.style.display="none",null===(e=document.querySelector(".error-msg-body"))||void 0===e||e.classList.add("hidden"),n&&(n.style.display="block")),this.downloadWhitepaper()}handleFormError(){var e,t;(0,a.stopLoader)();const n=document.getElementById("papers-download-form");n&&(n.style.display="none",null===(e=document.querySelector(".thank-you-body"))||void 0===e||e.classList.add("hidden"),null===(t=document.querySelector(".error-msg-body"))||void 0===t||t.classList.remove("hidden"));const i=document.getElementById("failure");i&&i.classList.remove("hidden");const o=document.getElementById("confirmation");o&&(o.style.display="block")}downloadWhitepaper(){const e=document.getElementById("whitepaperdoc");if(!(null==e?void 0:e.value))return;const t=document.createElement("a");t.style.display="none",t.href=e.value,t.download="downloaded.pdf",t.target="_blank",document.body.appendChild(t),t.click(),document.body.removeChild(t)}createBaseContactPayload(e,t){return{firstName:e.firstName.split(" ")[0],lastName:e.lastName.split(" ")[0],zipCode:e.zipCode.trim(),email:e.email,state:"",city:"",phone:e.phoneNumber,address:"No address collected",address2:"",comments:"",conceptId:Number(t.id),conceptCode:t.code,vendorId:Number(t.vendorId),emailOptOut:!1,signUpForUpdates:!1,formType:this.getFormType()}}contactUsApiCall(e){return(0,i.__awaiter)(this,void 0,void 0,function*(){var e;const t=this.getFormFields(),n=(null===(e=document.getElementById("conceptId"))||void 0===e?void 0:e.value)||"11";try{const e=yield this.fetchBrandDetails(n);if(!e)throw new Error("Brand details not found");const i=document.getElementById("weblocationId")||document.getElementById("local_weblocationId"),s=!!(null==i?void 0:i.value);let a=Object.assign(Object.assign({},this.createBaseContactPayload(t,e)),{isLocalized:s});a=this.optinEmailCheck(a);const d=yield(0,v.contactUsPostCallWrapper)(o.apiConfig.CONTACT_US_SEND,a);(0,r.storeBookingApiPayload)(a,d),this.handleFormSuccess()}catch(e){this.handleFormError()}})}handleSubmit(e,t,n){return(0,i.__awaiter)(this,void 0,void 0,function*(){var n;e.preventDefault();const i=this.getFormFields(),s=(null===(n=document.getElementById("conceptId"))||void 0===n?void 0:n.value)||"11";try{const e=yield this.fetchBrandDetails(s);if(!e)throw new Error("Brand details not found");let n=Object.assign(Object.assign({},this.createBaseContactPayload(i,e)),{isLocalized:!0,postalCode:i.zipCode.trim(),note:"",leadSource:"WEB",leadOrigin:"WEB",phoneType:"true",isLeadOnly:!0,scheduleID:"",campaignName:"N/A",callType:"WEB",conceptCalledId:Number(e.id),isEstimate:!1,fileUrls:[{}],webLocationId:0});t.franchiseWebLocationId&&(n.webLocationId=t.franchiseWebLocationId,n.franchiseId=t.franchiseId);const a=yield(0,l.handleMissingData)(n.city,n.state,n.zipCode);n.city=(null==a?void 0:a.city)||n.city,n.state=(null==a?void 0:a.state)||n.state,n=this.optinEmailCheck(n);const d=yield(0,c.bookingUsPostCallWrapper)(o.apiConfig.BOOKING_API_URL,n);(0,r.storeBookingApiPayload)(n,d),this.handleFormSuccess()}catch(e){this.handleFormError()}})}optinEmailCheck(e){return(0,I.handleOptinEmailCheck)(e,"#papers-download-form","papers-download-service-reminder-us","papers-download-service-reminder-ca","download form")}getFormFields(){return{firstName:document.getElementById("fname").value,lastName:document.getElementById("lname").value,zipCode:document.getElementById("zipcode").value,phoneNumber:document.getElementById("phone-number").value,email:document.getElementById("email").value}}getSelectedRatio(e){const t=e;for(const e of t)if(e.checked){return document.querySelector(`[for="${e.id}"]`).innerText}return null}getFormType(){const e=document.getElementById("case-study");return e&&e.value?"case study"===e.value.toLowerCase()?"Case Study":e.value:""}
1validateField(e,t,n,i,o=!0,s){return e.trim()?!n.test(e)||s&&!s(e)?i:null:o?"":null}validateForm(){const e=this.getFormFields();document.querySelectorAll(".invalid-field").forEach(e=>e.classList.remove("invalid-field"));const t={},n=this.validateField(e.firstName,"fname",s.REGEX.sendName,"Invalid name format.");null!==n&&(t.fname=n);const i=this.validateField(e.lastName,"lname",s.REGEX.sendName,"Invalid name format.");null!==i&&(t.lname=i);const o=this.validateField(e.zipCode,"zipcode",s.REGEX.sendZip,"Invalid zip code format.",!0,e=>"00000"!==e);null!==o&&(t.zipcode=o),""===e.phoneNumber?t["phone-number"]="":e.phoneNumber.length<14&&(t["phone-number"]="Invalid phone format.");const a=this.validateField(e.email,"email",s.REGEX.sendEmail,"Invalid email format.");null!==a&&(t.email=a),""===e.note&&(t["send-note"]=""),e.city&&!s.REGEX.sendCity.test(e.city)&&(t["send-city"]="Invalid city format.");const d=this.handleCheckboxChange();return d&&(t[d]=""),Object.keys(t).forEach((e,n)=>{const i=document.getElementById(e),o=document.getElementById(`${e}-error-msg`);if(i&&i.parentNode){const n=t[e],s=document.createElement("span");s.className="error-msg",s.id=`${e}-error-msg`,s.textContent=n,i.classList.add("invalid-field"),o&&o.classList.contains("hidden")&&o.classList.remove("hidden")}0===n&&i&&i.focus()}),0===Object.keys(t).length}}globalThis.__WhitePaperFormListenerAdded||(globalThis.__WhitePaperFormListenerAdded=!0,document.addEventListener("DOMContentLoaded",()=>{if(globalThis.__WhitePaperFormInitialized)return;document.querySelector("#papers-download-form")&&(globalThis.__WhitePaperFormInitialized=!0,f.getInstance())}))},"./src/js/opus2/white-paper/index.ts"(e,t,n){n.r(t),n.d(t,{FormHandlerAskQuestionWhitePaper:()=>i.FormHandlerAskQuestionWhitePaper});var i=n(/*! ./form-white */"./src/js/opus2/white-paper/form-white.ts")}}]); 2//# sourceMappingURL=opus2.whitepaper-form-loader.0f5e0172c6e7b30f61b9.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.