define(["require","exports","tslib","react","./constants","./FormElementOuter","./keyboard","./utils"],function(t,e,R,C,S,_,D,x){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),C=R.__importDefault(C),_=R.__importDefault(_);var r=C.default.lazy(function(){return new Promise(function(e,n){t(["./components/NumberRangeSlider"],e,n)}).then(R.__importStar)});e.renderNumberRangeSlider=function(e,n){return C.default.createElement(C.default.Suspense,{fallback:null},C.default.createElement(r,{component:e,element:n}))},e.renderNumber=function(t,u){var n=t.props.name,a=t.props.host,l=(f=(M=u.value,N=u.format,N=null==(N=x.isNumberRef(M)?M.format:N)?{}:N)).precision;"number"==typeof l&&0*l==0||(l=3);var i=Math.pow(10,-1*l),s=Math.round(f.step/i)*i;"number"==typeof s&&0*s<s||(s=void 0);var m=Math.floor(f.lowerBound/i)*i;"number"==typeof m&&0*m==0||(m=void 0);var p=Math.ceil(f.upperBound/i)*i;"number"==typeof p&&0*p==0||(p=void 0),void 0!==m&&void 0!==p&&p<=m&&(p=m=void 0);var e=[S.CssClasses.NUMERIC,x.makeSafeClassName(n)],r=!1;u.type===S.FormElementTypes.NUMBERSLIDER&&(e.push(S.CssClasses.SLIDER),r=!0,void 0===s&&(s=Math.max(1,i)),void 0===m&&(m=0),void 0===p&&(p=100)),void 0!==s&&e.push(S.CssClasses.STEPPER);var f={precision:l,step:s,lowerBound:m,upperBound:p},d={useGrouping:!0,minimumFractionDigits:0<l?l:0,maximumFractionDigits:0<l?l:0};function o(e){var n,t,r;if(e=function(e){if("string"==typeof e){if(e.length<1)return;e=Number(e)}if("number"==typeof e&&0*e==0)return void 0!==p&&p<e&&(e=p),void 0!==m&&e<m&&(e=m),Math.round(e/i)*i}(e),u.type===S.FormElementTypes.NUMBERSLIDER&&void 0===e&&void 0!==m&&void 0!==p&&((r=((n=(m+p)/2)-m)/(t=s||i))%1==0?e=n:(r=Math.ceil(r),(o=m+r*t)<=p&&(e=o))),void 0===e)return u.value=void 0,"";u.value={refValueType:"number",format:f,display:a.formatNumber(e,d),numeric:e};var o=20<(o=l)?20:o;return e.toFixed(o=o<0?0:o)}var v,c=null,b=null,y=(v=u.value,x.isNumberRef(v)&&(v=v.numeric),o("number"==typeof(v=x.isString(v)?a.coerceNumber(v):v)?v:void 0));function h(e){return e=o(e),c.value=b.value=e,E=c.value,y!==e&&(y=e,a.post("changed",{name:n,value:u.value}),1)}var E=void 0;function g(){var e=c.value;E!==e&&h(e)}var M=a.renderText(u.prompt),N=a.renderText(u.tooltip);return C.default.createElement(_.default,{className:e.join(" "),component:t,element:u,errorClassName:S.CssClasses.ERROR,htmlElementType:"label",ref:function(e){null!==e&&null===e.querySelector("*:focus")&&(c.value=b.value=y,E=c.value,a.renderFocus(r?c:b,n))}},C.default.createElement("input",R.__assign({placeholder:M,title:N},{type:"range",disabled:!t.enabled,min:m,max:p,step:s,onMouseMove:g,onMouseDown:g,onChange:g,onInput:g,ref:function(e){c=e}})),C.default.createElement("input",R.__assign({placeholder:M,title:N},{type:"number",disabled:!t.enabled,min:m,max:p,step:s,onKeyDown:function(e){var n=D.getKeyString(e);if("enter"===n&&h(b.value))return b.select(),e.preventDefault(),e.stopPropagation(),!1;"escape"===n&&(c.value=b.value=y,b.select()),t.autoInput=!1},onFocus:function(){b.select()},onMouseDown:function(){t.autoInput=!0},onChange:function(){t.autoInput&&(h(b.value),b.select())},onBlur:function(){h(b.value)},ref:function(e){b=e}})))}});