define("formCommon",["lodash","coreUtils","santa-components","componentsCore","prop-types","reactDOM","santa-core-utils"],function(e,t,i,s,o,n,r){return function(e){var t={};function i(s){if(t[s])return t[s].exports;var o=t[s]={i:s,l:!1,exports:{}};return e[s].call(o.exports,o,o.exports,i),o.l=!0,o.exports}return i.m=e,i.c=t,i.d=function(e,t,s){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)i.d(s,o,function(t){return e[t]}.bind(null,o));return s},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=752)}({0:function(t,i){t.exports=e},1:function(e,i){e.exports=t},10:function(e,t){e.exports=r},2:function(e,t){e.exports=i},3:function(e,t){e.exports=s},4:function(e,t){e.exports=o},7:function(e,t){e.exports=n},752:function(e,t,i){var s,o;s=[i(753)],void 0===(o=function(e){"use strict";return{formMixin:e}}.apply(t,s))||(e.exports=o)},753:function(e,t,i){var s,o,n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};s=[i(0),i(2),i(10),i(3),i(1),i(754),i(756),i(7),i(4)],void 0===(o=function(e,t,i,s,o,r,a,p,l){"use strict";var c=o.cookieUtils,d=o.dateTimeUtils,u=o.ajaxLibrary,m="wixClient",h={name:"firstName",secondaryEmail:"email",customField:"additional"},f=-666;function y(e,t,i,s,o,n,r,a,p,l,c){return c?{metaSiteId:n||"dc853130-4fb2-464f-878d-3b6667dc4f97",to:[{address:i,name:i}],bcc:s?{address:s,name:s}:null,from:{address:e,name:t},contactPhone:a,contactAddress:l,formSubject:p,formMessage:r}:{to:[{address:i,personal:i}],bcc:s?[{address:s||"n/a",personal:s||"n/a"}]:[],cc:[],from:{address:e,personal:t},subject:o,metaSiteId:n||"dc853130-4fb2-464f-878d-3b6667dc4f97",plainTextMessage:"n/a"}}function g(t,i,s,o){var n=new Date,r={todayDate:"<%=todayDay%> <%=todayMonthName%>, <%=todayYear%>",singleField:'
<%=fieldKey%> <%=fieldValue%>',outerMessage:'- <%=title%>
- <%=via%> <%=websiteUrl%>
- <%=details%>
'+(o?'- <%=formNameLabel%> <%=formName%>
':"")+'- <%=sentOn%> <%=dateToday%>
- <%=thanks%>
'};return e.template(r.outerMessage)({title:this.translatedKeys.title,via:this.translatedKeys.via,websiteUrl:i,details:this.translatedKeys.details,fields:e.reduce(t,function(t,i,s){return t+e.template(r.singleField)({fieldKey:s,fieldValue:i})},""),sentOn:this.translatedKeys.sentOn,dateToday:e.template(r.todayDate)({todayDay:n.getDate(),todayMonthName:d.getMonthName(n.getMonth()),todayYear:n.getFullYear()}),formNameLabel:this.translatedKeys.formNameLabel,formName:o||this.translatedKeys.formNameNoValuePlacholder,thanks:this.translatedKeys["thanks"+(s?"_premium":"")]})}function v(){var e=void 0,t=this.props.structure&&this.props.structure.dataQuery;switch(t&&(void 0===t?"undefined":n(t))){case"string":e=t;break;case"object":e=t.id}return(e||"").replace("#","")}function b(t){var i=this,s=void 0,o=void 0,n=this.props.isPremiumUser,r=this.getFormFields.call(this),a=this.props.compData.toEmailAddress,p=this.props.compData.bccEmailAddress,l=this.getInputName(),c=this.props.metaSiteId,d=this.props.isExperimentOpen("sendContactFormEmailsViaPong"),u=this.props.compData.formName;if(r.newModel){var m=function(e){return(r.data.getAll(e)[0]||{}).value};o=r.data.displayed,s=y(m("email"),l,a,p,this.translatedKeys["subject"+(n?"_premium":"")]+" "+m("email"),c,m("message"),m("phone"),m("subject"),m("address"),d)}else o=r,s=y(this.state.email.value,l,a,p,this.translatedKeys["subject"+(n?"_premium":"")]+" "+(r.email||r.Email||r[this.props.compData.emailFieldLabel]),c,this.state.message&&this.state.message.value,this.state.phone&&this.state.phone.value,this.state.subject&&this.state.subject.value,this.state.address&&this.state.address.value,d);return e.assign(s,{componentId:this.props.id,compDataId:v.call(this),pageId:e.isEmpty(this.props.compMasterPageData)?this.props.pageId:"masterPage",siteId:this.props.siteId}),d?(s.fields=o,s):t?function(t,i,s,o){var n=o&&!e.isEmpty(o)?{formName:o}:{},r=e.merge({viaContactForm:"via Contact Form",aSiteVisitor:"A site visitor",neverMissALead:"Never miss a lead.",downloadThe:"Download the",wixMobileApp:"Wix Mobile App",desktopViewEditYourSettings:"Edit your email settings",mobileViewEditYourSettings:"To edit your email settings, go to your Inbox on desktop.",wixContactForm:"Wix Contact Form",to:"to"},e.pick(this.translatedKeys,"viaContactForm","aSiteVisitor","details","neverMissALead","downloadThe","wixMobileApp","desktopViewEditYourSettings","mobileViewEditYourSettings","wixContactForm","to"),{websiteUrl:i,metaSiteId:this.props.metaSiteId,fields:e.map(t,function(e,t){return{fieldKey:t,fieldValue:e}})},n);return fetch("/_api/crm-templates-server/contact-form/consume",{method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json; charset=utf-8","x-wix-site-revision":this.props.siteRevision}}).then(function(e){if(200===e.status)return e.text();throw new Error(e.statusText)})}.call(this,o,this.props.externalBaseUrl||"",n,u).then(function(e){return s.htmlMessage=e,s}).catch(function(){return s.htmlMessage=g.call(i,o,i.props.externalBaseUrl||"",n,u),s}):(s.htmlMessage=g.call(this,o,this.props.externalBaseUrl||"",n,u),s)}var T="/_api/wix-common-services-webapp/notification/invoke",I="https://fallback.wix.com",S="/_api/crm-inbox-server/pong/message",F="_api/wix-forms/v1/submit-contact-form";function x(e,t){var i=t?S:T;if(!e){var s=window.location.protocol+"//"+window.location.hostname,n=c.getCookie(m);return"{{site}}{{service}}{{secured}}?accept=json&contentType=json&appUrl={{site}}{{cookie}}".replace(/\{\{site\}\}/g,s).replace("{{service}}",i).replace("{{cookie}}",n).replace("{{secured}}","Secured")}var r=o.urlUtils.parseUrl(e);return r.protocol+"//"+r.host+i+"?accept=json&contentType=json&appUrl="+r.protocol+"//"+r.hostname}function M(e,t){return(e||[]).reduce(function(e,i){return i[t]?e+1:e},0)}function _(e){return"message"===e.fieldType?"fieldMessage":"field"+(e.index+1)}function D(){var t,i=this,s=this.props.compData,n=s.toEmailAddress,r=s.bccEmailAddress,a=["phone","address","date","website","email"],p=e.reduce(this.props.orderedFields,function(t,s){var o,n,r;return s.hidden&&t.push((o={label:s.fieldLabel},n=h[s.fieldType]||s.fieldType,r=e.merge({},function(t){return e.includes(a,t.fieldType)?{tag:"main"}:{}}(s),function(e){return{value:"customField"===e.fieldType?{string:i.state[_(e)].value}:i.state[_(e)].value}}(s)),n in o?Object.defineProperty(o,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):o[n]=r,o)),t},[]),l={to:[{address:n||"",name:n||""}]},c=r?{bcc:[{address:r,name:r}]}:{};o.ajaxLibrary.ajax({type:"POST",dataType:"json",contentType:"application/json; charset=utf-8",url:this.props.activityInfo.baseUrl+"/"+F,headers:{Authorization:(t=i.props.getClientSpecMapEntry(f),e.get(t,"instance")),"x-wix-site-revision":this.props.siteRevision},data:JSON.stringify(e.merge({},{fields:p},l,c))})}function R(t){var i;o.integrations.promoteAnalytics.trackEvent(this.props.siteApiForPromoteAnalytics,"Lead"),this.retryCount=0,this.props.reportBI(a.FORM_SUBMIT_SUCCESS,{componentId:this.props.id,componentType:this.props.structure.componentType}),this.setState({mailSent:!0}),"message"===this.props.compData.onSubmitBehavior?function(){var e=this.props.compData.successMessage||this.translatedKeys.successMessage;this.showMessage(e)}.call(this):function(){var t=this.props.compData.link;if(t){var i=o.linkRenderer.renderLink(t,this.props.linkRenderInfo,this.props.rootNavigationInfo),s=o.wixUrlParser.parseUrl(this.props.linkRenderInfo,o.linkRenderer.getLinkUrlFromLinkProps(i));if(s){var n=t.anchorDataId;e.assign(s,{anchorData:n}),s.pageId===this.props.rootNavigationInfo.pageId?n&&this.props.scrollToAnchor(n):this.props.navigateToPage(s)}}}.call(this),(i=this.props).ignoreActivityReport||i.isTemplate||(this.props.isExperimentOpen("sv_contactFormUseFormBuilderSubmit")&&"SubscribeFormActivity"!==this.getActivityName()?D.call(this):function(e,t,i,o,n){var r=s.activityTypes[t];r&&s.activityService.reportActivity(e,new r(o,i,n))}(this.props.activityInfo.baseUrl,t,this.getFieldsForActivityReporting(),this.props.activityInfo,this.getFieldLabels())),A.call(this),this.isBusy=!1}var C=["abort","timeout"];function O(t,i){if(this.retryCount+=1,this.shouldSubmitFallbackRequest&&e.includes(C,i)&&this.retryCount<2){var s=this.props.isExperimentOpen("sendContactFormEmailsViaPong"),o=this.props.isExperimentOpen("longer_timeouts_pong"),n=b.call(this);N.call(this,x(this.props.externalBaseUrl||"",s),n,R.bind(this,this.getActivityName()),O.bind(this),U(o))}else this.shouldSubmitFallbackRequest&&e.includes(C,i)&&this.retryCount>1?(this.props.reportBI(r.FORM_SUBMIT_FAILURE,{componentId:this.props.id,componentType:this.props.structure.componentType,errorDesc:"Unspecified error occurred, possibly a connection problem, fallback activated",response:JSON.stringify(t)}),function(){this.shouldSubmitFallbackRequest=!1;var e=b.call(this);u.ajax({type:"POST",dataType:"json",contentType:"application/json; charset=utf-8",url:I+T+"?accept=json&contentType=json&appUrl="+I,headers:{"x-wix-site-revision":this.props.siteRevision},data:JSON.stringify(e),success:R.bind(this,this.getActivityName()),error:O.bind(this)})}.call(this)):(this.props.reportBI(r.FORM_SUBMIT_FINAL_FALLBACK,{componentId:this.props.id,componentType:this.props.structure.componentType,errorDesc:"Error occurred in Fallback Request",response:JSON.stringify(t)}),this.setState({mailSent:!1}),this.showMessage(this.translatedKeys.error,!0),this.isBusy=!1)}function A(){this.setState(this.getCleanFormState())}function U(e){return e?3e4:8e3}function w(e){if(e.preventDefault(),this.retryCount=0,this.shouldBlockSubmit&&this.shouldBlockSubmit())this.blockSubmit(p.findDOMNode(this));else{B.call(this,a.CONTACT_FORM_CLICK_SUBMIT,{isDynamic:this.props.isDynamicContactForm});var t=this.props.compData.toEmailAddress;t&&"a33012eff368a577d48f52f310c92140"!==t||this.props.reportBI(r.FORM_SUBMIT_INVALID_EMAIL,{email:t});var i={isDynamic:this.props.isDynamicContactForm,numOfFields:M(this.props.orderedFields,"hidden"),numOfRequiredFields:M(this.props.orderedFields,"required")},s=this.isFormValid();if(!this.isBusy&&s){this.props.reportBI(a.FORM_SUBMIT,{componentId:this.props.id,componentType:this.props.structure.componentType}),B.call(this,a.CONTACT_FORM_SUBMIT_VALIDATION_SUCCESS,i),this.shouldSubmitFallbackRequest=!0,this.isBusy=!0,"message"===this.props.compData.onSubmitBehavior&&this.showMessage(this.translatedKeys.submitting);var o=this.props.isExperimentOpen("sendContactFormEmailsViaPong"),n=this.props.isExperimentOpen("longer_timeouts_pong"),l=this.props.isExperimentOpen("sv_contactFormAscendEmail"),c=b.call(this,l);l?function(e,t,i,s,o){var n=this;t.then(function(t){return u.ajax({type:"POST",dataType:"json",contentType:"application/json; charset=utf-8",url:e,headers:{"x-wix-site-revision":n.props.siteRevision},data:JSON.stringify(t),success:i,error:s,timeout:o})})}.call(this,x(this.props.externalBaseUrl||"",o),c,R.bind(this,this.getActivityName()),O.bind(this),U(n)):N.call(this,x(this.props.externalBaseUrl||"",o),c,R.bind(this,this.getActivityName()),O.bind(this),U(n))}else s||B.call(this,a.CONTACT_FORM_SUBMIT_VALIDATION_FAILURE,i)}}function N(e,t,i,s,o){u.ajax({type:"POST",dataType:"json",contentType:"application/json; charset=utf-8",url:e,headers:{"x-wix-site-revision":this.props.siteRevision},data:JSON.stringify(t),success:i,error:s,timeout:o})}function B(t,i){this.props.biVisitorId&&this.props.reportBI(t,e.merge(i,{visitorId:this.props.biVisitorId}))}return{mixins:[s.mixins.skinBasedComp,i.timersMixins.timeoutsMixin],propTypes:{compMasterPageData:t.santaTypesDefinitions.ContactFormSantaTypes.compMasterPageData,siteApiForPromoteAnalytics:t.santaTypesDefinitions.ContactFormSantaTypes.siteApiForPromoteAnalytics,id:t.santaTypesDefinitions.Component.id.isRequired,pageId:t.santaTypesDefinitions.Component.pageId.isRequired,siteId:t.santaTypesDefinitions.RendererModel.siteId.isRequired,structure:t.santaTypesDefinitions.Component.structure.isRequired,compData:t.santaTypesDefinitions.Component.compData.isRequired,rootNavigationInfo:t.santaTypesDefinitions.Component.rootNavigationInfo.isRequired,shouldResetComponent:t.santaTypesDefinitions.RenderFlags.shouldResetComponent.isRequired,contactFormTranslations:t.santaTypesDefinitions.ContactFormSantaTypes.contactFormTranslations.isRequired,isMobileView:t.santaTypesDefinitions.isMobileView.isRequired,isPremiumUser:t.santaTypesDefinitions.isPremiumUser.isRequired,isTemplate:t.santaTypesDefinitions.isTemplate.isRequired,metaSiteId:t.santaTypesDefinitions.RendererModel.metaSiteId.isRequired,externalBaseUrl:t.santaTypesDefinitions.PublicModel.externalBaseUrl,scrollToAnchor:t.santaTypesDefinitions.scrollToAnchor.isRequired,navigateToPage:t.santaTypesDefinitions.navigateToPage.isRequired,reportBI:t.santaTypesDefinitions.reportBI.isRequired,linkRenderInfo:t.santaTypesDefinitions.Link.renderInfo.isRequired,activityInfo:t.santaTypesDefinitions.Activity.activityInfo,ignoreActivityReport:l.bool,isExperimentOpen:t.santaTypesDefinitions.isExperimentOpen,isDynamicContactForm:t.santaTypesDefinitions.ContactFormSantaTypes.isDynamicContactForm.isRequired,userLanguage:t.santaTypesDefinitions.WixUserSantaTypes.userLanguage.isRequired,biVisitorId:t.santaTypesDefinitions.biVisitorId,siteRevision:t.santaTypesDefinitions.PublicModel.siteRevision,getClientSpecMapEntry:t.santaTypesDefinitions.getClientSpecMapEntry.isRequired},getInitialState:function(){return this.shouldResetFields=this.props.shouldResetComponent,this.translatedKeys=this.getLangKeys(this.props.contactFormTranslations),this.translatedKeys.submitting="…",e.merge(this.getFormInitialState(),{$mob:this.props.isMobileView?"mobile":"desktop",$dir:this.props.compData.textDirection||"left"})},showMessage:function(e,t){this.setState({notifications:{message:e,error:!!t}})},componentWillReceiveProps:function(e){var t=this.props.shouldResetComponent;t&&t!==this.shouldResetFields&&A.call(this),this.shouldResetFields=t,this.setState({$mob:e.isMobileView?"mobile":"desktop",$dir:e.compData.textDirection||"left"})},getSkinProperties:function(){return this.state.notifications.message&&this.registerReLayout(),e.merge(this.getFormSkinProperties(this.translatedKeys),{submit:{onClick:w.bind(this),children:this.props.compData.submitButtonLabel||"Send"}})}}}.apply(t,s))||(e.exports=o)},754:function(e,t,i){var s,o;s=[i(755),i(0),i(1)],void 0===(o=function(e,t,i){"use strict";return t.forEach(e,function(e,t){e.errorName=t}),i.loggingUtils.logger.register("forms","error",e),e}.apply(t,s))||(e.exports=o)},755:function(e){e.exports=JSON.parse('{"FORM_SUBMIT_FAILURE":{"errorCode":101027,"severity":"error","params":{"p1":"componentId","p2":"componentType","p3":"errorDesc","p4":"response"}},"FORM_SUBMIT_FINAL_FALLBACK":{"errorCode":101028,"severity":"fatal","params":{"p1":"componentId","p2":"componentType","p3":"errorDesc","p4":"response"}},"FORM_SUBMIT_INVALID_EMAIL":{"errorCode":101029,"severity":"error","params":{"p1":"email"}}}')},756:function(e,t,i){var s,o;s=[i(757)],void 0===(o=function(e){"use strict";return e}.apply(t,s))||(e.exports=o)},757:function(e){e.exports=JSON.parse('{"FORM_SUBMIT":{"eventId":100,"adapter":"ugc-viewer","params":{"c1":"componentId","c2":"componentType"}},"FORM_SUBMIT_SUCCESS":{"eventId":367,"adapter":"ugc-viewer","params":{"component_id":"componentId","component_type":"componentType"}},"CONTACT_FORM_CLICK_SUBMIT":{"eventId":712,"adapter":"contact-form","src":5,"params":{"is_dynamic":"isDynamic","visitor_id":"visitorId"}},"CONTACT_FORM_SUBMIT_VALIDATION_SUCCESS":{"eventId":713,"adapter":"contact-form","src":5,"params":{"is_dynamic":"isDynamic","num_of_required_fields":"numOfRequiredFields","num_of_fields":"numOfFields","visitor_id":"visitorId"}},"CONTACT_FORM_SUBMIT_VALIDATION_FAILURE":{"eventId":714,"adapter":"contact-form","src":5,"params":{"is_dynamic":"isDynamic","num_of_required_fields":"numOfRequiredFields","num_of_fields":"numOfFields","visitor_id":"visitorId"}}}')}})});
//# sourceMappingURL=formCommon.min.js.map