!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.DateRangePicker={})}(this,function(t){"use strict";function o(){var t=new Date;return t.setHours(0,0,0,0),t}function h(t,e){return(t&&t.toDateString())===(e&&e.toDateString())}function v(t,e,n){var a=(t=new Date(t)).getDate(),o=t.getMonth()+e;return t.setDate(1),t.setMonth(n?(12+o)%12:o),t.setDate(a),t.getDate()=t}),t.min=e(t.min||i(o(),-100)),t.max=e(t.max||i(o(),100)),t.hilightedDate=t.parse(t.hilightedDate),t}var m={left:37,up:38,right:39,down:40,enter:13,esc:27};function D(t,e,n){return e.addEventListener(t,n,!0),function(){e.removeEventListener(t,n,!0)}}var y=function(){var t=window.CustomEvent;"function"!=typeof t&&((t=function(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),n}).prototype=window.Event.prototype);return t}();var b={day:{onKeyDown:function(t,e){var n=t.keyCode,a=n===m.left?-1:n===m.right?1:n===m.up?-7:n===m.down?7:0;n===m.esc?e.close():a&&(t.preventDefault(),e.setState({hilightedDate:(o=e.state.hilightedDate,r=a,(o=new Date(o)).setDate(o.getDate()+r),o)}));var o,r},onClick:{"dp-day":function(t,e){e.setState({selectedDate:new Date(parseInt(t.target.getAttribute("data-date")))})},"dp-next":function(t,e){var n=e.state.hilightedDate;e.setState({hilightedDate:v(n,1)})},"dp-prev":function(t,e){var n=e.state.hilightedDate;e.setState({hilightedDate:v(n,-1)})},"dp-today":function(t,e){e.setState({selectedDate:o()})},"dp-clear":function(t,e){e.setState({selectedDate:null})},"dp-close":function(t,e){e.close()},"dp-cal-month":function(t,e){e.setState({view:"month"})},"dp-cal-year":function(t,e){e.setState({view:"year"})}},render:function(r){var i=r.opts,t=i.lang,e=r.state,n=t.days,a=i.dayOffset||0,s=e.selectedDate,u=e.hilightedDate,d=u.getMonth(),c=o().getTime();return''+n.map(function(t,e){return'"}).join("")+function(t,e,n){var a="",o=new Date(t);o.setDate(1),o.setDate(1-o.getDay()+e),e&&o.getDate()===e+1&&o.setDate(e-6);for(var r=0;r<42;++r)a+=n(o),o.setDate(o.getDate()+1);return a}(u,a,function(t){var e=t.getMonth()!==d,n=!i.inRange(t),a=t.getTime()===c,o="dp-day";return o+=e?" dp-edge-day":"",o+=h(t,u)?" dp-current":"",o+=h(t,s)?" dp-selected":"",o+=n?" dp-day-disabled":"",o+=a?" dp-day-today":"",'"})+'
"}},year:{render:function(t){var e=t.state,n=e.hilightedDate.getFullYear(),a=e.selectedDate.getFullYear();return''+function(t,e){for(var n="",a=t.opts.max.getFullYear();a>=t.opts.min.getFullYear();--a)n+=e(a);return n}(t,function(t){var e="dp-year";return e+=t===n?" dp-current":"",'"})+"
"},onKeyDown:function(t,e){var n=t.keyCode,a=e.opts,o=n===m.left||n===m.up?1:n===m.right||n===m.down?-1:0;if(n===m.esc)e.setState({view:"day"});else if(o){t.preventDefault();var r=i(e.state.hilightedDate,o);e.setState({hilightedDate:l(r,a.min,a.max)})}},onClick:{"dp-year":function(t,e){e.setState({hilightedDate:(n=e.state.hilightedDate,a=parseInt(t.target.getAttribute("data-year")),(n=new Date(n)).setFullYear(a),n),view:"day"});var n,a}}},month:{onKeyDown:function(t,e){var n=t.keyCode,a=n===m.left?-1:n===m.right?1:n===m.up?-3:n===m.down?3:0;n===m.esc?e.setState({view:"day"}):a&&(t.preventDefault(),e.setState({hilightedDate:v(e.state.hilightedDate,a,!0)}))},onClick:{"dp-month":function(t,e){e.setState({hilightedDate:(n=e.state.hilightedDate,a=parseInt(t.target.getAttribute("data-month")),v(n,a-n.getMonth())),view:"day"});var n,a}},render:function(t){var e=t.opts.lang.months,a=t.state.hilightedDate.getMonth();return''+e.map(function(t,e){var n="dp-month";return'"}).join("")+"
"}}};function d(o,r,a){var t,i,e,n,s,u,d=!1,c={el:void 0,opts:a,shouldFocusOnBlur:!0,shouldFocusOnRender:!0,state:{get selectedDate(){return i},set selectedDate(t){t&&!a.inRange(t)||(t?(i=new Date(t),c.state.hilightedDate=i):i=t,c.updateInput(i),r("select"),c.close())},view:"day"},adjustPosition:p,containerHTML:'',attachToDom:function(){document.body.appendChild(c.el)},updateInput:function(t){var e=new y("change",{bubbles:!0});e.simulated=!0,o.value=t?a.format(t):"",o.dispatchEvent(e)},computeSelectedDate:function(){return a.parse(o.value)},currentView:function(){return b[c.state.view]},open:function(){var t,e,n;d||(c.el||(c.el=(t=a,e=c.containerHTML,(n=document.createElement("div")).className=t.mode,n.innerHTML=e,n),function(a){var t=a.el,e=t.querySelector(".dp");function n(n){n.target.className.split(" ").forEach(function(t){var e=a.currentView().onClick[t];e&&e(n,a)})}t.ontouchstart=p,D("blur",e,f(150,function(){a.hasFocus()||a.close(!0)})),D("keydown",t,function(t){t.keyCode===m.enter?n(t):a.currentView().onKeyDown(t,a)}),D("mousedown",e,function(t){t.target.focus&&t.target.focus(),document.activeElement!==t.target&&(t.preventDefault(),w(a))}),D("click",t,n)}(c)),i=l(c.computeSelectedDate(),a.min,a.max),c.state.hilightedDate=i||a.hilightedDate,c.state.view="day",c.attachToDom(),c.render(),r("open"))},isVisible:function(){return!!c.el&&!!c.el.parentNode},hasFocus:function(){var t=document.activeElement;return c.el&&c.el.contains(t)&&t.className.indexOf("dp-focuser")<0},shouldHide:function(){return c.isVisible()},close:function(t){var e=c.el;if(c.isVisible()){if(e){var n=e.parentNode;n&&n.removeChild(e)}var a;d=!0,t&&c.shouldFocusOnBlur&&((a=o).focus(),/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream&&a.blur()),setTimeout(function(){d=!1},100),r("close")}},destroy:function(){c.close(),t()},render:function(){if(c.el){var t=c.hasFocus(),e=c.currentView().render(c);e&&(c.el.firstChild.innerHTML=e),c.adjustPosition(),(t||c.shouldFocusOnRender)&&w(c)}},setState:function(t){for(var e in t)c.state[e]=t[e];r("statechange"),c.render()}};return e=o,n=c,s=f(5,function(){n.shouldHide()?n.close():n.open()}),u=[D("blur",e,f(150,function(){n.hasFocus()||n.close(!0)})),D("mousedown",e,function(){e===document.activeElement&&s()}),D("focus",e,s),D("input",e,function(t){var e=n.opts.parse(t.target.value);isNaN(e)||n.setState({hilightedDate:e})})],t=function(){u.forEach(function(t){t()})},c}function w(t){var e=t.el.querySelector(".dp-current");return e&&e.focus()}function c(S,t,e){var x=d(S,t,e);return x.shouldFocusOnBlur=!1,Object.defineProperty(x,"shouldFocusOnRender",{get:function(){return S!==document.activeElement}}),x.adjustPosition=function(){var t,e,n,a,o,r,i,s,u,d,c,l,f,p,h,v,g,m,D,y,b,w;c=x,l=S.getBoundingClientRect(),f=window,t=l,e=f,n=c.el,a=e.pageYOffset,o=a+t.top,r=n.offsetHeight,i=o+t.height+8,u=0<(s=o-r-8)&&i+r>a+e.innerHeight,d=u?s:i,n.classList&&(n.classList.toggle("dp-is-above",u),n.classList.toggle("dp-is-below",!u)),n.style.top=d+"px",p=l,h=f,v=c.el,g=h.pageXOffset,m=p.left+g,D=h.innerWidth+g,y=v.offsetWidth,b=D-y,w=D.',o):"dp-below"===n.mode?c(t,e,n):"dp-permanent"===n.mode?((s=d(r=t,e,i=n)).close=p,s.destroy=p,s.updateInput=p,s.shouldFocusOnRender=i.shouldFocusOnRender,s.computeSelectedDate=function(){return i.hilightedDate},s.attachToDom=function(){r.appendChild(s.el)},s.open(),s):void 0;var a,o,r,i,s}function x(){var a={};function n(t,e){(a[t]=a[t]||[]).push(e)}return{on:function(t,e){return e?n(t,e):function(t){for(var e in t)n(e,t[e])}(t),this},emit:function(e,n){(a[e]||[]).forEach(function(t){t(e,n)})},off:function(t,e){return t?a[t]=e?(a[t]||[]).filter(function(t){return t!==e}):[]:a={},this}}}function F(t,e){var n=x(),a=S(t,function(t){n.emit(t,o)},u(e)),o={get state(){return a.state},on:n.on,off:n.off,setState:a.setState,open:a.open,close:a.close,destroy:a.destroy};return o}var e=F;function C(t){return 12*t.getYear()+t.getMonth()}t.TinyDatePicker=e,t.DateRangePicker=function(t,e){e=e||{};var o,n=x(),a=(c=t,"string"==typeof c&&(c=document.querySelector(c)),c.innerHTML='
',c.querySelector(".dr-cals")),r={start:void 0,end:void 0},i=F(a.querySelector(".dr-cal-start"),g({},e.startOpts,{mode:"dp-permanent",dateClass:p})),s=F(a.querySelector(".dr-cal-end"),g({},e.endOpts,{mode:"dp-permanent",hilightedDate:v(i.state.hilightedDate,1),dateClass:p})),u={statechange:function(t,e){var n,a=i.state.hilightedDate,o=s.state.hilightedDate;1!=(n=a,C(o)-C(n))&&(e===i?s.setState({hilightedDate:v(e.state.hilightedDate,1)}):i.setState({hilightedDate:v(e.state.hilightedDate,-1)}))},select:function(t,e){var n=e.state.selectedDate;!r.start||r.end?l({start:n,end:void 0}):l({start:n>r.start?r.start:n,end:n>r.start?n:r.start})}},d={state:r,setState:l,on:n.on,off:n.off};var c;function l(t){for(var e in t)r[e]=t[e];n.emit("statechange",d),f()}function f(){i.setState({}),s.setState({})}function p(t){var e,n,a;return((r.end||o)&&r.start&&(e=t,n=r.end||o,a=r.start,e