1import{showGlobalMessage as a}from"./chunk-BB_ZJ9xr.js";import{a as l}from"./chunk-ChWm5g_s.js";import{a as h}from"./chunk-DDHtAA0h.js";import{g as m}from"./chunk-i30fFyTI.js";import"./chunk-DCddhnw_.js";import"./chunk-DJz7FJiK.js";const r=/.+/;class u{constructor(){this.$form=$(".j-contact-us-form"),this.$firstName=this.$form.find("#j-contact-us-first-name"),this.$lastName=this.$form.find("#j-contact-us-last-name"),this.$phone=this.$form.find("#j-contact-us-phone"),this.$email=this.$form.find("#j-contact-us-email"),this.$topicDropdown=this.$form.find(".j-dropdown-topic"),this.$subtopicDropdown=this.$form.find(".j-dropdown-subtopic"),this.$orderNumber=this.$form.find("#j-contact-us-order-number"),this.$message=this.$form.find("#j-contact-us-message"),this.$sendButton=this.$form.find(".j-contact-us-send"),this.$fileInputContainer=this.$form.find(".j-contact-us-file-upload"),this.files=[],this.topics=[],this.loadTopics(),this.bindTopicDropdownChange(),this.bindPhoneNumberInputChange(),this.bindFileInputEventListener(),this.bindFormSubmit(),this.showCaptcha()}loadTopics(){const t=`${ACC.config.contextPath}/contact-us/topics`;h(t,"GET",null,o=>{if(!o){this.onLoadTopicsError();return}this.onLoadTopicsSuccess(o)},()=>this.onLoadTopicsError())}onLoadTopicsError(){a("Failed to load topics","error")}onLoadTopicsSuccess(t){this.topics=t.dataObject||[],this.populateTopicsDropdown(this.topics)}populateTopicsDropdown(t){if(!t.length)return;const o=this.$topicDropdown.find(".j-dropdown-list");o.empty();const i=this.$topicDropdown.find(".j-dropdown-inner button");i.removeClass("populated"),i.find(".j-active-option").empty(),t.forEach(e=>{o.append(`<li class="dropdown__item j-dropdown-item"><a>${e.name}</a></li>`)})}bindTopicDropdownChange(){this.$topicDropdown.on("dropdown.change",()=>{const t=this.$topicDropdown.find(".j-active-option").val(),o=this.$subtopicDropdown.find(".j-dropdown-list"),i=this.topics.find(n=>n.name===t)?.subTopics;if(!i?.length)return;o.empty();const s=this.$subtopicDropdown.find(".j-dropdown-inner button");s.removeClass("populated"),s.find(".j-active-option").empty(),i.forEach(n=>{o.append(`<li class="dropdown__item j-dropdown-item" data-code="${n.routingCode}"><a>${n.name}</a></li>`)}),this.$subtopicDropdown.removeClass("hidden")})}bindPhoneNumberInputChange(){this.$phone.on("input",function(){this.value=m(this.value)})}bindFileInputEventListener(){this.$fileInputContainer.on("fileUpload.change",(t,o)=>{this.files=o?.files||[]})}bindFormSubmit(){this.$sendButton.on("click",()=>{this.validateForm()&&(this.$sendButton.addClass("loading"),this.submitForm())})}validateForm(){const t=this.$topicDropdown.find(".j-active-option"),o=this.$subtopicDropdown.find(".j-active-option"),i=this.isFieldValid(this.$firstName,ACC.config.nameRegex),s=this.isFieldValid(this.$lastName,ACC.config.nameRegex),e=this.isFieldValid(this.$email,ACC.config.emailRegex),n=this.isPhoneFieldValid(this.$phone,ACC.config.phoneRegex),c=this.isFieldValid(t,r),p=this.isFieldValid(o,r),d=this.isFieldValid(this.$message,r);return i&s&e&n&c&p&d}isFieldValid(t,o){const i=(t.val()??"").trim(),s=t.closest(".j-custom-input-group, .j-dropdown").find(".j-input-error");return i&&o.test(i)?(s.hide(),!0):(s.show(),!1)}isPhoneFieldValid(t,o){const i=(t.val()??"").trim(),s=i.replace(/[\s\-()]/g,""),e=t.closest(".j-custom-input-group").find(".j-input-error");return i&&o.test(s)?(e.hide(),!0):(e.show(),!1)}submitForm(){const t=new FormData,o=this.$topicDropdown.find(".j-active-option"),i=this.$subtopicDropdown.find(".j-active-option"),s=this.$subtopicDropdown.find(".j-dropdown-item.selected").data("c
1ode");t.append("firstName",this.$firstName.val().trim()),t.append("lastName",this.$lastName.val().trim()),t.append("phoneNumber",this.$phone.val().trim()),t.append("email",this.$email.val().trim()),t.append("topic",o.val()),t.append("subTopic",i.text()),t.append("routingCode",s),t.append("orderNumber",this.$orderNumber.val().trim()),t.append("message",this.$message.val().trim()),t.append("recaptchaToken",$(".j-contact-us-recaptcha-token").val());for(const e of this.files)t.append("files",e);$.ajax({url:"/contact-us",type:"POST",data:t,cache:!1,processData:!1,contentType:!1,headers:{csrftoken:ACC.config.CSRFToken},success:e=>this.handleSuccess(e),error:()=>this.handleError()})}handleSuccess(t){if(t.successful)a(ACC.messages.contactUsMessageSent,"success"),this.clearFields(),this.clearTopicDropdown(),this.$fileInputContainer.trigger("fileUpload.clear"),$("#contact-us-recaptcha").hide(),this.$sendButton.attr("disabled","disabled");else{let o=ACC.messages.contactUsErrorMessage;for(const i in t.errors)o+=` ${ACC.messages["contactFormError"+i]}!`;a(o,"test")}l(),this.$sendButton.removeClass("loading")}handleError(){a(ACC.messages.contactUsErrorMessage,"error"),this.$sendButton.removeClass("loading")}clearFields(){this.$firstName.val(""),this.$lastName.val(""),this.$phone.val(""),this.$email.val(""),this.$message.val(""),this.$orderNumber.val("")}clearTopicDropdown(){const t=$(".j-active-option"),o=$(".j-dropdown-inner button"),i=$(".j-dropdown-item");t.empty(),o.removeClass("populated"),i.removeClass("selected"),this.$subtopicDropdown.addClass("hidden")}showCaptcha(){ACC.recaptcha.enabled&&$(".contact-form input").on("keyup",()=>{$("#contact-us-recaptcha").show()})}}const D=()=>new u;export{u as ContactUsFormComponent,D as init};
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.