import React from"react";import{CssClasses}from"./constants.js";import FormElementOuter from"./FormElementOuter.js";import{getKeyString}from"./keyboard.js";import{makeSafeClassName}from"./utils.js";function renderPasswordBox(e,t){const{host:r,name:o}=e.props;let a="";var n=t.value;function l(e){e=e.value;a!==e&&(t.value=a=e,r.post("changed",{name:o,value:a}))}"string"==typeof n&&(a=n),t.value=a;var s=r.renderText(t.prompt),n=r.renderText(t.tooltip);const u=[t.type,makeSafeClassName(o)];return React.createElement(FormElementOuter,{className:u.join(" "),component:e,element:t,errorClassName:CssClasses.ERROR,htmlElementType:"label"},React.createElement("input",{type:"password",disabled:!e.enabled,placeholder:s,title:n,ref:function(n){if(null!==n){n.value=a;let t=!1;n.onmousedown=function(){t=!0},n.onmouseup=function(){t=!1},n.onfocus=function(){setTimeout(function(){var e=n.value.length;n.setSelectionRange(t?0:e,e)})},n.disabled||r.renderFocus(n,o)}},onKeyDown:function(e){var t=getKeyString(e);return"enter"===t?function(e){const t=e.currentTarget;if(a!==t.value)return l(t),t.select(),e.stopPropagation(),e.preventDefault(),!1}(e):"escape"===t?function(e){const t=e.currentTarget;if(a!==t.value)return t.value=a,t.select(),e.stopPropagation(),e.preventDefault(),!1}(e):void 0},onBlur:e=>l(e.currentTarget)}))}function renderTextBox(e,t){const{host:r,name:o}=e.props;let a="";var n=t.value;function l(e){e=e.value;a!==e&&(t.value=a=e,r.post("changed",{name:o,value:a}))}"string"==typeof n&&(a=n),"number"==typeof n&&(a=r.formatNumber(n,{useGrouping:!0})),t.value=a;var s=r.renderText(t.prompt),n=r.renderText(t.tooltip);const u=[t.type,makeSafeClassName(o)];return React.createElement(FormElementOuter,{className:u.join(" "),component:e,element:t,errorClassName:CssClasses.ERROR,htmlElementType:"label"},React.createElement("input",{type:"text",disabled:!e.enabled,maxLength:t.maxLength,readOnly:t.readOnly,placeholder:s,title:n,ref:function(n){if(null!==n){n.value=a;let t=!1;n.onmousedown=function(){t=!0},n.onmouseup=function(){t=!1},n.onfocus=function(){setTimeout(function(){var e=n.value.length;n.setSelectionRange(t?0:e,e)})},n.disabled||r.renderFocus(n,o)}},onKeyDown:function(e){var t=getKeyString(e);return"enter"===t?function(e){const t=e.currentTarget;if(a!==t.value)return l(t),t.select(),e.stopPropagation(),e.preventDefault(),!1}(e):"escape"===t?function(e){const t=e.currentTarget;if(a!==t.value)return t.value=a,t.select(),e.stopPropagation(),e.preventDefault(),!1}(e):void 0},onBlur:e=>l(e.currentTarget)}))}function renderTextArea(e,t){const{host:r,name:o}=e.props;let a="";var n=t.value;"string"==typeof n&&(a=n),t.value=a;var l=t.size;let s=8;"number"==typeof l&&(s=l);var u=r.renderText(t.prompt),n=r.renderText(t.tooltip),l=t.wrap||"off";const c=[t.type,makeSafeClassName(o)];return React.createElement(FormElementOuter,{className:c.join(" "),component:e,element:t,errorClassName:CssClasses.ERROR,htmlElementType:"label"},React.createElement("textarea",{disabled:!e.enabled,readOnly:t.readOnly,placeholder:u,rows:s,title:n,wrap:l,maxLength:t.maxLength,spellCheck:!1,ref:function(n){if(null!==n){n.value=a;let t=!(n.onkeydown=function(e){e.stopPropagation()});n.onmousedown=function(){t=!0},n.onmouseup=function(){t=!1},n.onfocus=function(){setTimeout(function(){var e=n.value.length;n.setSelectionRange(t?0:e,e),n.scrollTop=n.scrollHeight})},n.disabled||r.renderFocus(n,o)}},onBlur:function(e){e=e.currentTarget.value,a!==e&&(t.value=a=e,r.post("changed",{name:o,value:a}))}}))}export{renderPasswordBox,renderTextBox,renderTextArea};