define(["dom","dialogHelper","clearButtonStyle","paper-icon-button-light","material-icons","css!./style"],function(dom,dialogHelper){"use strict";function getKeyHtml(key){return'<button data-key="'+key+'" class="clearButton keyboardButton">'+function(key){return"DEL"===key?'<i class="md-icon">backspace</i>':key}(key)+"</button>"}function getDisplayValue(field){var displayValue=field.value;if("password"===field.type)for(var length=displayValue.length,displayValue="";displayValue.length<length;)displayValue+="*";return displayValue}return{show:function(options){var dlg=dialogHelper.createDialog({removeOnClose:!0,size:"fullscreen"});dlg.classList.add("keyboardDialog");var html="";return html+='<div style="margin:0;padding:0;">',html+='<button tabindex="-1" is="paper-icon-button-light" class="btnKeyboardExit autoSize"><i class="md-icon">&#xE5C4;</i></button>',options.label&&(html+="<h1>",html+=options.label,html+="</h1>"),html+='<div class="keyboardValue">'+(getDisplayValue(options.field)||"&nbsp;")+"</div>",html+='<div class="keyboardContainer">',html+='<div class="standard">',{keys:{standard:[["@","1","2","3","4","5","6","7","8","9","0","-","=","DEL"],["q","w","e","r","t","y","u","i","o","p","[","]"],["SHIFT","a","s","d","f","g","h","j","k","l",";","'"],["z","x","c","v","b","n","m",",",".","/"]]}}.keys.standard.forEach(function(row){html+='<div class="keyboardRow">',row.forEach(function(key){html+=getKeyHtml(key)}),html+="</div>"}),html+="</div>",html+='<div class="keyboardRow">',html+=getKeyHtml("SPACE"),html+="</div>",html+="</div>",html+="</div>",dlg.innerHTML=html,document.body.appendChild(dlg),dlg.addEventListener("click",function(e){var btn=e.target.closest(".keyboardButton");btn&&function(dlg,field,key){switch(key){case"DEL":field.value&&(field.value=field.value.substring(0,field.value.length-1));break;case"SHIFT":dlg.querySelector(".keyboardContainer").classList.toggle("upper");break;case"SPACE":field.value+=" ";break;default:dlg.querySelector(".keyboardContainer").classList.contains("upper")&&(key=key.toUpperCase()),field.value+=key}var replace,displayValue=getDisplayValue(field);if("password"===field.type)for(var length=displayValue.length,displayValue="";displayValue.length<length;)displayValue+="*";dlg.querySelector(".keyboardValue").innerHTML=(replace="&nbsp;",(displayValue||"&nbsp;").split(" ").join(replace))}(dlg,options.field,btn.getAttribute("data-key"))}),dlg.querySelector(".btnKeyboardExit").addEventListener("click",function(e){dialogHelper.close(dlg)}),dialogHelper.open(dlg)}}});