i||a.getMonth()>=n)}return{getFirstDateOfMonth:e,getNumberOfDaysInMonth:t,getDateInNextMonth:a,getDateInPreviousMonth:n,isInNextMonth:l,isInPreviousMonth:s,getDateMidpoint:d,isSameMonthAndYear:i,getWeekOfMonth:o,incrementDays:c,incrementMonths:h,getLastDateOfMonth:m,isSameDay:r,getMonthDistance:u,isValidDate:p,setDateTimeToMidnight:g,createDateAtMidnight:f,isDateWithinRange:D,incrementYears:C,getYearDistance:v,clampDate:y,getTimestampFromNode:$,isMonthWithinRange:b}})}(),function(){"use strict";function e(e,a,n,i){return{template:function(t,a){var n=a.mdHideIcons,i=a.ariaLabel||a.mdPlaceholder,r="all"===n||"calendar"===n?"":' ',l="";return"all"!==n&&"triangle"!==n&&(l='
',t.addClass(s)),r+' '+l+'
'},require:["ngModel","mdDatepicker","?^mdInputContainer","?^form"],scope:{minDate:"=mdMinDate",maxDate:"=mdMaxDate",placeholder:"@mdPlaceholder",currentView:"@mdCurrentView",dateFilter:"=mdDateFilter",isOpen:"=?mdIsOpen",debounceInterval:"=mdDebounceInterval",dateLocale:"=mdDateLocale"},controller:t,controllerAs:"ctrl",bindToController:!0,link:function(e,t,s,d){var o=d[0],c=d[1],h=d[2],u=d[3],m=a.parseAttributeBoolean(s.mdNoAsterisk);if(c.configureNgModel(o,h,i),h){var p=t[0].querySelector(".md-errors-spacer");p&&t.after(angular.element("").append(p)),h.setHasPlaceholder(s.mdPlaceholder),h.input=t,h.element.addClass(r).toggleClass(l,"calendar"!==s.mdHideIcons&&"all"!==s.mdHideIcons),h.label?m||s.$observe("required",function(e){h.label.toggleClass("md-required",!!e)}):n.expect(t,"aria-label",s.mdPlaceholder),e.$watch(h.isErrorGetter||function(){return o.$invalid&&(o.$touched||u&&u.$submitted)},h.setInvalid)}else if(u)var g=e.$watch(function(){return u.$submitted},function(e){e&&(c.updateErrorState(),g())})}}}function t(e,t,a,n,i,r,l,s,d,o,c){this.$window=n,this.dateUtil=d,this.$mdConstant=i,this.$mdUtil=l,this.$$rAF=o,this.$mdDateLocale=s,this.documentElement=angular.element(document.documentElement),this.ngModelCtrl=null,this.inputElement=t[0].querySelector("input"),this.ngInputElement=angular.element(this.inputElement),this.inputContainer=t[0].querySelector(".md-datepicker-input-container"),this.calendarPane=t[0].querySelector(".md-datepicker-calendar-pane"),this.calendarButton=t[0].querySelector(".md-datepicker-button"),this.inputMask=angular.element(t[0].querySelector(".md-datepicker-input-mask-opaque")),this.$element=t,this.$attrs=a,this.$scope=e,this.date=null,this.isFocused=!1,this.isDisabled,this.setDisabled(t[0].disabled||angular.isString(a.disabled)),this.isCalendarOpen=!1,this.openOnFocus=a.hasOwnProperty("mdOpenOnFocus"),this.mdInputContainer=null,this.calendarPaneOpenedFrom=null,this.calendarPaneId="md-date-pane-"+l.nextUid(),this.bodyClickHandler=angular.bind(this,this.handleBodyClick),this.windowEventName=h.test(navigator.userAgent||navigator.vendor||window.opera)?"orientationchange":"resize",this.windowEventHandler=l.debounce(angular.bind(this,this.closeCalendarPane),100),this.windowBlurHandler=angular.bind(this,this.handleWindowBlur),this.ngDateFilter=c("date"),this.leftMargin=20,this.topMargin=null,a.tabindex?(this.ngInputElement.attr("tabindex",a.tabindex),a.$set("tabindex",null)):a.$set("tabindex","-1"),a.$set("aria-owns",this.calendarPaneId),r(t),r(angular.element(this.calendarPane));var u=this;e.$on("$destroy",function(){u.detachCalendarPane()}),a.mdIsOpen&&e.$watch("ctrl.isOpen",function(e){e?u.openCalendarPane({target:u.inputElement}):u.closeCalendarPane()}),1===angular.version.major&&angular.version.minor<=4&&this.$onInit()}t.$inject=["$scope","$element","$attrs","$window","$mdConstant","$mdTheming","$mdUtil","$mdDateLocale","$$mdDateUtil","$$rAF","$filter"],e.$inject=["$$mdSvgRegistry","$mdUtil","$mdAria","inputDirective"],angular.module("material.components.datepicker").directive("mdDatepicker",e);var a=3,n="md-datepicker-invalid",i="md-datepicker-open",r="_md-datepicker-floating-label",l="_md-datepicker-has-calendar-icon",s="_md-datepicker-has-triangle-icon",d=500,o=368,c=360,h=/ipad|iphone|ipod|android/i;t.prototype.$onInit=function(){this.locale=this.dateLocale?angular.extend({},this.$mdDateLocale,this.dateLocale):this.$mdDateLocale,this.installPropertyInterceptors(),this.attachChangeListeners(),this.attachInteractionListeners()},t.prototype.configureNgModel=function(e,t,a){this.ngModelCtrl=e,this.mdInputContainer=t,this.$attrs.$set("type","date"),a[0].link.pre(this.$scope,{on:angular.noop,val:angular.noop,0:{}},this.$attrs,[e]);var n=this;n.ngModelCtrl.$formatters.push(function(e){if(e&&!(e instanceof Date))throw Error("The ng-model for md-datepicker must be a Date instance. Currently the model is a: "+typeof e);return n.onExternalChange(e),e}),e.$viewChangeListeners.unshift(angular.bind(this,this.updateErrorState));var i=n.$mdUtil.getModelOption(e,"updateOn");i&&this.ngInputElement.on(i,angular.bind(this.$element,this.$element.triggerHandler,i))},t.prototype.attachChangeListeners=function(){var e=this;e.$scope.$on("md-calendar-change",function(t,a){e.setModelValue(a),e.onExternalChange(a),e.closeCalendarPane()}),e.ngInputElement.on("input",angular.bind(e,e.resizeInputElement));var t=angular.isDefined(this.debounceInterval)?this.debounceInterval:d;e.ngInputElement.on("input",e.$mdUtil.debounce(e.handleInputEvent,t,e))},t.prototype.attachInteractionListeners=function(){var e=this,t=this.$scope,a=this.$mdConstant.KEY_CODE;e.ngInputElement.on("keydown",function(n){n.altKey&&n.keyCode==a.DOWN_ARROW&&(e.openCalendarPane(n),t.$digest())}),e.openOnFocus&&(e.ngInputElement.on("focus",angular.bind(e,e.openCalendarPane)),angular.element(e.$window).on("blur",e.windowBlurHandler),t.$on("$destroy",function(){angular.element(e.$window).off("blur",e.windowBlurHandler)})),t.$on("md-calendar-close",function(){e.closeCalendarPane()})},t.prototype.installPropertyInterceptors=function(){var e=this;if(this.$attrs.ngDisabled){var t=this.$scope.$parent;t&&t.$watch(this.$attrs.ngDisabled,function(t){e.setDisabled(t)})}Object.defineProperty(this,"placeholder",{get:function(){return e.inputElement.placeholder},set:function(t){e.inputElement.placeholder=t||""}})},t.prototype.setDisabled=function(e){this.isDisabled=e,this.inputElement.disabled=e,this.calendarButton&&(this.calendarButton.disabled=e)},t.prototype.updateErrorState=function(e){var t=e||this.date;if(this.clearErrorState(),this.dateUtil.isValidDate(t)){if(t=this.dateUtil.createDateAtMidnight(t),this.dateUtil.isValidDate(this.minDate)){var a=this.dateUtil.createDateAtMidnight(this.minDate);this.ngModelCtrl.$setValidity("mindate",t>=a)}if(this.dateUtil.isValidDate(this.maxDate)){var i=this.dateUtil.createDateAtMidnight(this.maxDate);this.ngModelCtrl.$setValidity("maxdate",t<=i)}angular.isFunction(this.dateFilter)&&this.ngModelCtrl.$setValidity("filtered",this.dateFilter(t))}else this.ngModelCtrl.$setValidity("valid",null==t);angular.element(this.inputContainer).toggleClass(n,!this.ngModelCtrl.$valid)},t.prototype.clearErrorState=function(){this.inputContainer.classList.remove(n),["mindate","maxdate","filtered","valid"].forEach(function(e){this.ngModelCtrl.$setValidity(e,!0)},this)},t.prototype.resizeInputElement=function(){this.inputElement.size=this.inputElement.value.length+a},t.prototype.handleInputEvent=function(){var e=this.inputElement.value,t=e?this.locale.parseDate(e):null;this.dateUtil.setDateTimeToMidnight(t);var a=""==e||this.dateUtil.isValidDate(t)&&this.locale.isDateComplete(e)&&this.isDateEnabled(t);a&&(this.setModelValue(t),this.date=t),this.updateErrorState(t)},t.prototype.isDateEnabled=function(e){return this.dateUtil.isDateWithinRange(e,this.minDate,this.maxDate)&&(!angular.isFunction(this.dateFilter)||this.dateFilter(e))},t.prototype.attachCalendarPane=function(){var e=this.calendarPane,t=document.body;e.style.transform="",this.$element.addClass(i),this.mdInputContainer&&this.mdInputContainer.element.addClass(i),angular.element(t).addClass("md-datepicker-is-showing");var a=this.inputContainer.getBoundingClientRect(),n=t.getBoundingClientRect();(!this.topMargin||this.topMargin<0)&&(this.topMargin=(this.inputMask.parent().prop("clientHeight")-this.ngInputElement.prop("clientHeight"))/2);var r=a.top-n.top-this.topMargin,l=a.left-n.left-this.leftMargin,s=n.top<0&&0==document.body.scrollTop?-n.top:document.body.scrollTop,d=n.left<0&&0==document.body.scrollLeft?-n.left:document.body.scrollLeft,h=s+this.$window.innerHeight,u=d+this.$window.innerWidth;
if(this.inputMask.css({position:"absolute",left:this.leftMargin+"px",top:this.topMargin+"px",width:a.width-1+"px",height:a.height-2+"px"}),l+c>u){if(u-c>0)l=u-c;else{l=d;var m=this.$window.innerWidth/c;e.style.transform="scale("+m+")"}e.classList.add("md-datepicker-pos-adjusted")}r+o>h&&h-o>s&&(r=h-o,e.classList.add("md-datepicker-pos-adjusted")),e.style.left=l+"px",e.style.top=r+"px",document.body.appendChild(e),this.$$rAF(function(){e.classList.add("md-pane-open")})},t.prototype.detachCalendarPane=function(){this.$element.removeClass(i),this.mdInputContainer&&this.mdInputContainer.element.removeClass(i),angular.element(document.body).removeClass("md-datepicker-is-showing"),this.calendarPane.classList.remove("md-pane-open"),this.calendarPane.classList.remove("md-datepicker-pos-adjusted"),this.isCalendarOpen&&this.$mdUtil.enableScrolling(),this.calendarPane.parentNode&&this.calendarPane.parentNode.removeChild(this.calendarPane)},t.prototype.openCalendarPane=function(e){if(!this.isCalendarOpen&&!this.isDisabled&&!this.inputFocusedOnWindowBlur){this.isCalendarOpen=this.isOpen=!0,this.calendarPaneOpenedFrom=e.target,this.$mdUtil.disableScrollAround(this.calendarPane),this.attachCalendarPane(),this.focusCalendar(),this.evalAttr("ngFocus");var t=this;this.$mdUtil.nextTick(function(){t.documentElement.on("click touchstart",t.bodyClickHandler)},!1),window.addEventListener(this.windowEventName,this.windowEventHandler)}},t.prototype.closeCalendarPane=function(){function e(){t.isCalendarOpen=t.isOpen=!1}if(this.isCalendarOpen){var t=this;t.detachCalendarPane(),t.ngModelCtrl.$setTouched(),t.evalAttr("ngBlur"),t.documentElement.off("click touchstart",t.bodyClickHandler),window.removeEventListener(t.windowEventName,t.windowEventHandler),t.calendarPaneOpenedFrom.focus(),t.calendarPaneOpenedFrom=null,t.openOnFocus?t.$mdUtil.nextTick(e):e()}},t.prototype.getCalendarCtrl=function(){return angular.element(this.calendarPane.querySelector("md-calendar")).controller("mdCalendar")},t.prototype.focusCalendar=function(){var e=this;this.$mdUtil.nextTick(function(){e.getCalendarCtrl().focus()},!1)},t.prototype.setFocused=function(e){e||this.ngModelCtrl.$setTouched(),this.openOnFocus||this.evalAttr(e?"ngFocus":"ngBlur"),this.isFocused=e},t.prototype.handleBodyClick=function(e){if(this.isCalendarOpen){var t=this.$mdUtil.getClosest(e.target,"md-calendar");t||this.closeCalendarPane(),this.$scope.$digest()}},t.prototype.handleWindowBlur=function(){this.inputFocusedOnWindowBlur=document.activeElement===this.inputElement},t.prototype.evalAttr=function(e){this.$attrs[e]&&this.$scope.$parent.$eval(this.$attrs[e])},t.prototype.setModelValue=function(e){var t=this.$mdUtil.getModelOption(this.ngModelCtrl,"timezone");this.ngModelCtrl.$setViewValue(this.ngDateFilter(e,"yyyy-MM-dd",t))},t.prototype.onExternalChange=function(e){var t=this.$mdUtil.getModelOption(this.ngModelCtrl,"timezone");this.date=e,this.inputElement.value=this.locale.formatDate(e,t),this.mdInputContainer&&this.mdInputContainer.setHasValue(!!e),this.resizeInputElement(),this.updateErrorState()}}(),ngmaterial.components.datepicker=angular.module("material.components.datepicker");