var $=require("jquery"),Util=require("./util.js"),layer=require("./../../layer_mobile/layer.js"),layerCss=require("./../../layer_mobile/need/layer.css"),Dialog={device:"app",loadingOn:function(){var e=layer.open({type:2,shadeClose:!1,shade:"background-color:rgba(0,0,0,0.3)"});$("#layui-m-layer"+e).attr("type","loading")},loadingOff:function(){layer.closeAll("loading")},tipSuccess:function(e){var t=2e3;e&&e.length>10&&(t=1e3*parseInt(e.length/5)),layer.open({content:e,skin:"msg",time:parseInt((t+1e3)/1e3)})},tipError:function(e){var t=2e3;e&&e.length>10&&(t=1e3*parseInt(e.length/5)),layer.open({content:e,skin:"msg",time:parseInt((t+1e3)/1e3)})},alertSuccess:function(e,t){layer.open({shadeClose:!1,content:e,btn:"确定",end:function(e){layer.close(e),t&&t()}})},alertError:function(e,t){layer.open({shadeClose:!1,content:e,btn:"确定",end:function(e){layer.close(e),t&&t()}})},confirm:function(e,t,o,i){t=t||!1,o=o||!1,layer.open({content:e,btn:["是","否"],yes:function(e){layer.close(e),t&&t()},no:function(e){layer.close(e),o&&o()}})},dialog:function(e,t){var o=$.extend({width:"100%",height:"100%",top:"",closeBtn:!0,closeCallback:function(){}},t),i=['<div style="position:absolute;left:0;top:0;right:0;bottom:0px;background:none;">','<div style="position:relative;margin:auto;width:'+o.width+";height:"+o.height+";"+(o.top?"margin-top:"+o.top:"")+';">',o.closeBtn?'<a href="javascript:;" class="h-dialog-close" style="display:block;position:absolute;width:40px;height:40px;'+("100%"==o.width?"right:0px;top:0px;":"right:-20px;top:-20px;")+'text-decoration:none;color:#FFF;border-radius:50%;text-align:center;line-height:40px;font-size:20px;background:#999;border:1px solid #FFF;">X</a>':"",'<iframe style="width:100%;height:100%;border:none;margin:0;padding:0;" src="'+e+'"></iframe>',"</div>","</div>"];return layer.open({type:1,content:i.join(""),shade:!0,anim:"up",style:"position:fixed;left:0;top:0; width:100%;height:100%;border:none;-webkit-animation-duration:.5s;animation-duration:.5s;background:none;",success:function(e){var t=$(e).attr("index");$(e).find(".h-dialog-close").on("click",function(){return layer.close(t),!1})},end:function(){o.closeCallback()}})},dialogContent:function(e,t){var o=$.extend({width:"auto",height:"auto",top:"40px",closeBtn:!0,openCallback:function(){},closeCallback:function(){}},t),i=$(e).width(),n=$(e).height(),l=['<div style="position:absolute;left:0;top:0;right:0;bottom:0px;background:none;">','<div style="position:relative;margin:auto;width:'+("auto"==o.width?i+"px":o.width)+";height:"+("auto"==o.height?n+"px":o.height)+";"+(o.top?"margin-top:"+o.top:"")+';">',o.closeBtn?'<a href="javascript:;" class="h-dialog-close" style="display:block;position:absolute;width:20px;height:20px;'+("100%"==o.width?"right:0px;top:0px;":"right:-10px;top:-10px;")+'text-decoration:none;color:#FFF;border-radius:50%;text-align:center;line-height:20px;font-size:16px;background:#999;border:1px solid #FFF;">X</a>':"",e,"</div>","</div>"];return layer.open({type:1,content:l.join(""),shade:!0,anim:"up",style:"position:fixed;left:0;top:0; width:100%;height:100%;border:none;-webkit-animation-duration:.5s;animation-duration:.5s;background:none;",success:function(e){var t=$(e).attr("index");$(e).find(".h-dialog-close").on("click",function(){return layer.close(t),!1}),o.openCallback()},end:function(){o.closeCallback()}})},dialogCloseAll:function(){layer.closeAll()},dialogClose:function(e){layer.close(e)},input:function(e,t){var o=$.extend({label:"请输入",width:"200px",height:"auto",defaultValue:""},t),i=o.defaultValue,n=Dialog.dialogContent(['<div id="dialog-input-box" style="width:',o.width,";height:",o.height,';background:#FFF;border-radius:3px;">','<div style="padding:10px 10px 0 10px;">',o.label,"</div>",'<div style="padding:10px;"><input type="text" style="border:1px solid #CCC;height:30px;line-height:30px;padding:0 5px;width:100%;display:block;box-sizing:border-box;outline:none;border-radius:2px;" value="',Util.specialchars(o.defaultValue),'" /></div>','<div style="padding:10px;text-align:center;color:#40AFFE;line-height:20px;border-top:1px solid #EEE;" class="close">确定</div>',"</div>"].join(""),{openCallback:function(){$("#dialog-input-box").find(".close").on("click",function(){Dialog.dialogClose(n)}),$("#dialog-input-box").find("input").on("change",function(){i=$(this).val()})},closeCallback:function(){e&&e(i)}})}};module.exports=Dialog;