(window.webpackWcBlocksJsonp=window.webpackWcBlocksJsonp||[]).push([[1],{126:function(e,t,r){"use strict";var n=r(3),a=r.n(n);function o(e,t){for(var r=0;r1&&void 0!==arguments[1])||arguments[1],r="-"===e[0],n=r&&t,a=(e=e.replace("-","")).split("."),o=a[0],i=a[1]||"";return{beforeDecimal:o,afterDecimal:i,hasNagation:r,addNegation:n}}function y(e,t,r){for(var n="",a=r?"0":"",o=0;o<=t-1;o++)n+=e[o]||a;return n}function S(e,t){if(e.value=e.value,null!==e){if(e.createTextRange){var r=e.createTextRange();return r.move("character",t),r.select(),!0}return e.selectionStart||0===e.selectionStart?(e.focus(),e.setSelectionRange(t,t),!0):(e.focus(),!1)}}function b(e,t,r){return Math.min(Math.max(e,t),r)}function x(e){return Math.max(e.selectionStart,e.selectionEnd)}var w={thousandSeparator:p.oneOfType([p.string,p.oneOf([!0])]),decimalSeparator:p.string,allowedDecimalSeparators:p.arrayOf(p.string),thousandsGroupStyle:p.oneOf(["thousand","lakh","wan"]),decimalScale:p.number,fixedDecimalScale:p.bool,displayType:p.oneOf(["input","text"]),prefix:p.string,suffix:p.string,format:p.oneOfType([p.string,p.func]),removeFormatting:p.func,mask:p.oneOfType([p.string,p.arrayOf(p.string)]),value:p.oneOfType([p.number,p.string]),defaultValue:p.oneOfType([p.number,p.string]),isNumericString:p.bool,customInput:p.elementType,allowNegative:p.bool,allowEmptyFormatting:p.bool,allowLeadingZeros:p.bool,onValueChange:p.func,onKeyDown:p.func,onMouseUp:p.func,onChange:p.func,onFocus:p.func,onBlur:p.func,type:p.oneOf(["text","tel","password"]),isAllowed:p.func,renderText:p.func,getInputRef:p.oneOfType([p.func,p.shape({current:p.any})])},k={displayType:"input",decimalSeparator:".",thousandsGroupStyle:"thousand",fixedDecimalScale:!1,prefix:"",suffix:"",allowNegative:!0,allowEmptyFormatting:!1,allowLeadingZeros:!1,isNumericString:!1,type:"text",onValueChange:h,onChange:h,onKeyDown:h,onMouseUp:h,onFocus:h,onBlur:h,isAllowed:function(){return!0}},O=function(e){function t(e){var r,n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),r=!(n=s(t).call(this,e))||"object"!=typeof n&&"function"!=typeof n?l(this):n;var a=e.defaultValue;r.validateProps();var o=r.formatValueProp(a);return r.state={value:o,numAsString:r.removeFormatting(o)},r.selectionBeforeInput={selectionStart:0,selectionEnd:0},r.onChange=r.onChange.bind(l(r)),r.onKeyDown=r.onKeyDown.bind(l(r)),r.onMouseUp=r.onMouseUp.bind(l(r)),r.onFocus=r.onFocus.bind(l(r)),r.onBlur=r.onBlur.bind(l(r)),r}var r,n;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&u(e,t)}(t,e),r=t,(n=[{key:"componentDidUpdate",value:function(e){this.updateValueIfRequired(e)}},{key:"componentWillUnmount",value:function(){clearTimeout(this.focusTimeout)}},{key:"updateValueIfRequired",value:function(e){var t=this.props,r=this.state,n=this.focusedElm,a=r.value,o=r.numAsString,i=void 0===o?"":o;if(e!==t){this.validateProps();var s=this.formatNumString(i),u=m(t.value)?s:this.formatValueProp(),l=this.removeFormatting(u),c=parseFloat(l),f=parseFloat(i);(isNaN(c)&&isNaN(f)||c===f)&&s===a&&(null!==n||u===a)||this.updateValue({formattedValue:u,numAsString:l,input:n})}}},{key:"getFloatString",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=this.props.decimalScale,r=this.getSeparators(),n=r.decimalSeparator,a=this.getNumberRegex(!0),o="-"===e[0];o&&(e=e.replace("-","")),n&&0===t&&(e=e.split(n)[0]);var i=(e=(e.match(a)||[]).join("").replace(n,".")).indexOf(".");return-1!==i&&(e="".concat(e.substring(0,i),".").concat(e.substring(i+1,e.length).replace(new RegExp(d(n),"g"),""))),o&&(e="-"+e),e}},{key:"getNumberRegex",value:function(e,t){var r=this.props,n=r.format,a=r.decimalScale,o=this.getSeparators().decimalSeparator;return new RegExp("\\d"+(!o||0===a||t||n?"":"|"+d(o)),e?"g":void 0)}},{key:"getSeparators",value:function(){var e=this.props.decimalSeparator,t=this.props,r=t.thousandSeparator,n=t.allowedDecimalSeparators;return!0===r&&(r=","),n||(n=[e,"."]),{decimalSeparator:e,thousandSeparator:r,allowedDecimalSeparators:n}}},{key:"getMaskAtIndex",value:function(e){var t=this.props.mask,r=void 0===t?" ":t;return"string"==typeof r?r:r[e]||" "}},{key:"getValueObject",value:function(e,t){var r=parseFloat(t);return{formattedValue:e,value:t,floatValue:isNaN(r)?void 0:r}}},{key:"validateProps",value:function(){var e=this.props.mask,t=this.getSeparators(),r=t.decimalSeparator,n=t.thousandSeparator;if(r===n)throw new Error("\n Decimal separator can't be same as thousand separator.\n thousandSeparator: ".concat(n,' (thousandSeparator = {true} is same as thousandSeparator = ",")\n decimalSeparator: ').concat(r," (default value for decimalSeparator is .)\n "));if(e&&("string"===e?e:e.toString()).match(/\d/g))throw new Error("\n Mask ".concat(e," should not contain numeric character;\n "))}},{key:"setPatchedCaretPosition",value:function(e,t,r){S(e,t),setTimeout((function(){e.value===r&&S(e,t)}),0)}},{key:"correctCaretPosition",value:function(e,t,r){var n=this.props,a=n.prefix,o=n.suffix,i=n.format;if(""===e)return 0;if(t=b(t,0,e.length),!i){var s="-"===e[0];return b(t,a.length+(s?1:0),e.length-o.length)}if("function"==typeof i)return t;if("#"===i[t]&&g(e[t]))return t;if("#"===i[t-1]&&g(e[t-1]))return t;var u=i.indexOf("#");t=b(t,u,i.lastIndexOf("#")+1);for(var l=i.substring(t,i.length).indexOf("#"),c=t,f=t+(-1===l?0:l);c>u&&("#"!==i[c]||!g(e[c]));)c-=1;return!g(e[f])||"left"===r&&t!==u||t-c0&&void 0!==arguments[0]?arguments[0]:"",t=this.props,r=t.format,n=t.allowEmptyFormatting,a=e;return""!==e||n?"-"!==e||r?"string"==typeof r?this.formatWithPattern(a):"function"==typeof r?r(a):this.formatAsNumber(a):"-":""}},{key:"formatValueProp",value:function(e){var t=this.props,r=t.format,n=t.decimalScale,a=t.fixedDecimalScale,o=t.allowEmptyFormatting,i=this.props,s=i.value,u=i.isNumericString,l=!(s=m(s)?e:s)&&0!==s;return l&&o&&(s=""),l&&!o?"":("number"==typeof s&&(s=s.toString(),u=!0),"Infinity"===s&&u&&(s=""),u&&!r&&"number"==typeof n&&(s=function(e,t,r){if(-1!==["","-"].indexOf(e))return e;var n=-1!==e.indexOf(".")&&t,a=v(e),o=a.beforeDecimal,i=a.afterDecimal,s=a.hasNagation,u=parseFloat("0.".concat(i||"0")).toFixed(t).split("."),l=o.split("").reverse().reduce((function(e,t,r){return e.length>r?(Number(e[0])+Number(t)).toString()+e.substring(1,e.length):t+e}),u[0]),c=y(u[1]||"",Math.min(t,i.length),r),f=n?".":"";return"".concat(s?"-":"").concat(l).concat(f).concat(c)}(s,n,a)),u?this.formatNumString(s):this.formatInput(s))}},{key:"formatNegation",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=this.props.allowNegative,r=new RegExp("(-)"),n=new RegExp("(-)(.)*(-)"),a=r.test(e),o=n.test(e);return e=e.replace(/-/g,""),a&&!o&&t&&(e="-"+e),e}},{key:"formatInput",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=this.props.format;return t||(e=this.removePrefixAndSuffix(e),e=this.formatNegation(e)),e=this.removeFormatting(e),this.formatNumString(e)}},{key:"isCharacterAFormat",value:function(e,t){var r=this.props,n=r.format,a=r.prefix,o=r.suffix,i=r.decimalScale,s=r.fixedDecimalScale,u=this.getSeparators().decimalSeparator;return"string"==typeof n&&"#"!==n[e]||!(n||!(e=t.length-o.length||i&&s&&t[e]===u))}},{key:"checkIfFormatGotDeleted",value:function(e,t,r){for(var n=e;nr&&a-n>r;)n++;return{start:r,end:a-n}}(t,r),y=d.start,S=d.end;if(!a&&y===S&&-1!==c.indexOf(r[g])){var b=0===u?"":f;return r.substr(0,g)+b+r.substr(g+1,r.length)}var x=a?0:i.length,w=t.length-(a?0:s.length);if(r.length>t.length||!r.length||y===S||0===g&&m===t.length||g===x&&m===w)return r;if(this.checkIfFormatGotDeleted(y,S,t)&&(r=t),!a){var k=this.removeFormatting(r),O=v(k,o),P=O.beforeDecimal,F=O.afterDecimal,N=O.addNegation,C=eb;)S--;S=this.correctCaretPosition(s,S,"left")}}else for(;!d.test(s[S])&&Sx)&&(e.preventDefault(),this.setPatchedCaretPosition(r,S,s)),e.isUnitTestRun&&this.setPatchedCaretPosition(r,S,s),g(e)}else g(e)}},{key:"onMouseUp",value:function(e){var t=e.target,r=t.selectionStart,n=t.selectionEnd,a=t.value,o=void 0===a?"":a;if(r===n){var i=this.correctCaretPosition(o,r);i!==r&&this.setPatchedCaretPosition(t,i,o)}this.props.onMouseUp(e)}},{key:"onFocus",value:function(e){var t=this;e.persist(),this.focusedElm=e.target,this.focusTimeout=setTimeout((function(){var r=e.target,n=r.selectionStart,a=r.selectionEnd,o=r.value,i=void 0===o?"":o,s=t.correctCaretPosition(i,n);s===n||0===n&&a===i.length||t.setPatchedCaretPosition(r,s,i),t.props.onFocus(e)}),0)}},{key:"render",value:function(){var e,t,r,n=this.props,o=n.type,s=n.displayType,u=n.customInput,l=n.renderText,c=n.getInputRef,f=n.format,p=this.state.value,h=(e=this.props,t=w,r={},Object.keys(e).forEach((function(n){t[n]||(r[n]=e[n])})),r),g=i({inputMode:function(e){return e||!(navigator.platform&&/iPhone|iPod/.test(navigator.platform))}(f)?"numeric":void 0},h,{type:o,value:p,onChange:this.onChange,onKeyDown:this.onKeyDown,onMouseUp:this.onMouseUp,onFocus:this.onFocus,onBlur:this.onBlur});if("text"===s)return l?l(p)||null:a.a.createElement("span",i({},h,{ref:c}),p);if(u){var m=u;return a.a.createElement(m,i({},g,{ref:c}))}return a.a.createElement("input",i({},g,{ref:c}))}}])&&o(r.prototype,n),t}(a.a.Component);O.propTypes=w,O.defaultProps=k,t.a=O}}]);