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=757)}({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},6:function(e,t){e.exports=n},757:function(e,t,i){var s,o;s=[i(758)],void 0===(o=function(e){"use strict";return{formMixin:e}}.apply(t,s))||(e.exports=o)},758: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(759),i(761),i(6),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(){return this.props.isExperimentOpen("sv_contactFormSendEmailThroughFormBuilder")}function _(){return this.props.isExperimentOpen("sv_contactFormUseFormBuilderSubmit")}function D(e,t){return(e||[]).reduce(function(e,i){return i[t]?e+1:e},0)}function R(e){return"message"===e.fieldType?"fieldMessage":"field"+(e.index+1)}function C(t,i,s){var n,r=this,a=this.props.compData,p=a.toEmailAddress,l=a.bccEmailAddress,c=["phone","address","date","website","email"],d=e.reduce(this.props.orderedFields,function(t,i){var s,o,n;return i.hidden&&t.push((s={label:i.fieldLabel},o=h[i.fieldType]||i.fieldType,n=e.merge({},function(t){return e.includes(c,t.fieldType)?{tag:"main"}:{}}(i),function(e){return{value:"customField"===e.fieldType?{string:r.state[R(e)].value||""}:r.state[R(e)].value}}(i)),o in s?Object.defineProperty(s,o,{value:n,enumerable:!0,configurable:!0,writable:!0}):s[o]=n,s)),t},[]),u={to:[{address:p||"",name:p||""}]},m=l?{bcc:[{address:l,name:l}]}:{},y=t?{editorMetaData:{siteId:this.props.siteId,pageId:this.props.pageId,compDataId:this.props.compData.id}}:{};o.ajaxLibrary.ajax({type:"POST",dataType:"json",contentType:"application/json; charset=utf-8",url:this.props.activityInfo.baseUrl+"/"+F,headers:{Authorization:(n=r.props.getClientSpecMapEntry(f),e.get(n,"instance")),"x-wix-site-revision":this.props.siteRevision},data:e.merge({fields:d},u,m,y),success:i,error:s})}function O(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||(_.call(this)&&"SubscribeFormActivity"!==this.getActivityName()?M.call(this)||C.call(this,!1):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())),w.call(this),this.isBusy=!1}var A=["abort","timeout"];function U(t,i){this.retryCount+=1;var s=_.call(this)&&M.call(this);if(!s&&this.shouldSubmitFallbackRequest&&e.includes(A,i)&&this.retryCount<2){var o=this.props.isExperimentOpen("sendContactFormEmailsViaPong"),n=this.props.isExperimentOpen("longer_timeouts_pong"),a=b.call(this);E.call(this,x(this.props.externalBaseUrl||"",o),a,O.bind(this,this.getActivityName()),U.bind(this),N(n))}else!s&&this.shouldSubmitFallbackRequest&&e.includes(A,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:O.bind(this,this.getActivityName()),error:U.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 w(){this.setState(this.getCleanFormState())}function N(e){return e?3e4:8e3}function B(e){if(e.preventDefault(),this.retryCount=0,this.shouldBlockSubmit&&this.shouldBlockSubmit())this.blockSubmit(p.findDOMNode(this));else{k.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:D(this.props.orderedFields,"hidden"),numOfRequiredFields:D(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}),k.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");if(_.call(this)&&M.call(this))C.call(this,!0,O.bind(this,this.getActivityName()),U.bind(this));else{var 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,O.bind(this,this.getActivityName()),U.bind(this),N(n)):E.call(this,x(this.props.externalBaseUrl||"",o),c,O.bind(this,this.getActivityName()),U.bind(this),N(n))}}else s||k.call(this,a.CONTACT_FORM_SUBMIT_VALIDATION_FAILURE,i)}}function E(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 k(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=e.shouldResetComponent;t&&t!==this.shouldResetFields&&w.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:B.bind(this),children:this.props.compData.submitButtonLabel||"Send"}})}}}.apply(t,s))||(e.exports=o)},759:function(e,t,i){var s,o;s=[i(760),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)},760: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"}}}')},761:function(e,t,i){var s,o;s=[i(762)],void 0===(o=function(e){"use strict";return e}.apply(t,s))||(e.exports=o)},762: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