(function(){"use strict";u8.Crm.Widgets.PhoneInput=function(t,e){this.TextInput(t,$.extend({},u8.Crm.Widgets.PhoneInput.defaults,e))};u8.Crm.Widgets.PhoneInput.states=u8.Base.Widgets.TextInput.states;u8.Crm.Widgets.PhoneInput.makeClass({name:"PhoneInput",deriveFrom:u8.Base.Widgets.TextInput});u8.Crm.Widgets.PhoneInput.defaults={type:"tel",ghostTextWhenDisabled:false,injectAutoSuggestOnClick:true,autoSuggestFormat:u8.session.webConfigValues.get("Phone.AutoSuggestFormat"),injectAutoSuggestKeys:[8,33,36,37],removeAutoSuggestKeys:[46]};u8.Crm.Widgets.PhoneInput.override({_showGhostText:function(t,e){if(e===undefined){return}this._shouldAutoSuggestShow=this._suppressAutoSuggest?false:!!e;if(this._shouldAutoSuggestShow&&this.ghostText===undefined&&this.autoSuggestFormat){if(!this._loadGhostTextDespammed){this._loadGhostTextDespammed=this._loadGhostText.bind(this).despam(1)}this._loadGhostTextDespammed(function(e){this.ghostText=e;t(this._shouldAutoSuggestShow);this._adjustInputMargin()})}else{t(this._shouldAutoSuggestShow);this._adjustInputMargin()}},_onFocus:function(t){t();this._suppressAutoSuggest=this.getInputElement().val()!=="";this._showGhostText(!this._suppressAutoSuggest)},_onBlur:function(t){t();this._suppressAutoSuggest=false;this._showGhostText(false)},_onKeyDown:function(t,e){var s=this.getInputElement().val().length;if(s==0&&this._isGhostTextVisible()){if(this.removeAutoSuggestKeys.indexOf(e.which)>-1){this._suppressAutoSuggest=true;this._showGhostText(false)}else if(this.injectAutoSuggestKeys.indexOf(e.which)>-1){this._injectAutoSuggest()}}t(e)},_onGhostClick:function(){if(this.injectAutoSuggestOnClick){this._injectAutoSuggest()}},_onGhostMousedown:function(t,e){e.preventDefault();return false},_onInput:function(t,e){if(this._isGhostTextVisible()){this._showGhostText(false);this._injectAutoSuggest(this.getValue())}t(e)}});$.extend(u8.Crm.Widgets.PhoneInput.prototype,{getUid:function(){return uid},setUid:function(t){var e=!u8.equalsRecordUid(this.uid,t);this.uid=t;if(e){this._updateGhostText()}},getLinks:function(){return this.links},setLinks:function(t){if(this.links===t){return}this.links=t;this._updateGhostText()},getCountryCode:function(){return this.countryCode},setCountryCode:function(t){if(this.countryCode===t){return}this.countryCode=t;this._updateGhostText()},getAreaCode:function(){return this.areaCode},setAreaCode:function(t){if(this.areaCode===t){return}this.areaCode=t;this._updateGhostText()},_adjustInputMargin:function(){var t=this._getGhostTextElement();var e=this.getInputElement();e.css("margin-left",this._isGhostTextVisible()?t.outerWidth():0);this._adjustWidth()},_injectAutoSuggest:function(t){this._suppressAutoSuggest=true;this._showGhostText(false);this.getInputElement().val("");var e;if(this._onChange){e=this._onChange;this._onChange=function(t){}}this.setValue((this.ghostText||"")+(t||""));if(e){this._onChange=e;e=null}},_updateGhostText:function(){this.ghostText=undefined;this._showGhostText(this._shouldAutoSuggestShow)},_loadGhostText:function(t){if(this._isDisposed){return}var e=this,s=this.getAreaCode(),i=this.getCountryCode(),u=s||s==="",o=i||i==="";var n=""+(s||"")+(i||"")!=="";if((!u||!o)&&u8.isValidRecordUid(this.uid)){u8.Crm.Phone.getNumberPrefixes(this.uid,this.fieldId,this.links,h)}else if(n){h({areaCode:s,countryCode:i})}else{h({})}function h(n){if(e._isDisposed){return}n.areaCode=u?s:n.areaCode||"";n.countryCode=o?+i:+n.countryCode||"";n.number="";var h;if(n.areaCode||n.countryCode){if(n.areaCode.startsWith("0")){n.areaCode=n.areaCode.substr(1)}h=u8.format(e.autoSuggestFormat,n)}else{h=""}t.call(e,h)}}})})();