!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.DateRangePicker={})}(this,function(e){"use strict";function t(){var e=new Date;return e.setHours(0,0,0,0),e}function n(e,t){return(e&&e.toDateString())===(t&&t.toDateString())}function a(e,t){return e=new Date(e),e.setDate(e.getDate()+t),e}function r(e,t,n){e=new Date(e);var a=e.getDate(),r=e.getMonth()+t;return e.setDate(1),e.setMonth(n?(12+r)%12:r),e.setDate(a),e.getDate()n?n:e}function d(e){e=e||{},e=h(l(),e);var n=u(e.parse);return e.lang=h(te,e.lang),e.parse=n,e.inRange=f(e),e.min=n(e.min||i(t(),-100)),e.max=n(e.max||i(t(),100)),e.hilightedDate=e.parse(e.hilightedDate),e}function l(){return{lang:te,mode:"dp-modal",hilightedDate:t(),format:function(e){return e.getMonth()+1+"/"+e.getDate()+"/"+e.getFullYear()},parse:function(e){var n=new Date(e);return isNaN(n)?t():n},dateClass:function(){},inRange:function(){return!0}}}function f(e){var t=e.inRange;return function(n,a){return t(n,a)&&e.min<=n&&e.max>=n}}function h(e,t){t=t||{};for(var n in t)e[n]=t[n];return e}function p(e,t,n){return t.addEventListener(e,n,!0),function(){t.removeEventListener(e,n,!0)}}function v(e){var a=e.opts,r=a.lang,i=e.state,o=r.days,c=a.dayOffset||0,u=i.selectedDate,s=i.hilightedDate,d=s.getMonth(),l=t().getTime();return'
Prev'+r.months[d]+''+s.getFullYear()+'Next
'+o.map(function(e,t){return''+o[(t+c)%o.length]+""}).join("")+C(s,c,function(t){var r=t.getMonth()!==d,i=!a.inRange(t),o=t.getTime()===l,c="dp-day";return c+=r?" dp-edge-day":"",c+=n(t,s)?" dp-current":"",c+=n(t,u)?" dp-selected":"",c+=i?" dp-day-disabled":"",c+=o?" dp-day-today":"",''+t.getDate()+""})+'
"}function g(e,t){var n=e.keyCode,r=n===ne.left?-1:n===ne.right?1:n===ne.up?-7:n===ne.down?7:0;n===ne.esc?t.close():r&&(e.preventDefault(),t.setState({hilightedDate:a(t.state.hilightedDate,r)}))}function m(e,n){n.setState({selectedDate:t()})}function D(e,t){t.setState({selectedDate:null})}function y(e,t){t.close()}function b(e,t){t.setState({view:"month"})}function w(e,t){t.setState({view:"year"})}function S(e,t){var n=t.state.hilightedDate;t.setState({hilightedDate:r(n,1)})}function j(e,t){var n=t.state.hilightedDate;t.setState({hilightedDate:r(n,-1)})}function x(e,t){t.setState({selectedDate:new Date(parseInt(e.target.getAttribute("data-date")))})}function C(e,t,n){var a="",r=new Date(e);r.setDate(1),r.setDate(1-r.getDay()+t),t&&r.getDate()===t+1&&r.setDate(t-6);for(var i=0;i<42;++i)a+=n(r),r.setDate(r.getDate()+1);return a}function F(e,t){t.setState({hilightedDate:c(t.state.hilightedDate,parseInt(e.target.getAttribute("data-month"))),view:"day"})}function T(e){var t=e.opts,n=t.lang,a=n.months,r=e.state.hilightedDate,i=r.getMonth();return'
'+a.map(function(e,t){var n="dp-month";return''+e+""}).join("")+"
"}function E(e,t){var n=e.keyCode,a=n===ne.left?-1:n===ne.right?1:n===ne.up?-3:n===ne.down?3:0;n===ne.esc?t.setState({view:"day"}):a&&(e.preventDefault(),t.setState({hilightedDate:r(t.state.hilightedDate,a,!0)}))}function M(e){var t=e.state,n=t.hilightedDate.getFullYear(),a=t.selectedDate.getFullYear();return'
'+P(e,function(e){var t="dp-year";return t+=e===n?" dp-current":"",''+e+""})+"
"}function O(e,t){t.setState({hilightedDate:o(t.state.hilightedDate,parseInt(e.target.getAttribute("data-year"))),view:"day"})}function k(e,t){var n=e.keyCode,a=t.opts,r=n===ne.left||n===ne.up?1:n===ne.right||n===ne.down?-1:0;if(n===ne.esc)t.setState({view:"day"});else if(r){e.preventDefault();var o=i(t.state.hilightedDate,r);t.setState({hilightedDate:s(o,a.min,a.max)})}}function P(e,t){for(var n="",a=e.opts.max.getFullYear(),r=a;r>=e.opts.min.getFullYear();--r)n+=t(r);return n}function R(e,t){var n=void 0;return function(){clearTimeout(n),n=setTimeout(t,e)}}function H(){}function L(e,t,n){var a,r,i=!1,o={el:void 0,opts:n,shouldFocusOnBlur:!0,shouldFocusOnRender:!0,state:function(){return{get selectedDate(){return r},set selectedDate(e){e&&!n.inRange(e)||(e?(r=new Date(e),o.state.hilightedDate=r):r=e,o.updateInput(r),t("select"),o.close())},view:"day"}}(),adjustPosition:H,containerHTML:'
',attachToDom:function(){document.body.appendChild(o.el)},updateInput:function(t){var a=new ae("change",{bubbles:!0});a.simulated=!0,e.value=t?n.format(t):"",e.dispatchEvent(a)},computeSelectedDate:function(){return n.parse(e.value)},currentView:function(){return ce[o.state.view]},open:function(){i||(o.el||(o.el=N(n,o.containerHTML),I(o)),r=s(o.computeSelectedDate(),n.min,n.max),o.state.hilightedDate=r||n.hilightedDate,o.state.view="day",o.attachToDom(),o.render(),t("open"))},isVisible:function(){return!!o.el&&!!o.el.parentNode},hasFocus:function(){return o.el&&o.el.contains(document.activeElement)},shouldHide:function(){return o.isVisible()},close:function(n){var a=o.el;if(o.isVisible()){if(a){var r=a.parentNode;r&&r.removeChild(a)}i=!0,n&&o.shouldFocusOnBlur&&V(e),setTimeout(function(){i=!1},100),t("close")}},destroy:function(){o.close(),a()},render:function(){if(o.el){var e=o.hasFocus(),t=o.currentView().render(o);t&&(o.el.firstChild.innerHTML=t),o.adjustPosition(),(e||o.shouldFocusOnRender)&&q(o)}},setState:function(e){for(var n in e)o.state[n]=e[n];t("statechange"),o.render()}};return a=Y(e,o),o}function N(e,t){var n=document.createElement("div");return n.className=e.mode,n.innerHTML=t,n}function Y(e,t){var n=R(5,function(){t.shouldHide()?t.close():t.open()}),a=[p("blur",e,R(5,function(){t.hasFocus()||t.close(!0)})),p("mousedown",e,function(){e===document.activeElement&&n()}),p("focus",e,n),p("input",e,function(e){var n=t.opts.parse(e.target.value);isNaN(n)||t.setState({hilightedDate:n})})];return function(){a.forEach(function(e){e()})}}function q(e){var t=e.el.querySelector(".dp-current");return t&&t.focus()}function I(e){function t(t){t.target.className.split(" ").forEach(function(n){var a=e.currentView().onClick[n];a&&a(t,e)})}var n=e.el,a=n.querySelector(".dp");p("blur",a,R(10,function(){a.contains(document.activeElement)||e.close(!0)})),p("keydown",n,function(n){n.keyCode===ne.enter?t(n):e.currentView().onKeyDown(n,e)}),p("mousedown",a,function(t){document.activeElement!==t.target&&(t.preventDefault(),q(e))}),p("click",n,t)}function V(e){e.focus(),/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream&&e.blur()}function A(e,t,n){var a=L(e,t,n);return e.readonly=!0,a.containerHTML+='.',a}function B(e,t,n){var a=L(e,t,n);return a.shouldFocusOnBlur=!1,Object.defineProperty(a,"shouldFocusOnRender",{get:function(){return e!==document.activeElement}}),a.adjustPosition=function(){K(e,a)},a}function K(e,t){var n=e.getBoundingClientRect(),a=document.documentElement;W(t,n,a),J(t,n,a),t.el.style.visibility=""}function J(e,t,n){var a=e.el,r=n.scrollLeft,i=t.left+r,o=n.clientWidth+r,c=a.offsetWidth,u=i+c,s=o-c,d=u>o&&s>0?s:i;a.style.left=d+"px"}function W(e,t,n){var a=e.el,r=n.scrollTop,i=r+t.top,o=a.offsetHeight,c=i+t.height+8,u=i-o-8,s=u>0&&c+o>r+n.clientHeight?u:c;a.style.top=s+"px"}function _(e,t,n){var a=L(e,t,n);return a.close=H,a.destroy=H,a.updateInput=H,a.shouldFocusOnRender=!1,a.computeSelectedDate=function(){return n.hilightedDate},a.attachToDom=function(){e.appendChild(a.el)},a.open(),a}function z(e,t,n){return e=e&&e.tagName?e:document.querySelector(e),"dp-modal"===n.mode?A(e,t,n):"dp-below"===n.mode?B(e,t,n):"dp-permanent"===n.mode?_(e,t,n):void 0}function G(){function e(e,t){(n[e]=n[e]||[]).push(t)}function t(t){for(var n in t)e(n,t[n])}var n={};return{on:function(n,a){return a?e(n,a):t(n),this},emit:function(e,t){(n[e]||[]).forEach(function(n){n(e,t)})},off:function(e,t){return e?n[e]=t?(n[e]||[]).filter(function(e){return e!==t}):[]:n={},this}}}function Q(e,t){function n(e){a.emit(e,o)}var a=G(),r=d(t),i=z(e,n,r),o={get state(){return i.state},on:a.on,off:a.off,setState:i.setState,open:i.open,close:i.close,destroy:i.destroy};return o}function U(e){function t(e,t){1!==$(f.state.hilightedDate,h.state.hilightedDate)&&(t===f?h.setState({hilightedDate:r(t.state.hilightedDate,1)}):f.setState({hilightedDate:r(t.state.hilightedDate,-1)}))}function a(e,t){var n=t.state.selectedDate;i(!l.start||l.end?{start:n,end:void 0}:{start:n>l.start?l.start:n,end:n>l.start?n:l.start})}function i(e){for(var t in e)l[t]=e[t];s.emit("statechange",v),o()}function o(){f.setState({}),h.setState({})}function c(e){const t=u&&l.start&&ee(e,l.end||u,l.start),a=n(e,l.start)||n(e,l.end);return(t?"dr-in-range ":"")+(a?"dr-selected ":"")}var u,s=G(),d=X(e),l={start:void 0,end:void 0},f=Q(d.querySelector(".dr-cal-start"),{mode:"dp-permanent",dateClass:c}),h=Q(d.querySelector(".dr-cal-end"),{mode:"dp-permanent",hilightedDate:r(f.state.hilightedDate,1),dateClass:c}),p={statechange:t,select:a},v={state:l,on:s.on,off:s.off};return f.on(p),h.on(p),d.addEventListener("mouseover",function(e){if(e.target.classList.contains("dp-day")){const t=new Date(parseInt(e.target.dataset.date));!n(t,u)&&(u=t,o())}}),v}function X(e){return"string"==typeof e&&(e=document.querySelector(e)),e.innerHTML='
',e.querySelector(".dr-cals")}function Z(e){return 12*e.getYear()+e.getMonth()}function $(e,t){return Z(t)-Z(e)}function ee(e,t,n){return e=t||e<=t&&e>n}var te={days:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],today:"Today",clear:"Clear",close:"Close"},ne={left:37,up:38,right:39,down:40,enter:13,esc:27},ae=function(){var e=window.CustomEvent;return"function"!=typeof e&&(e=function(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n},e.prototype=window.Event.prototype),e}(),re={onKeyDown:g,onClick:{"dp-day":x,"dp-next":S,"dp-prev":j,"dp-today":m,"dp-clear":D,"dp-close":y,"dp-cal-month":b,"dp-cal-year":w},render:v},ie={onKeyDown:E,onClick:{"dp-month":F},render:T},oe={render:M,onKeyDown:k,onClick:{"dp-year":O}},ce={day:re,year:oe,month:ie};const ue=Q;e.TinyDatePicker=ue,e.DateRangePicker=U,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=dist/date-range-picker.min.js.map