/*!
 * SAP UI development toolkit for HTML5 (SAPUI5/OpenUI5)
 * (c) Copyright 2009-2015 SAP SE or an SAP affiliate company.
 * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
 */
sap.ui.define(['jquery.sap.global','./Button','./Dialog','./Text','sap/ui/core/IconPool','sap/ui/core/theming/Parameters'],function(q,B,D,T,I,P){"use strict";var M={};M._rb=sap.ui.getCore().getLibraryResourceBundle("sap.m");M.Action={OK:"OK",CANCEL:"CANCEL",YES:"YES",NO:"NO",ABORT:"ABORT",RETRY:"RETRY",IGNORE:"IGNORE",CLOSE:"CLOSE",DELETE:"DELETE"};M.Icon={NONE:undefined,INFORMATION:"INFORMATION",WARNING:"WARNING",ERROR:"ERROR",SUCCESS:"SUCCESS",QUESTION:"QUESTION"};(function(){var A=M.Action,a=M.Icon,c={"INFORMATION":"sapMMessageBoxInfo","WARNING":"sapMMessageBoxWarning","ERROR":"sapMMessageBoxError","SUCCESS":"sapMMessageBoxSuccess","QUESTION":"sapMMessageBoxQuestion"},m={"INFORMATION":I.getIconURI("message-information"),"WARNING":I.getIconURI("message-warning"),"ERROR":I.getIconURI("message-error"),"SUCCESS":I.getIconURI("message-success"),"QUESTION":I.getIconURI("question-mark")};M.show=function(v,o){var d,r=null,t=this,b=[],i,s,e,f,C,g,h,j={id:sap.ui.core.ElementMetadata.uid("mbox"),initialFocus:null,textDirection:sap.ui.core.TextDirection.Inherit,verticalScrolling:true,horizontalScrolling:true,details:""};if(typeof o==="string"||arguments.length>2){s=arguments[1];e=arguments[2];f=arguments[3];C=arguments[4];g=arguments[5];h=arguments[6];o={icon:s,title:e,actions:f,onClose:C,id:g,styleClass:h};}if(o.hasOwnProperty("details")){j.icon=sap.m.MessageBox.Icon.INFORMATION;j.actions=[A.OK,A.CANCEL];o=q.extend({},j,o);v=l(o,v);}o=q.extend({},j,o);if(typeof o.actions!=="undefined"&&!q.isArray(o.actions)){o.actions=[o.actions];}if(!o.actions||o.actions.length===0){o.actions=[A.OK];}function k(u){var w;if(M.Action.hasOwnProperty(u)){w=t._rb.getText("MSGBOX_"+u);}var x=new B({id:sap.ui.core.ElementMetadata.uid("mbox-btn-"),text:w||u,press:function(){r=u;d.close();}});return x;}for(i=0;i<o.actions.length;i++){b.push(k(o.actions[i]));}function l(o,v){var u;if(typeof v==="string"){u=new T().setText(v).addStyleClass("sapMMsgBoxText");}else if(v instanceof sap.ui.core.Control){u=v.addStyleClass("sapMMsgBoxText");}var w=new sap.m.TextArea({value:o.details,editable:false,visible:false});var L=new sap.m.Link({text:t._rb.getText("MSGBOX_LINK_TITLE"),press:function(){w.setVisible(true);this.setVisible(false);d._setInitialFocus();}});L.addStyleClass("sapMMessageBoxLinkText");w.addStyleClass("sapMMessageBoxDetails");var x=new sap.ui.layout.VerticalLayout({width:"100%",content:[u,L,w]});return x;}function n(){if(typeof o.onClose==="function"){o.onClose(r);}d.detachAfterClose(n);d.destroy();}function p(){var i=0;var u=null;if(o.initialFocus){if(o.initialFocus instanceof sap.ui.core.Control){u=o.initialFocus;}if(typeof o.initialFocus==="string"){for(i=0;i<b.length;i++){if(M.Action.hasOwnProperty(o.initialFocus)){if(t._rb.getText("MSGBOX_"+o.initialFocus).toLowerCase()===b[i].getText().toLowerCase()){u=b[i];break;}}else{if(o.initialFocus.toLowerCase()===b[i].getText().toLowerCase()){u=b[i];break;}}}}}return u;}d=new D({id:o.id,type:sap.m.DialogType.Message,title:o.title,icon:m[o.icon],initialFocus:p(),verticalScrolling:o.verticalScrolling,horizontalScrolling:o.horizontalScrolling,afterClose:n});d.addEventDelegate({onAfterRendering:function(){d.$().attr("role","alertdialog");}});if(typeof(v)==="string"){d.addContent(new T({textDirection:o.textDirection}).setText(v).addStyleClass("sapMMsgBoxText"));}else if(v instanceof sap.ui.core.Control){d.addContent(v.addStyleClass("sapMMsgBoxText"));}if(b.length>2){for(i=0;i<b.length;i++){d.addButton(b[i]);}}else{d.setBeginButton(b[0]);if(b[1]){d.setEndButton(b[1]);}}if(c[o.icon]){d.addStyleClass(c[o.icon]);}if(o.styleClass){d.addStyleClass(o.styleClass);}d.open();};M.alert=function(v,o){var d={icon:a.NONE,title:this._rb.getText("MSGBOX_TITLE_ALERT"),actions:A.OK,id:sap.ui.core.ElementMetadata.uid("alert"),initialFocus:null},C,t,s,S;if(typeof o==="function"||arguments.length>2){C=arguments[1];t=arguments[2];s=arguments[3];S=arguments[4];o={onClose:C,title:t,id:s,styleClass:S};}o=q.extend({},d,o);return M.show(v,o);};M.confirm=function(v,o){var d={icon:a.QUESTION,title:this._rb.getText("MSGBOX_TITLE_CONFIRM"),actions:[A.OK,A.CANCEL],id:sap.ui.core.ElementMetadata.uid("confirm"),initialFocus:null},C,t,s,S;if(typeof o==="function"||arguments.length>2){C=arguments[1];t=arguments[2];s=arguments[3];S=arguments[4];o={onClose:C,title:t,id:s,styleClass:S};}o=q.extend({},d,o);return M.show(v,o);};}());return M;},true);
