/* eslint-disable no-prototype-builtins */
!(function (e, t) {
'object' == typeof exports && 'object' == typeof module
? (module.exports = t())
: 'function' == typeof define && define.amd
? define([], t)
: 'object' == typeof exports
? (exports.datepicker = t())
: (e.datepicker = t());
})(window, function () {
return (
(a = {}),
(r.m = n =
[
function (e, t, n) {
'use strict';
n.r(t);
var D = [],
w = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
b = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
],
g = { t: 'top', r: 'right', b: 'bottom', l: 'left', c: 'centered' };
function q() {}
var o = ['click', 'focusin', 'keydown', 'input'];
function a(t) {
o.forEach(function (e) {
t.addEventListener(e, t === document ? l : d);
});
}
function S(n) {
return Array.isArray(n)
? n.map(S)
: '[object Object]' === N(n)
? Object.keys(n).reduce(function (e, t) {
return (e[t] = S(n[t])), e;
}, {})
: n;
}
function M(e, t) {
var n,
a,
r = e.calendar.querySelector('.qs-overlay'),
i = r && !r.classList.contains('qs-hidden');
(t = t || new Date(e.currentYear, e.currentMonth)),
(e.calendar.innerHTML = [
((a = t),
[
'
',
'
',
'
',
'' +
e.months[a.getMonth()] +
'',
'' + a.getFullYear() + '',
'
',
'
',
'
',
].join('')),
(function (e, t, n) {
var a = t.currentMonth,
r = t.currentYear,
i = t.dateSelected,
o = t.maxDate,
s = t.minDate,
l = t.showAllDates,
d = t.days,
c = t.disabledDates,
u = t.startDay,
h = t.weekendIndices,
f = t.events,
v = t.getRange ? t.getRange() : {},
m = +v.start,
y = +v.end,
e = k(new Date(e).setDate(1)),
p = e.getDay() - u,
u = p < 0 ? 7 : 0;
e.setMonth(e.getMonth() + 1), e.setDate(0);
var w = e.getDate(),
D = [],
b = u + 7 * (((p + w) / 7) | 0);
b += (p + w) % 7 ? 7 : 0;
for (var g = 1; g <= b; g++) {
var q = (g - 1) % 7,
S = d[q],
M = g - (0 <= p ? p : 7 + p),
E = new Date(r, a, M),
x = f[+E],
C = M < 1 || w < M,
L = C ? (M < 1 ? -1 : 1) : 0,
Y = C && !l,
j = Y ? '' : E.getDate(),
P = +E == +i,
M = q === h[0] || q === h[1],
q = m != y,
S = 'qs-square ' + S;
x && !Y && (S += ' qs-event'),
C && (S += ' qs-outside-current-month'),
(!l && C) || (S += ' qs-num'),
P && (S += ' qs-active'),
(c[+E] ||
t.disabler(E) ||
(M && t.noWeekends) ||
(s && +E < +s) ||
(o && +o < +E)) &&
!Y &&
(S += ' qs-disabled'),
+k(new Date()) == +E && (S += ' qs-current'),
+E == m && y && q && (S += ' qs-range-start'),
m < +E && +E < y && (S += ' qs-range-middle'),
+E == y && m && q && (S += ' qs-range-end'),
Y && ((S += ' qs-empty'), (j = '')),
D.push(
'' +
j +
'
',
);
}
u = d
.map(function (e) {
return '' + e + '
';
})
.concat(D);
return (
u.unshift(
'',
),
u.push('
'),
u.join('')
);
})(t, e, i),
((n = i),
(a = (r = e).overlayPlaceholder),
(t = r.overlayButton),
[
'',
'
',
'
' +
r.overlayMonths
.map(function (e, t) {
return (
'
' +
e +
'
'
);
})
.join('') +
'
',
'
' + t + '
',
'
',
].join('')),
].join('')),
i &&
window.requestAnimationFrame(function () {
P(!0, e);
});
}
function E(e, t, n) {
var a = t.el,
r = t.calendar.querySelector('.qs-active'),
i = e.textContent,
o = t.sibling;
((a.disabled || a.readOnly) && t.respectDisabledReadOnly) ||
((t.dateSelected = n
? void 0
: new Date(t.currentYear, t.currentMonth, i)),
r && r.classList.remove('qs-active'),
n || e.classList.add('qs-active'),
x(a, t, n),
n || Y(t),
o &&
(s({ instance: t, deselect: n }),
t.first &&
!o.dateSelected &&
((o.currentYear = t.currentYear),
(o.currentMonth = t.currentMonth),
(o.currentMonthName = t.currentMonthName)),
M(t),
M(o)),
t.onSelect(t, n ? void 0 : new Date(t.dateSelected)));
}
function s(e) {
var t = e.instance.first ? e.instance : e.instance.sibling,
n = t.sibling;
t === e.instance
? e.deselect
? ((t.minDate = t.originalMinDate),
(n.minDate = n.originalMinDate))
: (n.minDate = t.dateSelected)
: e.deselect
? ((n.maxDate = n.originalMaxDate),
(t.maxDate = t.originalMaxDate))
: (t.maxDate = n.dateSelected);
}
function x(e, t, n) {
return (
!t.nonInput &&
(n
? (e.value = '')
: t.formatter !== q
? t.formatter(e, t.dateSelected, t)
: void (e.value = t.dateSelected.toDateString()))
);
}
function C(e, t, n, a) {
n || a
? (n && (t.currentYear = +n), a && (t.currentMonth = +a))
: ((t.currentMonth += e.contains('qs-right') ? 1 : -1),
12 === t.currentMonth
? ((t.currentMonth = 0), t.currentYear++)
: -1 === t.currentMonth &&
((t.currentMonth = 11), t.currentYear--)),
(t.currentMonthName = t.months[t.currentMonth]),
M(t),
t.onMonthChange(t);
}
function r(e) {
if (!e.noPosition) {
var t = e.position.top,
n = e.position.right;
if (e.position.centered)
return e.calendarContainer.classList.add('qs-centered');
var a = e.positionedEl.getBoundingClientRect(),
r = e.el.getBoundingClientRect(),
i = e.calendarContainer.getBoundingClientRect(),
t = r.top - a.top + (t ? -1 * i.height : r.height) + 'px',
i = r.left - a.left + (n ? r.width - i.width : 0) + 'px';
e.calendarContainer.style.setProperty('top', t),
e.calendarContainer.style.setProperty('left', i);
}
}
function L(e) {
return '[object Date]' === N(e) && 'Invalid Date' !== e.toString();
}
function k(e) {
if (L(e) || ('number' == typeof e && !isNaN(e))) {
e = new Date(+e);
return new Date(e.getFullYear(), e.getMonth(), e.getDate());
}
}
function Y(e) {
e.disabled ||
e.calendarContainer.classList.contains('qs-hidden') ||
e.alwaysShow ||
('overlay' !== e.defaultView && P(!0, e),
e.calendarContainer.classList.add('qs-hidden'),
e.onHide(e));
}
function j(e) {
e.disabled ||
(e.calendarContainer.classList.remove('qs-hidden'),
'overlay' === e.defaultView && P(!1, e),
r(e),
e.onShow(e));
}
function P(e, t) {
var n = t.calendar,
a = n.querySelector('.qs-overlay'),
r = a.querySelector('.qs-overlay-year'),
t = n.querySelector('.qs-controls'),
n = n.querySelector('.qs-squares');
e
? (a.classList.add('qs-hidden'),
t.classList.remove('qs-blur'),
n.classList.remove('qs-blur'),
(r.value = ''))
: (a.classList.remove('qs-hidden'),
t.classList.add('qs-blur'),
n.classList.add('qs-blur'),
r.focus());
}
function O(e, t, n, a) {
var r = isNaN(+new Date().setFullYear(t.value || void 0)),
i = r ? null : t.value;
13 === e.which || 13 === e.keyCode || 'click' === e.type
? a
? C(null, n, i, a)
: r || t.classList.contains('qs-disabled') || C(null, n, i)
: n.calendar.contains(t) &&
n.calendar
.querySelector('.qs-submit')
.classList[r ? 'add' : 'remove']('qs-disabled');
}
function N(e) {
return {}.toString.call(e);
}
function _(t) {
D.forEach(function (e) {
e !== t && Y(e);
});
}
function l(e) {
if (!e.__qs_shadow_dom) {
var t = e.which || e.keyCode,
n = e.type,
a = e.target,
r = a.classList,
i = D.filter(function (e) {
return e.calendar.contains(a) || e.el === a;
})[0],
o = i && i.calendar.contains(a);
if (!(i && i.isMobile && i.disableMobile))
if ('click' === n) {
if (!i) return D.forEach(Y);
if (!i.disabled) {
var s = i.calendar,
l = i.calendarContainer,
d = i.disableYearOverlay,
c = i.nonInput,
u = s.querySelector('.qs-overlay-year'),
h = !!s.querySelector('.qs-hidden'),
f = s.querySelector('.qs-month-year').contains(a),
s = a.dataset.monthNum;
if (i.noPosition && !o)
(l.classList.contains('qs-hidden') ? j : Y)(i);
else if (r.contains('qs-arrow')) C(r, i);
else if (f || r.contains('qs-close')) d || P(!h, i);
else if (s) O(e, u, i, s);
else if (!r.contains('qs-disabled'))
if (r.contains('qs-num')) {
var v = a.textContent,
h = +a.dataset.direction,
s = new Date(i.currentYear, i.currentMonth + h, v);
if (h) {
(i.currentYear = s.getFullYear()),
(i.currentMonth = s.getMonth()),
(i.currentMonthName = b[i.currentMonth]),
M(i);
for (
var m,
y = i.calendar.querySelectorAll(
'[data-direction="0"]',
),
p = 0;
!m;
) {
var w = y[p];
w.textContent === v && (m = w), p++;
}
a = m;
}
+s == +i.dateSelected
? E(a, i, !0)
: a.classList.contains('qs-disabled') || E(a, i);
} else
r.contains('qs-submit')
? O(e, u, i)
: c && a === i.el && (j(i), _(i));
}
} else
'focusin' === n && i
? (j(i), _(i))
: 'keydown' === n && 9 === t && i
? Y(i)
: 'keydown' === n && i && !i.disabled
? ((c = !i.calendar
.querySelector('.qs-overlay')
.classList.contains('qs-hidden')),
13 === t && c && o
? O(e, a, i)
: 27 === t && c && o && P(!0, i))
: 'input' === n &&
i &&
i.calendar.contains(a) &&
((n = i.calendar.querySelector('.qs-submit')),
(i = a.value
.split('')
.reduce(function (e, t) {
return e || '0' !== t
? e + (t.match(/[0-9]/) ? t : '')
: '';
}, '')
.slice(0, 4)),
(a.value = i),
n.classList[4 === i.length ? 'remove' : 'add'](
'qs-disabled',
));
}
}
function d(e) {
l(e), (e.__qs_shadow_dom = !0);
}
function c(t, n) {
o.forEach(function (e) {
t.removeEventListener(e, n);
});
}
function I() {
j(this);
}
function A() {
Y(this);
}
function R(e, t) {
var n = k(e),
a = this.currentYear,
r = this.currentMonth,
i = this.sibling;
if (null == e)
return (
(this.dateSelected = void 0),
x(this.el, this, !0),
i && (s({ instance: this, deselect: !0 }), M(i)),
M(this),
this
);
if (!L(e))
throw new Error('`setDate` needs a JavaScript Date object.');
if (this.disabledDates[+n] || n < this.minDate || n > this.maxDate)
throw new Error("You can't manually set a date that's disabled.");
(this.dateSelected = n),
t &&
((this.currentYear = n.getFullYear()),
(this.currentMonth = n.getMonth()),
(this.currentMonthName = this.months[n.getMonth()])),
x(this.el, this),
i && (s({ instance: this }), M(i));
i = a === n.getFullYear() && r === n.getMonth();
return i || t ? M(this, n) : i || M(this, new Date(a, r, 1)), this;
}
function F(e) {
return i(this, e, !0);
}
function B(e) {
return i(this, e);
}
function i(e, t, n) {
var a = e.dateSelected,
r = e.first,
i = e.sibling,
o = e.minDate,
s = e.maxDate,
l = k(t),
d = n ? 'Min' : 'Max';
function c() {
return 'original' + d + 'Date';
}
function u() {
return d.toLowerCase() + 'Date';
}
function h() {
return 'set' + d;
}
function f() {
throw new Error('Out-of-range date passed to ' + h());
}
if (null == t)
(e[c()] = void 0),
i
? ((i[c()] = void 0),
n
? ((r && !a) || (!r && !i.dateSelected)) &&
((e.minDate = void 0), (i.minDate = void 0))
: ((r && !i.dateSelected) || (!r && !a)) &&
((e.maxDate = void 0), (i.maxDate = void 0)))
: (e[u()] = void 0);
else {
if (!L(t)) throw new Error('Invalid date passed to ' + h());
i
? (((r && n && (a || s) < l) ||
(r && !n && l < (i.dateSelected || o)) ||
(!r && n && l > (i.dateSelected || s)) ||
(!r && !n && l < (a || o))) &&
f(),
(e[c()] = l),
(i[c()] = l),
((n && ((r && !a) || (!r && !i.dateSelected))) ||
(!n && ((r && !i.dateSelected) || (!r && !a)))) &&
((e[u()] = l), (i[u()] = l)))
: (((n && (a || s) < l) || (!n && l < (a || o))) && f(),
(e[u()] = l));
}
return i && M(i), M(e), e;
}
function V() {
var e = this.first ? this : this.sibling,
t = e.sibling;
return { start: e.dateSelected, end: t.dateSelected };
}
function T() {
var t = this.shadowDom,
n = this.positionedEl,
e = this.calendarContainer,
a = this.sibling,
r = this;
this.inlinePosition &&
(D.some(function (e) {
return e !== r && e.positionedEl === n;
}) ||
n.style.setProperty('position', null)),
e.remove(),
(D = D.filter(function (e) {
return e !== r;
})),
a && delete a.sibling,
D.length || c(document, l);
var i,
a = D.some(function (e) {
return e.shadowDom === t;
});
for (i in (t && !a && c(t, d), this)) delete this[i];
D.length ||
o.forEach(function (e) {
document.removeEventListener(e, l);
});
}
function H(e, t) {
e = new Date(e);
if (!L(e)) throw new Error('Invalid date passed to `navigate`');
(this.currentYear = e.getFullYear()),
(this.currentMonth = e.getMonth()),
M(this),
t && this.onMonthChange(this);
}
function J() {
var e = !this.calendarContainer.classList.contains('qs-hidden'),
t = !this.calendarContainer
.querySelector('.qs-overlay')
.classList.contains('qs-hidden');
e && P(t, this);
}
t.default = function (e, t) {
var n = (function (e, f) {
var t,
n,
a = (function () {
var r = S(
f || {
startDate: k(new Date()),
position: 'bl',
defaultView: 'calendar',
},
);
r.events &&
(r.events = r.events.reduce(function (e, t) {
if (!L(t))
throw new Error(
'"options.events" must only contain valid JavaScript Date objects.',
);
return (e[+k(t)] = !0), e;
}, {})),
['startDate', 'dateSelected', 'minDate', 'maxDate'].forEach(
function (e) {
var t = r[e];
if (t && !L(t))
throw new Error(
'"options.' +
e +
'" needs to be a valid JavaScript Date object.',
);
r[e] = k(t);
},
);
var t = r.position,
e = r.maxDate,
n = r.minDate,
a = r.dateSelected,
i = r.overlayPlaceholder,
o = r.overlayButton,
s = r.startDay,
l = r.id;
if (
((r.startDate = k(r.startDate || a || new Date())),
(r.disabledDates = (r.disabledDates || []).reduce(function (
e,
t,
) {
var n = +k(t);
if (!L(t))
throw new Error(
'You supplied an invalid date to "options.disabledDates".',
);
if (n == +k(a))
throw new Error(
'"disabledDates" cannot contain the same date as "dateSelected".',
);
return (e[n] = 1), e;
}, {})),
r.hasOwnProperty('id') && null == l)
)
throw new Error('`id` cannot be `null` or `undefined`');
if (null != l) {
var d = D.filter(function (e) {
return e.id === l;
});
if (1 < d.length)
throw new Error('Only two datepickers can share an id.');
d.length
? ((r.second = !0), (r.sibling = d[0]))
: (r.first = !0);
}
var c,
u = ['tr', 'tl', 'br', 'bl', 'c'].some(function (e) {
return t === e;
});
if (t && !u)
throw new Error(
'"options.position" must be one of the following: tl, tr, bl, br, or c.',
);
function h(e) {
throw new Error(
'"dateSelected" in options is ' +
(e ? 'less' : 'greater') +
' than "' +
(e || 'max') +
'Date".',
);
}
if (
((r.position =
((d = (c = t || 'bl')[1]),
((u = {})[g[c[0]]] = 1),
d && (u[g[d]] = 1),
u)),
e < n)
)
throw new Error(
'"maxDate" in options is less than "minDate".',
);
a && (a < n && h('min'), e < a && h()),
[
'onSelect',
'onShow',
'onHide',
'onMonthChange',
'formatter',
'disabler',
].forEach(function (e) {
'function' != typeof r[e] && (r[e] = q);
}),
[
'customDays',
'customMonths',
'customOverlayMonths',
].forEach(function (e, t) {
var n = r[e],
a = t ? 12 : 7;
if (n) {
if (
!Array.isArray(n) ||
n.length !== a ||
n.some(function (e) {
return 'string' != typeof e;
})
)
throw new Error(
'"' +
e +
'" must be an array with ' +
a +
' strings.',
);
r[t ? (t < 2 ? 'months' : 'overlayMonths') : 'days'] =
n;
}
}),
s && 0 < s && s < 7
? ((e = (n = (r.customDays || w).slice()).splice(0, s)),
(r.customDays = n.concat(e)),
(r.startDay = +s),
(r.weekendIndices = [n.length - 1, n.length]))
: ((r.startDay = 0), (r.weekendIndices = [6, 0])),
'string' != typeof i && delete r.overlayPlaceholder,
'string' != typeof o && delete r.overlayButton;
o = r.defaultView;
if (o && 'calendar' !== o && 'overlay' !== o)
throw new Error(
'options.defaultView must either be "calendar" or "overlay".',
);
return (r.defaultView = o || 'calendar'), r;
})(),
r = e;
if ('string' == typeof r)
r =
'#' === r[0]
? document.getElementById(r.slice(1))
: document.querySelector(r);
else {
if ('[object ShadowRoot]' === N(r))
throw new Error(
'Using a shadow DOM as your selector is not supported.',
);
for (var i, o = r.parentNode; !i; ) {
var s = N(o);
'[object HTMLDocument]' === s
? (i = !0)
: '[object ShadowRoot]' === s
? ((i = !0), (n = (t = o).host))
: (o = o.parentNode);
}
}
if (!r) throw new Error('No selector / element found.');
if (
D.some(function (e) {
return e.el === r;
})
)
throw new Error('A datepicker already exists on that element.');
var l = r === document.body,
d = t
? r.parentElement || t
: l
? document.body
: r.parentElement,
c = t ? r.parentElement || n : d,
u = document.createElement('div'),
h = document.createElement('div');
(u.className = 'qs-datepicker-container qs-hidden'),
(h.className = 'qs-datepicker');
var v,
m,
y,
p = {
shadowDom: t,
customElement: n,
positionedEl: c,
el: r,
parent: d,
nonInput: 'INPUT' !== r.nodeName,
noPosition: l,
position: !l && a.position,
startDate: a.startDate,
dateSelected: a.dateSelected,
disabledDates: a.disabledDates,
minDate: a.minDate,
maxDate: a.maxDate,
noWeekends: !!a.noWeekends,
weekendIndices: a.weekendIndices,
calendarContainer: u,
calendar: h,
currentMonth: (a.startDate || a.dateSelected).getMonth(),
currentMonthName: (a.months || b)[
(a.startDate || a.dateSelected).getMonth()
],
currentYear: (a.startDate || a.dateSelected).getFullYear(),
events: a.events || {},
defaultView: a.defaultView,
setDate: R,
remove: T,
setMin: F,
setMax: B,
show: I,
hide: A,
navigate: H,
toggleOverlay: J,
onSelect: a.onSelect,
onShow: a.onShow,
onHide: a.onHide,
onMonthChange: a.onMonthChange,
formatter: a.formatter,
disabler: a.disabler,
months: a.months || b,
days: a.customDays || w,
startDay: a.startDay,
overlayMonths:
a.overlayMonths ||
(a.months || b).map(function (e) {
return e.slice(0, 3);
}),
overlayPlaceholder: a.overlayPlaceholder || '4-digit year',
overlayButton: a.overlayButton || 'Submit',
disableYearOverlay: !!a.disableYearOverlay,
disableMobile: !!a.disableMobile,
isMobile: 'ontouchstart' in window,
alwaysShow: !!a.alwaysShow,
id: a.id,
showAllDates: !!a.showAllDates,
respectDisabledReadOnly: !!a.respectDisabledReadOnly,
first: a.first,
second: a.second,
};
a.sibling &&
((v = a.sibling),
(m = p),
(y = v.minDate || m.minDate),
(e = v.maxDate || m.maxDate),
((m.sibling = v).sibling = m),
(v.minDate = y),
(v.maxDate = e),
(m.minDate = y),
(m.maxDate = e),
(v.originalMinDate = y),
(v.originalMaxDate = e),
(m.originalMinDate = y),
(m.originalMaxDate = e),
(v.getRange = V),
(m.getRange = V)),
a.dateSelected && x(r, p);
a = getComputedStyle(c).position;
l ||
(a && 'static' !== a) ||
((p.inlinePosition = !0),
c.style.setProperty('position', 'relative'));
c = D.filter(function (e) {
return e.positionedEl === p.positionedEl;
});
return (
c.some(function (e) {
return e.inlinePosition;
}) &&
((p.inlinePosition = !0),
c.forEach(function (e) {
e.inlinePosition = !0;
})),
u.appendChild(h),
d.appendChild(u),
p.alwaysShow && j(p),
p
);
})(e, t);
return (
D.length || a(document),
n.shadowDom &&
(D.some(function (e) {
return e.shadowDom === n.shadowDom;
}) ||
a(n.shadowDom)),
D.push(n),
n.second &&
((t = n.sibling),
s({ instance: n, deselect: !n.dateSelected }),
s({ instance: t, deselect: !t.dateSelected }),
M(t)),
M(n, n.startDate || n.dateSelected),
n.alwaysShow && r(n),
n
);
};
},
]),
(r.c = a),
(r.d = function (e, t, n) {
r.o(e, t) || Object.defineProperty(e, t, { enumerable: !0, get: n });
}),
(r.r = function (e) {
'undefined' != typeof Symbol &&
Symbol.toStringTag &&
Object.defineProperty(e, Symbol.toStringTag, { value: 'Module' }),
Object.defineProperty(e, '__esModule', { value: !0 });
}),
(r.t = function (t, e) {
if ((1 & e && (t = r(t)), 8 & e)) return t;
if (4 & e && 'object' == typeof t && t && t.__esModule) return t;
var n = Object.create(null);
if (
(r.r(n),
Object.defineProperty(n, 'default', { enumerable: !0, value: t }),
2 & e && 'string' != typeof t)
)
for (var a in t)
r.d(
n,
a,
function (e) {
return t[e];
}.bind(null, a),
);
return n;
}),
(r.n = function (e) {
var t =
e && e.__esModule
? function () {
return e.default;
}
: function () {
return e;
};
return r.d(t, 'a', t), t;
}),
(r.o = function (e, t) {
return Object.prototype.hasOwnProperty.call(e, t);
}),
(r.p = ''),
r((r.s = 0)).default
);
function r(e) {
if (a[e]) return a[e].exports;
var t = (a[e] = { i: e, l: !1, exports: {} });
return n[e].call(t.exports, t, t.exports, r), (t.l = !0), t.exports;
}
var n, a;
});