(function(e,t){function n(e){var t={scope:{selectedTemplate:"=",selectedTemplateName:"=",dateStart:"=?",dateEnd:"=?",firstDayOfWeek:"=?",showTemplate:"=?",mdOnSelect:"&",localizationMap:"=?",customTemplates:"=?",disableTemplates:"@",maxRange:"=?",onePanel:"=?",isDisabledDate:"&?",format:"=?"},template:'
{{::day.name}}
{{::day.name}}
',controller:"mdDateRangePickerCtrl",link:function(t,n,r,i){t.actionByKey=function(e,n,r){switch(e){case"prev":t.handleClickPrevMonth(r),t.runIfNotInDigest();break;case"next":t.handleClickNextMonth(r),t.runIfNotInDigest();break;case"date1":t.handleClickDate(r,t.dates[n])?t.runIfNotInDigest(t.triggerChange):t.runIfNotInDigest();break;case"date2":t.handleClickDate(r,t.dates2[n])?t.runIfNotInDigest(t.triggerChange):t.runIfNotInDigest();break;case"TD":t.handleClickSelectToday(),t.runIfNotInDigest(t.triggerChange);break;case"YD":t.handleClickSelectYesterday(),t.runIfNotInDigest(t.triggerChange);break;case"TW":t.handleClickSelectThisWeek(),t.runIfNotInDigest(t.triggerChange);break;case"LW":t.handleClickSelectLastWeek(),t.runIfNotInDigest(t.triggerChange);break;case"TM":t.handleClickSelectThisMonth(),t.runIfNotInDigest(t.triggerChange);break;case"LM":t.handleClickSelectLastMonth(),t.runIfNotInDigest(t.triggerChange);break;case"TY":t.handleClickSelectThisYear(),t.runIfNotInDigest(t.triggerChange);break;case"LY":t.handleClickSelectLastYear(),t.runIfNotInDigest(t.triggerChange);break;case"Custom Template":t.runIfNotInDigest(t.triggerChange);break;default:}},t.runIfNotInDigest=function(e){t.$root!=null&&!t.$root.$$phase&&(t.$apply(),e&&typeof e=="function"&&e())},n.on("click",function(e){var n=e.target.getAttribute("event-key"),r=e.target.getAttribute("event-param");t.actionByKey(n,r,e)}),t.triggerChange=function(r){var i=e.getSelectedDate(t.dateStart,t.dateEnd,t.isDisabledDate,t.maxRange);t.mdOnSelect&&t.mdOnSelect({$dates:i})}}};return t}function r(e,t){function o(){var n=0,r;if(e.customTemplates!=null)for(var s=0;s0){if(e.maxRange&&Math.abs(Math.ceil(s/864e5))+1<=e.maxRange||!e.maxRange)e.dateEnd=n,i=!0,r=!0}else if(e.maxRange&&Math.abs(Math.ceil(s/864e5))+1<=e.maxRange||!e.maxRange)e.dateStart=n,i=!0,r=!0}}else if(!e.isDisabledDate||!e.isDisabledDate({$date:n}))e.dateStart=n,e.dateEnd=n,r=!0;return r&&(e.selectedTemplate=!1,e.selectedTemplateName=e.selectedDateText()),i}function m(t){return e.dateStart&&e.dateEnd?c(e.dateStart,t)>=0&&0<=c(t,e.dateEnd):!1}function g(t){var n=new Date(e.activeYear,e.activeMonth,1),r=new Date(e.activeYear2,e.activeMonth2,1);t?(n=new Date(e.activeYear2,e.activeMonth2-1,1),e.activeYear=n.getFullYear(),e.activeMonth=n.getMonth()):(r=new Date(e.activeYear,e.activeMonth+1,1),e.activeYear2=r.getFullYear(),e.activeMonth2=r.getMonth()),e.focusToDate(n)}function y(t){var n=new Date(e.activeDate.getFullYear(),e.activeDate.getMonth()+1,1);e.focusToDate(n)}function b(t){var n=new Date(e.activeDate.getFullYear(),e.activeDate.getMonth()-1,1);e.focusToDate(n)}function w(){var t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate());e.dateStart=n,e.dateEnd=n,e.selectedTemplate="TD",e.selectedTemplateName=e.selectedDateText()}function E(){var t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()-1);e.dateStart=n,e.dateEnd=n,e.selectedTemplate="YD",e.selectedTemplateName=e.selectedDateText()}function S(){var t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()),r=new Date(n.getFullYear(),n.getMonth(),n.getDate()-(n.getDay()-f())),i=new Date(n.getFullYear(),n.getMonth(),n.getDate()+(6-n.getDay()+f()));e.dateStart=r,e.dateEnd=i,e.selectedTemplate="TW",e.selectedTemplateName=e.selectedDateText()}function x(){var t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()-7),r=new Date(n.getFullYear(),n.getMonth(),n.getDate()-(n.getDay()-f())),i=new Date(n.getFullYear(),n.getMonth(),n.getDate()+(6-n.getDay()+f()));e.dateStart=r,e.dateEnd=i,e.selectedTemplate="LW",e.selectedTemplateName=e.selectedDateText()}function T(){var t=new Date,n=new Date(t.getFullYear(),t.getMonth(),1),r=new Date(t.getFullYear(),t.getMonth()+1,0);e.dateStart=n,e.dateEnd=r,e.selectedTemplate="TM",e.selectedTemplateName=e.selectedDateText()}function N(){var t=new Date,n=new Date(t.getFullYear(),t.getMonth(),0),r=new Date(n.getFullYear(),n.getMonth(),1),i=new Date(n.getFullYear(),n.getMonth()+1,0);e.dateStart=r,e.dateEnd=i,e.selectedTemplate="LM",e.selectedTemplateName=e.selectedDateText()}function C(){var t=new Date,n=new Date(t.getFullYear(),0,1),r=new Date(t.getFullYear(),11,31);e.dateStart=n,e.dateEnd=r,e.selectedTemplate="TY",e.selectedTemplateName=e.selectedDateText()}function k(){var t=new Date,n=new Date(t.getFullYear()-1,0,1),r=new Date(t.getFullYear()-1,11,31);e.dateStart=n,e.dateEnd=r,e.selectedTemplate="LY",e.selectedTemplateName=e.selectedDateText()}function L(t){return c(e.dateStart,t)===0}function A(t){return c(e.dateEnd,t)===0}function O(e){return c(e,new Date)===0}function M(){return e.format&&typeof e.format=="function"?e.format(e.dateStart,e.dateEnd,e.selectedTemplate,e.selectedTemplateName):!e.dateStart||!e.dateEnd?"":e.selectedTemplate?SELECTION_TEMPLATES_CUSTOM!=null&&SELECTION_TEMPLATES_CUSTOM[e.selectedTemplate]!=null?SELECTION_TEMPLATES_CUSTOM[e.selectedTemplate].name:i[e.selectedTemplate]:c(e.dateStart,e.dateEnd)===0?t("date")(e.dateStart,"dd MMM yyyy"):t("date")(e.dateStart,"dd"+(e.dateStart.getMonth()!==e.dateEnd.getMonth()||e.dateStart.getFullYear()!==e.dateEnd.getFullYear()?" MMM":"")+(e.dateStart.getFullYear()!==e.dateEnd.getFullYear()?" yyyy":""))+" - "+t("date")(e.dateEnd,"dd MMM yyyy")}function _(t){var n=new Date(t.getFullYear(),t.getMonth()+1,1);e.activeDate=t,e.activeMonth=t.getMonth(),e.activeYear=t.getFullYear(),e.activeDate2=n,e.activeMonth2=n.getMonth(),e.activeYear2=n.getFullYear(),e.dates=l(t),e.dates2=l(n)}var n=e,r=2,i={TD:a("Today"),YD:a("Yesterday"),TW:a("This Week"),LW:a("Last Week"),TM:a("This Month"),LM:a("Last Month"),TY:a("This Year"),LY:a("Last Year")},s=1;SELECTION_TEMPLATES_CUSTOM={},e.isMenuContainer=!1,e.days=[],e.label="Date range picker",e.dates=[],e.dates2=[],e.numberOfMonthToDisplay=2,e.today=new Date,e.dateStart&&e.dateStart.setHours(0,0,0,0),e.dateEnd&&e.dateEnd.setHours(23,59,59,999),e.firstDayOfMonth=e.dateStart?new Date(e.dateStart.getFullYear(),e.dateStart.getMonth(),1):Date(e.today.getFullYear(),e.today.getMonth(),1),e.lastDayOfMonth=e.dateStart?new Date(e.dateStart.getFullYear(),e.dateStart.getMonth()+1,0):Date(e.today.getFullYear(),e.today.getMonth()+1,0),e.activeDate=e.dateStart||e.today,e.activeDate2=new Date(e.activeDate.getFullYear(),e.activeDate.getMonth()+1,1),e.activeMonth=e.activeDate.getMonth(),e.activeYear=e.activeDate.getFullYear(),e.activeMonth2=e.activeDate2.getMonth(),e.activeYear2=e.activeDate2.getFullYear(),e.months=[],e.years=[],e.inCurrentMonth=p,e.isToday=O,e.handleClickDate=v,e.inSelectedDateRange=m,e.isSelectedStartDate=L,e.isSelectedEndDate=A,e.updateActiveDate=g,e.selectedDateText=M,e.focusToDate=_,e.handleClickNextMonth=y,e.handleClickPrevMonth=b,e.handleClickSelectToday=w,e.handleClickSelectYesterday=E,e.handleClickSelectThisWeek=S,e.handleClickSelectLastWeek=x,e.handleClickSelectThisMonth=T,e.handleClickSelectLastMonth=N,e.handleClickSelectThisYear=C,e.handleClickSelectLastYear=k,e.getLocalizationVal=a,e.selectCustomRange=u,e.isInMaxRange=d,e.selectionTemplate={},o()}function i(){return{scope:{ngModel:"=ngModel",autoConfirm:"=autoConfirm",ngDisabled:"=ngDisabled",showTemplate:"=",placeholder:"@",isDisabledDate:"&",localizationMap:"=?",customTemplates:"=?",disableTemplates:"@",mdOnSelect:"&",onePanel:"=?",format:"=?",maxRange:"=?",firstDayOfWeek:"=?"},template:['',''," {{ngModel.selectedTemplateName || placeholder}}",' ',"",'',' {{ngModel.selectedTemplateName || placeholder}}',' ','

','{{getLocalizationVal("Clear")}}','{{getLocalizationVal("Ok")}}',"

","
","
"].join(""),controller:["$scope","$mdMenu",function(e,t){e.ok=function(r){e.mdOnSelect({$dates:r}),t.hide()},e.clear=function(){e.ngModel.selectedTemplateName="",e.ngModel.selectedTemplate=null,e.ngModel.dateStart=null,e.ngModel.dateEnd=null},e.getLocalizationVal=function(n){var r=null;return e.ngModel&&e.ngModel.localizationMap!=null&&e.ngModel.localizationMap[n]!=null?r=e.ngModel.localizationMap[n]:r=n,r}}]}}function s(e){function r(e,t,n,r){var i=[],s=t.getTime(),o=e,u=0,a=e.getFullYear(),f=e.getMonth(),l=e.getDate();while(o.getTime()<=s){n&&!n({$date:o})&&i.push(o),u++,o=new Date(a,f,l+u);if(u>(r||1e4))break}return i}function i(n){return e.show({locals:{mdDateRangePickerServiceModel:t.copy(n.model),mdDateRangePickerServiceConfig:t.copy(n)},controller:["$scope","mdDateRangePickerServiceModel","mdDateRangePickerServiceConfig",function(t,n,r){t.model=n||{},t.config=r||{},t.model.selectedTemplateName=t.model.selectedTemplateName||"",t.ok=function(){t.model.dateStart&&t.model.dateStart.setHours(0,0,0,0),t.model.dateEnd&&t.model.dateEnd.setHours(23,59,59,999),e.hide(t.model)},t.cancel=function(){e.cancel()},t.clear=function(){t.model.selectedTemplateName="",t.model.selectedTemplate=null,t.model.dateStart=null,t.model.dateEnd=null},t.handleOnSelect=function(e){typeof t.config.mdOnSelect=="function"&&t.config.mdOnSelect(e),t.config.autoConfirm&&t.ok()},t.getLocalizationVal=function(n){var r=null;return t.model&&t.model.localizationMap!=null&&t.model.localizationMap[n]!=null?r=t.model.localizationMap[n]:r=n,r},t.model.customTemplates&&console.warn("model.customTemplates will be removed from model on next rlease, please use root config e.g. $mdDateRangePicker.show({customTemplates}) instead"),t.model.localizationMap&&console.warn("model.localizationMap will be removed from model on next rlease, please use root config e.g. $mdDateRangePicker.show({localizationMap}) instead"),t.model.firstDayOfWeek&&console.warn("model.firstDayOfWeek will be removed from model on next rlease, please use root config e.g. $mdDateRangePicker.show({firstDayOfWeek}) instead"),t.model.showTemplate&&console.warn("model.showTemplate will be removed from model on next rlease, please use root config e.g. $mdDateRangePicker.show({showTemplate}) instead"),t.model.maxRange&&console.warn("model.maxRange will be removed from model on next rlease, please use root config e.g. $mdDateRangePicker.show({maxRange}) instead"),t.model.onePanel&&console.warn("model.onePanel will be removed from model on next rlease, please use root config e.g. $mdDateRangePicker.show({onePanel}) instead"),t.model.isDisabledDate&&console.warn("model.isDisabledDate({ $date: $date }) will be removed from model on next rlease, please use root config e.g. $mdDateRangePicker.show({isDisabledDate:($date)=>{}}) instead")}],template:['','','",'{{model.selectedTemplateName}}',"","","","","",'','{{getLocalizationVal("Cancel")}}','{{getLocalizationVal("Clear")}}','{{getLocalizationVal("Ok")}}',"",""].join(""),parent:t.element(document.body),multiple:n.multiple,targetEvent:n.targetEvent||document.body,clickOutsideToClose:!0,fullscreen:n.model.fullscreen})}var n=this;n.show=i,n.getSelectedDate=r}t.module("ngMaterialDateRangePicker",["ngMaterial"]).directive("mdDateRangePicker",n).directive("mdDateRange",i).controller("mdDateRangePickerCtrl",r).service("$mdDateRangePicker",s),n.$inject=["$mdDateRangePicker"],r.$inject=["$scope","$filter"],s.$inject=["$mdDialog"]})(window,angular)