/*!
 * 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','sap/ui/unified/calendar/CalendarUtils'],function(q,C){"use strict";var M={};M.render=function(r,m){var d=m._getDate();var t=m.getTooltip_AsString();var a=sap.ui.getCore().getLibraryResourceBundle("sap.ui.unified");var i=m.getId();var A={value:i+"-Descr",append:true};r.write("<div");r.writeControlData(m);r.addClass("sapUiCalMonthView");r.writeClasses();if(t){r.writeAttributeEscaped("title",t);}if(m.getShowHeader()){A.value=A.value+" "+i+"-Head";}r.writeAccessibilityState(m,{role:"grid",readonly:"true",multiselectable:!m.getSingleSelection()||m.getIntervalSelection(),labelledby:A});r.write(">");r.write("<span id=\""+i+"-Descr\" style=\"display: none;\">"+a.getText("CALENDAR_DIALOG")+"</span>");this.renderMonth(r,m,d);r.write("</div>");};M.renderMonth=function(r,m,d){var l=m._getLocaleData();var f=l.getFirstDayOfWeek();var I=m.getId();var a=sap.ui.getCore().getLibraryResourceBundle("sap.ui.unified");if(m.getShowHeader()){var b=l.getMonthsStandAlone("wide");r.write("<div id=\""+I+"-Head\"class=\"sapUiCalMonthHead\" >");r.write(b[d.getUTCMonth()]);r.write("</div>");}var w=[];if(m._bLongWeekDays||!m._bNamesLengthChecked){w=l.getDaysStandAlone("abbreviated");}else{w=l.getDaysStandAlone("narrow");}var W=l.getDaysStandAlone("wide");r.write("<div");r.writeAttribute("id",I+"-CW");r.addStyle("display","none");r.writeStyles();r.writeAccessibilityState(null,{role:"columnheader"});r.write(">");r.write(a.getText("CALENDAR_WEEK"));r.write("</div>");r.write("<div");r.writeAccessibilityState(null,{role:"row"});r.write(">");for(var i=0;i<7;i++){r.write("<div");r.addClass("sapUiCalWH");r.writeAttribute("id",I+"-WH"+((i+f)%7));if(i==0){r.addClass("sapUiCalFirstWDay");}r.writeClasses();r.writeAccessibilityState(null,{role:"columnheader",label:W[(i+f)%7]});r.write(">");r.write(w[(i+f)%7]);r.write("</div>");}r.write("</div>");r.write("<div id=\""+I+"-days\" class=\"sapUiCalDays\">");this.renderDays(r,m,d);r.write("</div>");};M.renderDays=function(r,m,d){if(!d){d=m._getFocusedDate();}var l=m._getLocale();var L=m._getLocaleData();var i=d.getUTCMonth();var y=d.getUTCFullYear();var f=L.getFirstDayOfWeek();var w=L.getWeekendStart();var W=L.getWeekendEnd();var t=L.getRelativeDay(0);var T=new Date();var I=m.getId();var F=new Date(d.getTime());F.setUTCDate(1);var a=F.getUTCDay();var D=a-f;if(D<0){D=7+D;}if(D>0){F.setUTCDate(1-D);}var o=new Date(F.getTime());var Y="";var n=(i+1)%12;var s=0;var b;var A;var c=0;var e=m._getFormatLong();do{A={role:"gridcell",selected:false,label:""};Y=m._oFormatYyyymmdd.format(o,true);a=o.getUTCDay();s=m._checkDateSelected(o);b=m._getDateType(o);if(a==f){r.write("<div");r.writeAccessibilityState(null,{role:"row"});r.write(">");}r.write("<div");r.writeAttribute("id",I+"-"+Y);r.addClass("sapUiCalDay");r.addClass("sapUiCalWDay"+a);if(a==f){r.addClass("sapUiCalFirstWDay");c=C.calculateWeekNumber(o,y,l,L);}if(i!=o.getUTCMonth()){r.addClass("sapUiCalDayOtherMonth");A["disabled"]=true;}if(o.getUTCMonth()==T.getMonth()&&o.getUTCFullYear()==T.getFullYear()&&o.getUTCDate()==T.getDate()){r.addClass("sapUiCalDayToday");A["label"]=t+" ";}if(s>0){r.addClass("sapUiCalDaySel");A["selected"]=true;}if(s==2){r.addClass("sapUiCalDaySelStart");}else if(s==3){r.addClass("sapUiCalDaySelEnd");}else if(s==4){r.addClass("sapUiCalDaySelBetween");}else if(s==5){r.addClass("sapUiCalDaySelStart");r.addClass("sapUiCalDaySelEnd");}if(b){r.addClass("sapUiCalDay"+b.type);if(b.tooltip){r.writeAttributeEscaped('title',b.tooltip);}}if((a>=w&&a<=W)||(W<w&&(a>=w||a<=W))){r.addClass("sapUiCalDayWeekEnd");}r.writeAttribute("tabindex","-1");r.writeAttribute("data-sap-day",Y);r.writeClasses();A["describedby"]=I+"-CW"+" "+I+"-WNum-"+c+" "+I+"-WH"+a;A["label"]=A["label"]+e.format(o,true);r.writeAccessibilityState(null,A);r.write(">");r.write("<span");r.addClass("sapUiCalDayNum");r.writeClasses();r.write(">");r.write(o.getUTCDate());r.write("</span>");if(a==f){r.write("<span");r.writeAttribute("id",I+"-WNum-"+c);r.addClass("sapUiCalWeekNum");r.writeClasses();r.writeAccessibilityState(null,{role:"rowheader",desribedby:I+"-CW"});r.write(">");r.write(c);r.write("</span>");}r.write("</div>");if(a==(f+6)%7){r.write("</div>");}o.setUTCDate(o.getUTCDate()+1);}while(o.getUTCMonth()!=n||o.getUTCDay()!=f);};return M;},true);
