<commit_before>/*! flatpickr v2.4.8, @license MIT */
function Flatpickr(element, config) {
	const self = this;

	self._ = {};

	self.changeMonth = changeMonth;
	self.changeYear = changeYear;
	self.clear = clear;
	self.close = close;
	self._createElement = createElement;
	self.destroy = destroy;
	self.isEnabled = isEnabled;
	self.jumpToDate = jumpToDate;
	self.open = open;
	self.redraw = redraw;
	self.set = set;
	self.setDate = setDate;
	self.toggle = toggle;

	function init() {
		if (element._flatpickr)
			destroy(element._flatpickr);

		element._flatpickr = self;

		self.element = element;
		self.instanceConfig = config || {};
		self.parseDate = Flatpickr.prototype.parseDate.bind(self);
		self.formatDate = Flatpickr.prototype.formatDate.bind(self);

		setupFormats();
		parseConfig();
		setupLocale();
		setupInputs();
		setupDates();
		setupHelperFunctions();

		self.isOpen = self.config.inline;

		self.isMobile = (
			!self.config.disableMobile &&
			!self.config.inline &&
			self.config.mode === "single" &&
			!self.config.disable.length &&
			!self.config.enable.length &&
			!self.config.weekNumbers &&
			/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
		);

		if (!self.isMobile)
			build();

		bind();

		if (self.selectedDates.length || self.config.noCalendar) {
			if (self.config.enableTime) {
				setHoursFromDate(self.config.noCalendar
					? self.latestSelectedDateObj || self.config.minDate
					: null);
			}
			updateValue();
		}

		if (self.config.weekNumbers) {
			self.calendarContainer.style.width = self.daysContainer.clientWidth
				+ self.weekWrapper.clientWidth + "px";
		}

		self.showTimeInput = self.selectedDates.length > 0 || self.config.noCalendar;

		if (!self.isMobile)
			positionCalendar();
		triggerEvent("Ready");
	}

	function bindToInstance(fn) {
		return fn.bind(self);
	}

	function updateTime(e) {
		if (self.config.noCalendar && !self.selectedDates.length)
			// picking time only
			self.selectedDates = [self.now];

		timeWrapper(e);

		if (!self.selectedDates.length)
			return;

		if (!self.minDateHasTime || e.type !== "input" || e.target.value.length >= 2) {
			setHoursFromInputs();
			updateValue();
		}

		else {
			setTimeout(function(){
				setHoursFromInputs();
				updateValue();
			}, 1000);
		}
	}

	function setHoursFromInputs(){
		if (!self.config.enableTime)
			return;

		let hours = (parseInt(self.hourElement.value, 10) || 0) % (self.amPM ? 12 : 24),
			minutes = (parseInt(self.minuteElement.value, 10) || 0) % 60,
			seconds = self.config.enableSeconds
				? (parseInt(self.secondElement.value, 10) || 0)
				: 0;

		if (self.amPM)
			hours = (hours % 12) + (12 * (self.amPM.textContent === "PM"));

		if (
			self.minDateHasTime
			&& compareDates(self.latestSelectedDateObj, self.config.minDate) === 0
		) {

			hours = Math.max(hours, self.config.minDate.getHours());
			if (hours === self.config.minDate.getHours())
				minutes = Math.max(minutes, self.config.minDate.getMinutes());
		}

		if (
			self.maxDateHasTime
			&& compareDates(self.latestSelectedDateObj, self.config.maxDate) === 0
		) {
			hours = Math.min(hours, self.config.maxDate.getHours());
			if (hours === self.config.maxDate.getHours())
				minutes = Math.min(minutes, self.config.maxDate.getMinutes());
		}

		setHours(hours, minutes, seconds);
	}

	function setHoursFromDate(dateObj){
		const date = dateObj || self.latestSelectedDateObj;

		if (date)
			setHours(date.getHours(), date.getMinutes(), date.getSeconds());
	}

	function setHours(hours, minutes, seconds) {
		if (self.selectedDates.length) {
			self.latestSelectedDateObj.setHours(
				hours % 24, minutes, seconds || 0, 0
			);
		}

		if (!self.config.enableTime || self.isMobile)
			return;

		self.hourElement.value = self.pad(
			!self.config.time_24hr ? (12 + hours) % 12 + 12 * (hours % 12 === 0) : hours
		);

		self.minuteElement.value = self.pad(minutes);

		if (!self.config.time_24hr)
			self.amPM.textContent = hours >= 12 ? "PM" : "AM";

		if (self.config.enableSeconds)
			self.secondElement.value = self.pad(seconds);
	}

	function onYearInput(event) {
		let year = event.target.value;
		if (event.delta)
			year = (parseInt(year) + event.delta).toString();

		if (year.length === 4) {
			self.currentYearElement.blur();
			if (!/[^\d]/.test(year))
				changeYear(year);
		}
	}

	function onMonthScroll(e) {
		e.preventDefault();
		self.changeMonth(Math.max(-1, Math.min(1, (e.wheelDelta || -e.deltaY))));
	}

	function bind() {
		if (self.config.wrap) {
			["open", "close", "toggle", "clear"].forEach(el => {
				const toggles = self.element.querySelectorAll(`[data-${el}]`);
				for (let i = 0; i < toggles.length; i++)
					toggles[i].addEventListener("click", self[el]);
			});
		}

		if (window.document.createEvent !== undefined) {
			self.changeEvent = window.document.createEvent("HTMLEvents");
			self.changeEvent.initEvent("change", false, true);
		}

		if (self.isMobile)
			return setupMobile();

		self.debouncedResize = debounce(onResize, 50);
		self.triggerChange = () => {
			triggerEvent("Change");
		};
		self.debouncedChange = debounce(self.triggerChange, 300);

		if (self.config.mode === "range" && self.daysContainer)
			self.daysContainer.addEventListener("mouseover", e => onMouseOver(e.target));

		document.body.addEventListener("keydown", onKeyDown);

		if (!self.config.static)
			(self.altInput || self.input).addEventListener("keydown", onKeyDown);

		if (!self.config.inline && !self.config.static)
			window.addEventListener("resize", self.debouncedResize);

		if (window.ontouchstart)
			window.document.addEventListener("touchstart", documentClick);

		window.document.addEventListener("click", documentClick);
		(self.altInput || self.input).addEventListener("blur", documentClick);

		if (self.config.clickOpens)
			(self.altInput || self.input).addEventListener("focus", open);

		if (!self.config.noCalendar) {
			self.prevMonthNav.addEventListener("click", () => changeMonth(-1));
			self.nextMonthNav.addEventListener("click", () => changeMonth(1));

			self.currentMonthElement.addEventListener("wheel", e => debounce(onMonthScroll(e), 50));
			self.currentYearElement.addEventListener("wheel", e => debounce(yearScroll(e), 50));
			self.currentYearElement.addEventListener("focus", () => {
				self.currentYearElement.select();
			});

			self.currentYearElement.addEventListener("input", onYearInput);
			self.currentYearElement.addEventListener("increment", onYearInput);

			self.daysContainer.addEventListener("click", selectDate);

			if (self.config.animate)
				self.daysContainer.addEventListener("animationend", animateDays);
		}

		if (self.config.enableTime) {
			self.timeContainer.addEventListener("transitionend", positionCalendar);
			self.timeContainer.addEventListener("wheel", e => debounce(updateTime(e), 5));
			self.timeContainer.addEventListener("input", updateTime);
			self.timeContainer.addEventListener("increment", updateTime);
			self.timeContainer.addEventListener("increment", self.debouncedChange);

			self.timeContainer.addEventListener("wheel", self.debouncedChange);
			self.timeContainer.addEventListener("input", self.triggerChange);

			self.hourElement.addEventListener("focus", () => {
				self.hourElement.select();
			});
			self.minuteElement.addEventListener("focus", () => {
				self.minuteElement.select();
			});

			if (self.secondElement) {
				self.secondElement.addEventListener("focus", () => {
					self.secondElement.select();
				});
			}

			if (self.amPM) {
				self.amPM.addEventListener("click", (e) => {
					updateTime(e);
					self.triggerChange(e);
				});
			}
		}
	}

	function animateDays (e) {
		if (self.daysContainer.childNodes.length > 1) {
			switch(e.animationName) {
				case "slideLeft":
					self.daysContainer.childNodes[1].classList.remove("slideLeftNew")
					self.daysContainer.removeChild(self.daysContainer.childNodes[0]);
					break;

				case "slideRight":
					self.daysContainer.childNodes[0].classList.remove("slideRightNew")
					self.daysContainer.removeChild(self.daysContainer.childNodes[1]);
					break;

				default: break;
			}
		}
	}

	function jumpToDate(jumpDate) {
		jumpDate = jumpDate
			? self.parseDate(jumpDate)
			: self.latestSelectedDateObj || (self.config.minDate > self.now
				? self.config.minDate
				: self.config.maxDate && self.config.maxDate < self.now
					? self.config.maxDate
					: self.now
			);

		try {
			self.currentYear = jumpDate.getFullYear();
			self.currentMonth = jumpDate.getMonth();
		}

		catch (e) {
			/* istanbul ignore next */
			console.error(e.stack);
			/* istanbul ignore next */
			console.warn("Invalid date supplied: " + jumpDate);
		}

		self.redraw();
	}

	function incrementNumInput(e, delta, inputElem) {
		const input = inputElem || e.target.parentNode.childNodes[0];
		let ev;

		try {
			ev = new Event("increment", { "bubbles": true });
		}

		catch (err) {
			ev = window.document.createEvent("CustomEvent");
			ev.initCustomEvent("increment", true, true, {});
		}

		ev.delta = delta;
		input.dispatchEvent(ev);
	}

	function createNumberInput(inputClassName) {
		const wrapper = createElement("div", "numInputWrapper"),
			numInput = createElement("input", "numInput " + inputClassName),
			arrowUp = createElement("span", "arrowUp"),
			arrowDown = createElement("span", "arrowDown");

		numInput.type = "text";
		numInput.pattern = "\\d*";
		wrapper.appendChild(numInput);
		wrapper.appendChild(arrowUp);
		wrapper.appendChild(arrowDown);

		arrowUp.addEventListener("click", e => incrementNumInput(e, 1));
		arrowDown.addEventListener("click", e => incrementNumInput(e, -1));
		return wrapper;
	}

	function build() {
		const fragment = window.document.createDocumentFragment();
		self.calendarContainer = createElement("div", "flatpickr-calendar");
		self.numInputType = navigator.userAgent.indexOf("MSIE 9.0") > 0 ? "text" : "number";

		if (!self.config.noCalendar) {
			fragment.appendChild(buildMonthNav());
			self.innerContainer = createElement("div", "flatpickr-innerContainer")

			if (self.config.weekNumbers)
				self.innerContainer.appendChild(buildWeeks());

			self.rContainer = createElement("div", "flatpickr-rContainer");
			self.rContainer.appendChild(buildWeekdays());

			if (!self.daysContainer) {
				self.daysContainer = createElement("div", "flatpickr-days");
				self.daysContainer.tabIndex = -1;
			}

			buildDays();
			self.rContainer.appendChild(self.daysContainer);

			self.innerContainer.appendChild(self.rContainer);
			fragment.appendChild(self.innerContainer);
		}

		if (self.config.enableTime)
			fragment.appendChild(buildTime());

		toggleClass(self.calendarContainer, "rangeMode", self.config.mode === "range");
		toggleClass(self.calendarContainer, "animate", self.config.animate);

		self.calendarContainer.appendChild(fragment);

		const customAppend = self.config.appendTo && self.config.appendTo.nodeType;

		if (self.config.inline || self.config.static) {
			self.calendarContainer.classList.add(self.config.inline ? "inline" : "static");


			if (self.config.inline && !customAppend) {
				return self.element.parentNode.insertBefore(
					self.calendarContainer,
					(self.altInput || self.input).nextSibling
				);
			}

			if (self.config.static){
				const wrapper = createElement("div", "flatpickr-wrapper");
				self.element.parentNode.insertBefore(wrapper, self.element);
				wrapper.appendChild(self.element);

				if(self.altInput)
					wrapper.appendChild(self.altInput);

				wrapper.appendChild(self.calendarContainer);
				return;
			}
		}

		(customAppend ? self.config.appendTo : window.document.body)
			.appendChild(self.calendarContainer);
	}

	function createDay(className, date, dayNumber, i) {
		const dateIsEnabled = isEnabled(date, true),
			dayElement = createElement(
				"span",
				"flatpickr-day " + className,
				date.getDate()
			);

		dayElement.dateObj = date;
		dayElement.$i = i;
		dayElement.setAttribute("aria-label", self.formatDate(date, "F j, Y"));

		if (compareDates(date, self.now) === 0) {
			self.todayDateElem = dayElement;
			dayElement.classList.add("today");
		}

		if (dateIsEnabled) {
			dayElement.tabIndex = -1;
			if (isDateSelected(date)){
				dayElement.classList.add("selected");
				self.selectedDateElem = dayElement;
				if (self.config.mode === "range") {
					toggleClass(
						dayElement,
						"startRange",
						compareDates(date, self.selectedDates[0]) === 0
					);

					toggleClass(
						dayElement,
						"endRange",
						compareDates(date, self.selectedDates[1]) === 0
					);
				}
			}
		}

		else {
			dayElement.classList.add("disabled");
			if (
				self.selectedDates[0]
				&& date > self.minRangeDate
				&& date < self.selectedDates[0]
			)

				self.minRangeDate = date;

			else if (
				self.selectedDates[0]
				&& date < self.maxRangeDate
				&& date > self.selectedDates[0]
			)
				self.maxRangeDate = date;
		}

		if (self.config.mode === "range") {
			if (isDateInRange(date) && !isDateSelected(date))
				dayElement.classList.add("inRange");

			if (
				self.selectedDates.length === 1 &&
				(date < self.minRangeDate || date > self.maxRangeDate)
			)
				dayElement.classList.add("notAllowed");
		}

		if (self.config.weekNumbers && className !== "prevMonthDay" && dayNumber % 7 === 1) {
			self.weekNumbers.insertAdjacentHTML(
				"beforeend",
				"<span class='disabled flatpickr-day'>" + self.config.getWeek(date) + "</span>"
			);
		}

		triggerEvent("DayCreate", dayElement);

		return dayElement;
	}

	function focusOnDay(currentIndex, offset) {
		let newIndex = currentIndex + offset || 0,
			targetNode = currentIndex !== undefined
				? self.days.childNodes[newIndex]
				: self.selectedDateElem || self.todayDateElem || self.days.childNodes[0];

		if (targetNode === undefined) {
			if (offset > 0) {
				self.changeMonth(1);
				targetNode = self.days.childNodes[newIndex % 42].focus();
			}

			else if (offset < 0) {
				self.changeMonth(-1);
				targetNode = self.days.childNodes[42 + newIndex].focus();
			}
		}

		targetNode.focus();

		if (self.config.mode === "range")
			onMouseOver(targetNode);
	}

	function buildDays(delta) {
		const firstOfMonth = (
				new Date(self.currentYear, self.currentMonth, 1).getDay() -
				self.l10n.firstDayOfWeek + 7
			) % 7,
			isRangeMode = self.config.mode === "range";

		self.prevMonthDays = self.utils.getDaysinMonth((self.currentMonth - 1 + 12) % 12);
		self.selectedDateElem = undefined;
		self.todayDateElem = undefined;

		const daysInMonth = self.utils.getDaysinMonth(),
			days = window.document.createDocumentFragment();

		let	dayNumber = self.prevMonthDays + 1 - firstOfMonth,
			dayIndex = 0;

		if (self.config.weekNumbers && self.weekNumbers.firstChild)
			self.weekNumbers.textContent = "";

		if (isRangeMode) {
			// const dateLimits = self.config.enable.length || self.config.disable.length || self.config.mixDate || self.config.maxDate;
			self.minRangeDate = new Date(self.currentYear, self.currentMonth - 1, dayNumber);
			self.maxRangeDate = new Date(
				self.currentYear,
				self.currentMonth + 1,
				(42 - firstOfMonth) % daysInMonth
			);
		}

		// prepend days from the ending of previous month
		for (; dayNumber <= self.prevMonthDays; dayNumber++, dayIndex++) {
			days.appendChild(
				createDay(
					"prevMonthDay",
					new Date(self.currentYear, self.currentMonth - 1, dayNumber),
					dayNumber,
					dayIndex
				)
			);
		}

		// Start at 1 since there is no 0th day
		for (dayNumber = 1; dayNumber <= daysInMonth; dayNumber++, dayIndex++) {
			days.appendChild(
				createDay(
					"",
					new Date(self.currentYear, self.currentMonth, dayNumber),
					dayNumber,
					dayIndex
				)
			);
		}

		// append days from the next month
		for (let dayNum = daysInMonth + 1; dayNum <= 42 - firstOfMonth; dayNum++, dayIndex++) {
			days.appendChild(
				createDay(
					"nextMonthDay",
					new Date(self.currentYear, self.currentMonth + 1, dayNum % daysInMonth),
					dayNum,
					dayIndex
				)
			);
		}

		if (isRangeMode && self.selectedDates.length === 1 && days.childNodes[0]) {
			self._hidePrevMonthArrow = self._hidePrevMonthArrow ||
				self.minRangeDate > days.childNodes[0].dateObj;

			self._hideNextMonthArrow = self._hideNextMonthArrow ||
				self.maxRangeDate < new Date(self.currentYear, self.currentMonth + 1, 1);
		}

		else
			updateNavigationCurrentMonth();

		const dayContainer = createElement("div", "dayContainer");
		dayContainer.appendChild(days);

		if (!self.config.animate || delta === undefined)
			clearNode(self.daysContainer);

		else
			while (self.daysContainer.childNodes.length > 1)
				self.daysContainer.removeChild(self.daysContainer.firstChild);

		if (delta >= 0)
			self.daysContainer.appendChild(dayContainer);
		else
			self.daysContainer.insertBefore(dayContainer, self.daysContainer.firstChild);

		self.days = self.daysContainer.firstChild;
		return self.daysContainer;
	}

	function clearNode(node) {
		while (node.firstChild)
			node.removeChild(node.firstChild);
	}

	function buildMonthNav() {
		const monthNavFragment = window.document.createDocumentFragment();
		self.monthNav = createElement("div", "flatpickr-month");

		self.prevMonthNav = createElement("span", "flatpickr-prev-month");
		self.prevMonthNav.innerHTML = self.config.prevArrow;

		self.currentMonthElement = createElement("span", "cur-month");
		self.currentMonthElement.title = self.l10n.scrollTitle;

		const yearInput = createNumberInput("cur-year");
		self.currentYearElement =  yearInput.childNodes[0];
		self.currentYearElement.title = self.l10n.scrollTitle;

		if (self.config.minDate)
			self.currentYearElement.min = self.config.minDate.getFullYear();

		if (self.config.maxDate) {
			self.currentYearElement.max = self.config.maxDate.getFullYear();

			self.currentYearElement.disabled = self.config.minDate	&&
				self.config.minDate.getFullYear() === self.config.maxDate.getFullYear();
		}

		self.nextMonthNav = createElement("span", "flatpickr-next-month");
		self.nextMonthNav.innerHTML = self.config.nextArrow;

		self.navigationCurrentMonth = createElement("span", "flatpickr-current-month");
		self.navigationCurrentMonth.appendChild(self.currentMonthElement);
		self.navigationCurrentMonth.appendChild(yearInput);

		monthNavFragment.appendChild(self.prevMonthNav);
		monthNavFragment.appendChild(self.navigationCurrentMonth);
		monthNavFragment.appendChild(self.nextMonthNav);
		self.monthNav.appendChild(monthNavFragment);

		Object.defineProperty(self, "_hidePrevMonthArrow", {
			get () {
				return this.__hidePrevMonthArrow;
			},
			set (bool) {
				if (this.__hidePrevMonthArrow !== bool)
					self.prevMonthNav.style.display = bool ? "none" : "block";
				this.__hidePrevMonthArrow = bool;
			}
		});

		Object.defineProperty(self, "_hideNextMonthArrow", {
			get () {
				return this.__hideNextMonthArrow;
			},
			set (bool) {
				if (this.__hideNextMonthArrow !== bool)
					self.nextMonthNav.style.display = bool ? "none" : "block";
				this.__hideNextMonthArrow = bool;
			}
		});

		updateNavigationCurrentMonth();

		return self.monthNav;
	}

	function buildTime() {
		self.calendarContainer.classList.add("hasTime");
		if (self.config.noCalendar)
			self.calendarContainer.classList.add("noCalendar");
		self.timeContainer = createElement("div", "flatpickr-time");
		self.timeContainer.tabIndex = -1;
		const separator = createElement("span", "flatpickr-time-separator", ":");

		const hourInput = createNumberInput("flatpickr-hour");
		self.hourElement =  hourInput.childNodes[0];

		const minuteInput = createNumberInput("flatpickr-minute");
		self.minuteElement =  minuteInput.childNodes[0];

		self.hourElement.tabIndex = self.minuteElement.tabIndex = -1;

		self.hourElement.value = self.pad(self.latestSelectedDateObj
			? self.latestSelectedDateObj.getHours()
			: self.config.defaultHour
		);

		self.minuteElement.value = self.pad(self.latestSelectedDateObj
			? self.latestSelectedDateObj.getMinutes()
			: self.config.defaultMinute
		);

		self.hourElement.step = self.config.hourIncrement;
		self.minuteElement.step = self.config.minuteIncrement;

		self.hourElement.min = self.config.time_24hr ? 0 : 1;
		self.hourElement.max = self.config.time_24hr ? 23 : 12;

		self.minuteElement.min = 0;
		self.minuteElement.max = 59;

		self.hourElement.title = self.minuteElement.title = self.l10n.scrollTitle;

		self.timeContainer.appendChild(hourInput);
		self.timeContainer.appendChild(separator);
		self.timeContainer.appendChild(minuteInput);

		if (self.config.time_24hr)
			self.timeContainer.classList.add("time24hr");

		if (self.config.enableSeconds) {
			self.timeContainer.classList.add("hasSeconds");

			const secondInput = createNumberInput("flatpickr-second");
			self.secondElement =  secondInput.childNodes[0];

			self.secondElement.value =
				self.latestSelectedDateObj ? self.pad(self.latestSelectedDateObj.getSeconds()) : "00";

			self.secondElement.step = self.minuteElement.step;
			self.secondElement.min = self.minuteElement.min;
			self.secondElement.max = self.minuteElement.max;

			self.timeContainer.appendChild(
				createElement("span", "flatpickr-time-separator", ":")
			);
			self.timeContainer.appendChild(secondInput);
		}

		if (!self.config.time_24hr) { // add self.amPM if appropriate
			self.amPM = createElement(
				"span",
				"flatpickr-am-pm",
				["AM", "PM"][(self.hourElement.value > 11) | 0]
			);
			self.amPM.title = self.l10n.toggleTitle;
			self.amPM.tabIndex = -1;
			self.timeContainer.appendChild(self.amPM);
		}

		return self.timeContainer;
	}

	function buildWeekdays() {
		if (!self.weekdayContainer)
			self.weekdayContainer = createElement("div", "flatpickr-weekdays");

		const firstDayOfWeek = self.l10n.firstDayOfWeek;
		let	weekdays = self.l10n.weekdays.shorthand.slice();

		if (firstDayOfWeek > 0 && firstDayOfWeek < weekdays.length) {
			weekdays = [].concat(
				weekdays.splice(firstDayOfWeek, weekdays.length),
				weekdays.splice(0, firstDayOfWeek)
			);
		}

		self.weekdayContainer.innerHTML = `
		<span class=flatpickr-weekday>
			${weekdays.join("</span><span class=flatpickr-weekday>")}
		</span>
		`;

		return self.weekdayContainer;
	}

	/* istanbul ignore next */
	function buildWeeks() {
		self.calendarContainer.classList.add("hasWeeks");
		self.weekWrapper = createElement("div", "flatpickr-weekwrapper");
		self.weekWrapper.appendChild(
			createElement("span", "flatpickr-weekday", self.l10n.weekAbbreviation)
		);
		self.weekNumbers = createElement("div", "flatpickr-weeks");
		self.weekWrapper.appendChild(self.weekNumbers);

		return self.weekWrapper;
	}

	function changeMonth(value, is_offset) {
		is_offset = typeof is_offset === "undefined" || is_offset;
		const delta = is_offset ? value : value - self.currentMonth;

		if (
			(delta < 0 && self._hidePrevMonthArrow) ||
			(delta > 0 && self._hideNextMonthArrow)
		)
			return;

		self.currentMonth += delta;

		if (self.currentMonth < 0 || self.currentMonth > 11) {
			self.currentYear += (self.currentMonth > 11 ? 1 : -1);
			self.currentMonth = (self.currentMonth + 12) % 12;

			triggerEvent("YearChange");
		}

		updateNavigationCurrentMonth();
		buildDays(delta);

		triggerEvent("MonthChange");

		if (!self.config.animate)
			return;

		if (delta > 0) {
			self.daysContainer.lastChild.classList.add("slideLeftNew");
			self.daysContainer.firstChild.classList.add("slideLeft");
		}

		else if (delta < 0) {
			self.daysContainer.lastChild.classList.add("slideRight");
			self.daysContainer.firstChild.classList.add("slideRightNew");
		}
	}

	function clear(triggerChangeEvent) {
		self.input.value = "";

		if (self.altInput)
			self.altInput.value = "";

		if (self.mobileInput)
			self.mobileInput.value = "";

		self.selectedDates = [];
		self.latestSelectedDateObj = null;
		self.showTimeInput = false;

		self.redraw();

		if (triggerChangeEvent !== false)
			// triggerChangeEvent is true (default) or an Event
			triggerEvent("Change");
	}

	function close() {
		self.isOpen = false;

		if (!self.isMobile) {
			self.calendarContainer.classList.remove("open");
			(self.altInput || self.input).classList.remove("active");
		}

		triggerEvent("Close");
	}

	function destroy(instance) {
		instance = instance || self;
		instance.clear(false);

		window.removeEventListener("resize", instance.debouncedResize);

		window.document.removeEventListener("click", documentClick);
		window.document.removeEventListener("touchstart", documentClick);
		window.document.removeEventListener("blur", documentClick);

		if (instance.timeContainer)
			instance.timeContainer.removeEventListener("transitionend", positionCalendar);

		if (instance.mobileInput) {
			if (instance.mobileInput.parentNode)
				instance.mobileInput.parentNode.removeChild(instance.mobileInput);
			delete instance.mobileInput;
		}

		else if (instance.calendarContainer && instance.calendarContainer.parentNode)
			instance.calendarContainer.parentNode.removeChild(instance.calendarContainer);

		if (instance.altInput) {
			instance.input.type = "text";
			if (instance.altInput.parentNode)
				instance.altInput.parentNode.removeChild(instance.altInput);
			delete instance.altInput;
		}

		instance.input.type = instance.input._type;
		instance.input.classList.remove("flatpickr-input");
		instance.input.removeEventListener("focus", open);
		instance.input.removeAttribute("readonly");

		delete instance.input._flatpickr;
	}

	function isCalendarElem(elem) {
		if (self.config.appendTo && self.config.appendTo.contains(elem))
			return true;

		return self.calendarContainer.contains(elem);
	}

	function documentClick(e) {
		if (self.isOpen && !self.config.inline) {
			const isCalendarElement = isCalendarElem(e.target);
			const isInput = e.target === self.input
				|| e.target === self.altInput
				|| self.element.contains(e.target)
				|| (
					// web components
					e.path && e.path.indexOf &&
					(~e.path.indexOf(self.input) || ~e.path.indexOf(self.altInput))
				);

			const lostFocus = e.type === "blur"
				? isInput && e.relatedTarget && !isCalendarElem(e.relatedTarget)
				: !isInput && !isCalendarElement;

			if(lostFocus) {
				e.preventDefault();
				self.close();

				if (self.config.mode === "range" && self.selectedDates.length === 1) {
					self.clear();
					self.redraw();
				}
			}
		}
	}

	function changeYear(newYear) {
		if (
			!newYear
			|| (self.currentYearElement.min && newYear < self.currentYearElement.min)
			|| (self.currentYearElement.max && newYear > self.currentYearElement.max)
		)
			return;

		const newYearNum = parseInt(newYear, 10),
			isNewYear = self.currentYear !== newYearNum;

		self.currentYear = newYearNum || self.currentYear;

		if (self.config.maxDate	&& self.currentYear === self.config.maxDate.getFullYear()) {
			self.currentMonth = Math.min(
				self.config.maxDate.getMonth(),
				self.currentMonth
			);
		}

		else if (
			self.config.minDate && self.currentYear === self.config.minDate.getFullYear()) {
			self.currentMonth = Math.max(
				self.config.minDate.getMonth(),
				self.currentMonth
			);
		}

		if (isNewYear) {
			self.redraw();
			triggerEvent("YearChange");
		}
	}

	function isEnabled(date, timeless) {
		if (
			(self.config.minDate && compareDates(
				date,
				self.config.minDate,
				timeless !== undefined ? timeless : !self.minDateHasTime
			) < 0) || (self.config.maxDate && compareDates(
				date,
				self.config.maxDate,
				timeless !== undefined ? timeless : !self.maxDateHasTime
			) > 0)
		)
			return false;

		if (!self.config.enable.length && !self.config.disable.length)
			return true;

		const dateToCheck = self.parseDate(date, null, true); // timeless

		const bool = self.config.enable.length > 0,
			array = bool ? self.config.enable : self.config.disable;

		for (let i = 0, d; i < array.length; i++) {
			d = array[i];

			if (d instanceof Function && d(dateToCheck)) // disabled by function
				return bool;

			else if (d instanceof Date && d.getTime() === dateToCheck.getTime())
				// disabled by date
				return bool;

			else if (typeof d === "string" && self.parseDate(d, null, true).getTime() === dateToCheck.getTime())
				// disabled by date string
				return bool;

			else if ( // disabled by range
				typeof d === "object" && d.from && d.to &&
				dateToCheck >= d.from && dateToCheck <= d.to
			)
				return bool;
		}

		return !bool;
	}

	function onKeyDown(e) {
		if (e.key === "Enter" && e.target === (self.altInput||self.input) && self.config.allowInput) {
			self.setDate(
				(self.altInput || self.input).value,
				true,
				e.target === self.altInput
					? self.config.altFormat
					: self.config.dateFormat
			);
			return e.target.blur();
		}

		else if (self.isOpen || self.config.inline) {
			switch (e.key) {
				case "Enter":
					if (self.timeContainer && self.timeContainer.contains(e.target))
						updateValue();

					else
						selectDate(e);

					break;


				case "Escape": // escape
					e.preventDefault();
					self.close();
					break;

				case "ArrowLeft":
				case "ArrowRight": {
					e.preventDefault();
					const isTimeObj = self.timeContainer
						&& self.timeContainer.contains(e.target);
					if (self.daysContainer) {
						const delta = e.key === "ArrowRight" ? 1 : -1;
						if (!e.ctrlKey)
							focusOnDay(e.target.$i, delta);

						else {
							changeMonth(delta, true);
							focusOnDay(e.target.$i, 0);
						}
					}

					else if (self.config.enableTime && !isTimeObj)
						self.hourElement.focus();

					break;
				}


				case "ArrowUp":
				case "ArrowDown":
					e.preventDefault();
					const delta = e.key === "ArrowDown" ? 1 : -1;
					const isTimeObj = self.timeContainer
						&& self.timeContainer.contains(e.target);

					if (self.daysContainer) {
						if (e.ctrlKey) {
							changeYear(self.currentYear-delta);
							focusOnDay(e.target.$i, 0);
						}

						else if (!isTimeObj)
							focusOnDay(e.target.$i, delta*7);
					}

					else if (self.config.enableTime) {
						if (!isTimeObj)
							self.hourElement.focus();
						updateTime(e);
					}


					break;


				case "Tab":
					if (e.target === self.hourElement) {
						e.preventDefault();
						self.minuteElement.select();
					}

					else if (e.target === self.minuteElement && self.amPM) {
						e.preventDefault();
						self.amPM.focus();
					}

					break;

				case "a":
					if (e.target === self.amPM) {
						self.amPM.textContent = "AM";
						setHoursFromInputs();
						updateValue();
					}
					break;

				case "p":
					if (e.target === self.amPM) {
						self.amPM.textContent = "PM";
						setHoursFromInputs();
						updateValue();
					}
					break;

				default: break;

			}

			triggerEvent("KeyDown", e);
		}
	}

	function onMouseOver(elem) {
		if (self.selectedDates.length !== 1 || !elem.classList.contains("flatpickr-day"))
			return;

		let hoverDate = elem.dateObj,
			initialDate = self.parseDate(self.selectedDates[0], null, true),
			rangeStartDate = Math.min(hoverDate.getTime(), self.selectedDates[0].getTime()),
			rangeEndDate = Math.max(hoverDate.getTime(), self.selectedDates[0].getTime()),
			containsDisabled = false;

		for (let t = rangeStartDate; t < rangeEndDate; t += self.utils.duration.DAY) {
			if (!isEnabled(new Date(t))) {
				containsDisabled = true;
				break;
			}
		}

		for (
			let timestamp = self.days.childNodes[0].dateObj.getTime(), i = 0;
			i < 42;
			i++, timestamp += self.utils.duration.DAY
		) {
			const outOfRange = timestamp < self.minRangeDate.getTime()
				|| timestamp > self.maxRangeDate.getTime(),
				dayElem = self.days.childNodes[i];

			if (outOfRange) {
				self.days.childNodes[i].classList.add("notAllowed");
				["inRange", "startRange", "endRange"].forEach(c => {
					dayElem.classList.remove(c)
				});
				continue;
			}

			else if (containsDisabled && !outOfRange)
				continue;



			["startRange", "inRange", "endRange", "notAllowed"].forEach(c => {
				dayElem.classList.remove(c)
			});

			const minRangeDate = Math.max(self.minRangeDate.getTime(), rangeStartDate),
				maxRangeDate = Math.min(self.maxRangeDate.getTime(), rangeEndDate);

			elem.classList.add(hoverDate < self.selectedDates[0] ? "startRange" : "endRange");

			if (initialDate < hoverDate && timestamp === initialDate.getTime())
				dayElem.classList.add("startRange");<commit_msg>inline mode + onKeyDown | #623<commit_after>/*! flatpickr v2.4.8, @license MIT */
function Flatpickr(element, config) {
	const self = this;

	self._ = {};

	self.changeMonth = changeMonth;
	self.changeYear = changeYear;
	self.clear = clear;
	self.close = close;
	self._createElement = createElement;
	self.destroy = destroy;
	self.isEnabled = isEnabled;
	self.jumpToDate = jumpToDate;
	self.open = open;
	self.redraw = redraw;
	self.set = set;
	self.setDate = setDate;
	self.toggle = toggle;

	function init() {
		if (element._flatpickr)
			destroy(element._flatpickr);

		element._flatpickr = self;

		self.element = element;
		self.instanceConfig = config || {};
		self.parseDate = Flatpickr.prototype.parseDate.bind(self);
		self.formatDate = Flatpickr.prototype.formatDate.bind(self);

		setupFormats();
		parseConfig();
		setupLocale();
		setupInputs();
		setupDates();
		setupHelperFunctions();

		self.isOpen = false;

		self.isMobile = (
			!self.config.disableMobile &&
			!self.config.inline &&
			self.config.mode === "single" &&
			!self.config.disable.length &&
			!self.config.enable.length &&
			!self.config.weekNumbers &&
			/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
		);

		if (!self.isMobile)
			build();

		bind();

		if (self.selectedDates.length || self.config.noCalendar) {
			if (self.config.enableTime) {
				setHoursFromDate(self.config.noCalendar
					? self.latestSelectedDateObj || self.config.minDate
					: null);
			}
			updateValue();
		}

		if (self.config.weekNumbers) {
			self.calendarContainer.style.width = self.daysContainer.clientWidth
				+ self.weekWrapper.clientWidth + "px";
		}

		self.showTimeInput = self.selectedDates.length > 0 || self.config.noCalendar;

		if (!self.isMobile)
			positionCalendar();
		triggerEvent("Ready");
	}

	function bindToInstance(fn) {
		return fn.bind(self);
	}

	function updateTime(e) {
		if (self.config.noCalendar && !self.selectedDates.length)
			// picking time only
			self.selectedDates = [self.now];

		timeWrapper(e);

		if (!self.selectedDates.length)
			return;

		if (!self.minDateHasTime || e.type !== "input" || e.target.value.length >= 2) {
			setHoursFromInputs();
			updateValue();
		}

		else {
			setTimeout(function(){
				setHoursFromInputs();
				updateValue();
			}, 1000);
		}
	}

	function setHoursFromInputs(){
		if (!self.config.enableTime)
			return;

		let hours = (parseInt(self.hourElement.value, 10) || 0) % (self.amPM ? 12 : 24),
			minutes = (parseInt(self.minuteElement.value, 10) || 0) % 60,
			seconds = self.config.enableSeconds
				? (parseInt(self.secondElement.value, 10) || 0)
				: 0;

		if (self.amPM)
			hours = (hours % 12) + (12 * (self.amPM.textContent === "PM"));

		if (
			self.minDateHasTime
			&& compareDates(self.latestSelectedDateObj, self.config.minDate) === 0
		) {

			hours = Math.max(hours, self.config.minDate.getHours());
			if (hours === self.config.minDate.getHours())
				minutes = Math.max(minutes, self.config.minDate.getMinutes());
		}

		if (
			self.maxDateHasTime
			&& compareDates(self.latestSelectedDateObj, self.config.maxDate) === 0
		) {
			hours = Math.min(hours, self.config.maxDate.getHours());
			if (hours === self.config.maxDate.getHours())
				minutes = Math.min(minutes, self.config.maxDate.getMinutes());
		}

		setHours(hours, minutes, seconds);
	}

	function setHoursFromDate(dateObj){
		const date = dateObj || self.latestSelectedDateObj;

		if (date)
			setHours(date.getHours(), date.getMinutes(), date.getSeconds());
	}

	function setHours(hours, minutes, seconds) {
		if (self.selectedDates.length) {
			self.latestSelectedDateObj.setHours(
				hours % 24, minutes, seconds || 0, 0
			);
		}

		if (!self.config.enableTime || self.isMobile)
			return;

		self.hourElement.value = self.pad(
			!self.config.time_24hr ? (12 + hours) % 12 + 12 * (hours % 12 === 0) : hours
		);

		self.minuteElement.value = self.pad(minutes);

		if (!self.config.time_24hr)
			self.amPM.textContent = hours >= 12 ? "PM" : "AM";

		if (self.config.enableSeconds)
			self.secondElement.value = self.pad(seconds);
	}

	function onYearInput(event) {
		let year = event.target.value;
		if (event.delta)
			year = (parseInt(year) + event.delta).toString();

		if (year.length === 4) {
			self.currentYearElement.blur();
			if (!/[^\d]/.test(year))
				changeYear(year);
		}
	}

	function onMonthScroll(e) {
		e.preventDefault();
		self.changeMonth(Math.max(-1, Math.min(1, (e.wheelDelta || -e.deltaY))));
	}

	function bind() {
		if (self.config.wrap) {
			["open", "close", "toggle", "clear"].forEach(el => {
				const toggles = self.element.querySelectorAll(`[data-${el}]`);
				for (let i = 0; i < toggles.length; i++)
					toggles[i].addEventListener("click", self[el]);
			});
		}

		if (window.document.createEvent !== undefined) {
			self.changeEvent = window.document.createEvent("HTMLEvents");
			self.changeEvent.initEvent("change", false, true);
		}

		if (self.isMobile)
			return setupMobile();

		self.debouncedResize = debounce(onResize, 50);
		self.triggerChange = () => {
			triggerEvent("Change");
		};
		self.debouncedChange = debounce(self.triggerChange, 300);

		if (self.config.mode === "range" && self.daysContainer)
			self.daysContainer.addEventListener("mouseover", e => onMouseOver(e.target));

		document.body.addEventListener("keydown", onKeyDown);

		if (!self.config.static)
			(self.altInput || self.input).addEventListener("keydown", onKeyDown);

		if (!self.config.inline && !self.config.static)
			window.addEventListener("resize", self.debouncedResize);

		if (window.ontouchstart)
			window.document.addEventListener("touchstart", documentClick);

		window.document.addEventListener("click", documentClick);
		(self.altInput || self.input).addEventListener("blur", documentClick);

		if (self.config.clickOpens)
			(self.altInput || self.input).addEventListener("focus", open);

		if (!self.config.noCalendar) {
			self.prevMonthNav.addEventListener("click", () => changeMonth(-1));
			self.nextMonthNav.addEventListener("click", () => changeMonth(1));

			self.currentMonthElement.addEventListener("wheel", e => debounce(onMonthScroll(e), 50));
			self.currentYearElement.addEventListener("wheel", e => debounce(yearScroll(e), 50));
			self.currentYearElement.addEventListener("focus", () => {
				self.currentYearElement.select();
			});

			self.currentYearElement.addEventListener("input", onYearInput);
			self.currentYearElement.addEventListener("increment", onYearInput);

			self.daysContainer.addEventListener("click", selectDate);

			if (self.config.animate)
				self.daysContainer.addEventListener("animationend", animateDays);
		}

		if (self.config.enableTime) {
			self.timeContainer.addEventListener("transitionend", positionCalendar);
			self.timeContainer.addEventListener("wheel", e => debounce(updateTime(e), 5));
			self.timeContainer.addEventListener("input", updateTime);
			self.timeContainer.addEventListener("increment", updateTime);
			self.timeContainer.addEventListener("increment", self.debouncedChange);

			self.timeContainer.addEventListener("wheel", self.debouncedChange);
			self.timeContainer.addEventListener("input", self.triggerChange);

			self.hourElement.addEventListener("focus", () => {
				self.hourElement.select();
			});
			self.minuteElement.addEventListener("focus", () => {
				self.minuteElement.select();
			});

			if (self.secondElement) {
				self.secondElement.addEventListener("focus", () => {
					self.secondElement.select();
				});
			}

			if (self.amPM) {
				self.amPM.addEventListener("click", (e) => {
					updateTime(e);
					self.triggerChange(e);
				});
			}
		}
	}

	function animateDays (e) {
		if (self.daysContainer.childNodes.length > 1) {
			switch(e.animationName) {
				case "slideLeft":
					self.daysContainer.childNodes[1].classList.remove("slideLeftNew")
					self.daysContainer.removeChild(self.daysContainer.childNodes[0]);
					break;

				case "slideRight":
					self.daysContainer.childNodes[0].classList.remove("slideRightNew")
					self.daysContainer.removeChild(self.daysContainer.childNodes[1]);
					break;

				default: break;
			}
		}
	}

	function jumpToDate(jumpDate) {
		jumpDate = jumpDate
			? self.parseDate(jumpDate)
			: self.latestSelectedDateObj || (self.config.minDate > self.now
				? self.config.minDate
				: self.config.maxDate && self.config.maxDate < self.now
					? self.config.maxDate
					: self.now
			);

		try {
			self.currentYear = jumpDate.getFullYear();
			self.currentMonth = jumpDate.getMonth();
		}

		catch (e) {
			/* istanbul ignore next */
			console.error(e.stack);
			/* istanbul ignore next */
			console.warn("Invalid date supplied: " + jumpDate);
		}

		self.redraw();
	}

	function incrementNumInput(e, delta, inputElem) {
		const input = inputElem || e.target.parentNode.childNodes[0];
		let ev;

		try {
			ev = new Event("increment", { "bubbles": true });
		}

		catch (err) {
			ev = window.document.createEvent("CustomEvent");
			ev.initCustomEvent("increment", true, true, {});
		}

		ev.delta = delta;
		input.dispatchEvent(ev);
	}

	function createNumberInput(inputClassName) {
		const wrapper = createElement("div", "numInputWrapper"),
			numInput = createElement("input", "numInput " + inputClassName),
			arrowUp = createElement("span", "arrowUp"),
			arrowDown = createElement("span", "arrowDown");

		numInput.type = "text";
		numInput.pattern = "\\d*";
		wrapper.appendChild(numInput);
		wrapper.appendChild(arrowUp);
		wrapper.appendChild(arrowDown);

		arrowUp.addEventListener("click", e => incrementNumInput(e, 1));
		arrowDown.addEventListener("click", e => incrementNumInput(e, -1));
		return wrapper;
	}

	function build() {
		const fragment = window.document.createDocumentFragment();
		self.calendarContainer = createElement("div", "flatpickr-calendar");
		self.calendarContainer.tabIndex = -1;
		self.numInputType = navigator.userAgent.indexOf("MSIE 9.0") > 0 ? "text" : "number";

		if (!self.config.noCalendar) {
			fragment.appendChild(buildMonthNav());
			self.innerContainer = createElement("div", "flatpickr-innerContainer")

			if (self.config.weekNumbers)
				self.innerContainer.appendChild(buildWeeks());

			self.rContainer = createElement("div", "flatpickr-rContainer");
			self.rContainer.appendChild(buildWeekdays());

			if (!self.daysContainer) {
				self.daysContainer = createElement("div", "flatpickr-days");
				self.daysContainer.tabIndex = -1;
			}

			buildDays();
			self.rContainer.appendChild(self.daysContainer);

			self.innerContainer.appendChild(self.rContainer);
			fragment.appendChild(self.innerContainer);
		}

		if (self.config.enableTime)
			fragment.appendChild(buildTime());

		toggleClass(self.calendarContainer, "rangeMode", self.config.mode === "range");
		toggleClass(self.calendarContainer, "animate", self.config.animate);

		self.calendarContainer.appendChild(fragment);

		const customAppend = self.config.appendTo && self.config.appendTo.nodeType;

		if (self.config.inline || self.config.static) {
			self.calendarContainer.classList.add(self.config.inline ? "inline" : "static");


			if (self.config.inline && !customAppend) {
				return self.element.parentNode.insertBefore(
					self.calendarContainer,
					(self.altInput || self.input).nextSibling
				);
			}

			if (self.config.static){
				const wrapper = createElement("div", "flatpickr-wrapper");
				self.element.parentNode.insertBefore(wrapper, self.element);
				wrapper.appendChild(self.element);

				if(self.altInput)
					wrapper.appendChild(self.altInput);

				wrapper.appendChild(self.calendarContainer);
				return;
			}
		}

		(customAppend ? self.config.appendTo : window.document.body)
			.appendChild(self.calendarContainer);
	}

	function createDay(className, date, dayNumber, i) {
		const dateIsEnabled = isEnabled(date, true),
			dayElement = createElement(
				"span",
				"flatpickr-day " + className,
				date.getDate()
			);

		dayElement.dateObj = date;
		dayElement.$i = i;
		dayElement.setAttribute("aria-label", self.formatDate(date, "F j, Y"));

		if (compareDates(date, self.now) === 0) {
			self.todayDateElem = dayElement;
			dayElement.classList.add("today");
		}

		if (dateIsEnabled) {
			dayElement.tabIndex = -1;
			if (isDateSelected(date)){
				dayElement.classList.add("selected");
				self.selectedDateElem = dayElement;
				if (self.config.mode === "range") {
					toggleClass(
						dayElement,
						"startRange",
						compareDates(date, self.selectedDates[0]) === 0
					);

					toggleClass(
						dayElement,
						"endRange",
						compareDates(date, self.selectedDates[1]) === 0
					);
				}
			}
		}

		else {
			dayElement.classList.add("disabled");
			if (
				self.selectedDates[0]
				&& date > self.minRangeDate
				&& date < self.selectedDates[0]
			)

				self.minRangeDate = date;

			else if (
				self.selectedDates[0]
				&& date < self.maxRangeDate
				&& date > self.selectedDates[0]
			)
				self.maxRangeDate = date;
		}

		if (self.config.mode === "range") {
			if (isDateInRange(date) && !isDateSelected(date))
				dayElement.classList.add("inRange");

			if (
				self.selectedDates.length === 1 &&
				(date < self.minRangeDate || date > self.maxRangeDate)
			)
				dayElement.classList.add("notAllowed");
		}

		if (self.config.weekNumbers && className !== "prevMonthDay" && dayNumber % 7 === 1) {
			self.weekNumbers.insertAdjacentHTML(
				"beforeend",
				"<span class='disabled flatpickr-day'>" + self.config.getWeek(date) + "</span>"
			);
		}

		triggerEvent("DayCreate", dayElement);

		return dayElement;
	}

	function focusOnDay(currentIndex, offset) {
		let newIndex = currentIndex + offset || 0,
			targetNode = currentIndex !== undefined
				? self.days.childNodes[newIndex]
				: self.selectedDateElem || self.todayDateElem || self.days.childNodes[0];

		if (targetNode === undefined) {
			if (offset > 0) {
				self.changeMonth(1);
				targetNode = self.days.childNodes[newIndex % 42].focus();
			}

			else if (offset < 0) {
				self.changeMonth(-1);
				targetNode = self.days.childNodes[42 + newIndex].focus();
			}
		}

		targetNode.focus();

		if (self.config.mode === "range")
			onMouseOver(targetNode);
	}

	function buildDays(delta) {
		const firstOfMonth = (
				new Date(self.currentYear, self.currentMonth, 1).getDay() -
				self.l10n.firstDayOfWeek + 7
			) % 7,
			isRangeMode = self.config.mode === "range";

		self.prevMonthDays = self.utils.getDaysinMonth((self.currentMonth - 1 + 12) % 12);
		self.selectedDateElem = undefined;
		self.todayDateElem = undefined;

		const daysInMonth = self.utils.getDaysinMonth(),
			days = window.document.createDocumentFragment();

		let	dayNumber = self.prevMonthDays + 1 - firstOfMonth,
			dayIndex = 0;

		if (self.config.weekNumbers && self.weekNumbers.firstChild)
			self.weekNumbers.textContent = "";

		if (isRangeMode) {
			// const dateLimits = self.config.enable.length || self.config.disable.length || self.config.mixDate || self.config.maxDate;
			self.minRangeDate = new Date(self.currentYear, self.currentMonth - 1, dayNumber);
			self.maxRangeDate = new Date(
				self.currentYear,
				self.currentMonth + 1,
				(42 - firstOfMonth) % daysInMonth
			);
		}

		// prepend days from the ending of previous month
		for (; dayNumber <= self.prevMonthDays; dayNumber++, dayIndex++) {
			days.appendChild(
				createDay(
					"prevMonthDay",
					new Date(self.currentYear, self.currentMonth - 1, dayNumber),
					dayNumber,
					dayIndex
				)
			);
		}

		// Start at 1 since there is no 0th day
		for (dayNumber = 1; dayNumber <= daysInMonth; dayNumber++, dayIndex++) {
			days.appendChild(
				createDay(
					"",
					new Date(self.currentYear, self.currentMonth, dayNumber),
					dayNumber,
					dayIndex
				)
			);
		}

		// append days from the next month
		for (let dayNum = daysInMonth + 1; dayNum <= 42 - firstOfMonth; dayNum++, dayIndex++) {
			days.appendChild(
				createDay(
					"nextMonthDay",
					new Date(self.currentYear, self.currentMonth + 1, dayNum % daysInMonth),
					dayNum,
					dayIndex
				)
			);
		}

		if (isRangeMode && self.selectedDates.length === 1 && days.childNodes[0]) {
			self._hidePrevMonthArrow = self._hidePrevMonthArrow ||
				self.minRangeDate > days.childNodes[0].dateObj;

			self._hideNextMonthArrow = self._hideNextMonthArrow ||
				self.maxRangeDate < new Date(self.currentYear, self.currentMonth + 1, 1);
		}

		else
			updateNavigationCurrentMonth();

		const dayContainer = createElement("div", "dayContainer");
		dayContainer.appendChild(days);

		if (!self.config.animate || delta === undefined)
			clearNode(self.daysContainer);

		else {
			while (self.daysContainer.childNodes.length > 1)
				self.daysContainer.removeChild(self.daysContainer.firstChild);
		}

		if (delta >= 0)
			self.daysContainer.appendChild(dayContainer);
		else
			self.daysContainer.insertBefore(dayContainer, self.daysContainer.firstChild);

		self.days = self.daysContainer.firstChild;
		return self.daysContainer;
	}

	function clearNode(node) {
		while (node.firstChild)
			node.removeChild(node.firstChild);
	}

	function buildMonthNav() {
		const monthNavFragment = window.document.createDocumentFragment();
		self.monthNav = createElement("div", "flatpickr-month");

		self.prevMonthNav = createElement("span", "flatpickr-prev-month");
		self.prevMonthNav.innerHTML = self.config.prevArrow;

		self.currentMonthElement = createElement("span", "cur-month");
		self.currentMonthElement.title = self.l10n.scrollTitle;

		const yearInput = createNumberInput("cur-year");
		self.currentYearElement =  yearInput.childNodes[0];
		self.currentYearElement.title = self.l10n.scrollTitle;

		if (self.config.minDate)
			self.currentYearElement.min = self.config.minDate.getFullYear();

		if (self.config.maxDate) {
			self.currentYearElement.max = self.config.maxDate.getFullYear();

			self.currentYearElement.disabled = self.config.minDate	&&
				self.config.minDate.getFullYear() === self.config.maxDate.getFullYear();
		}

		self.nextMonthNav = createElement("span", "flatpickr-next-month");
		self.nextMonthNav.innerHTML = self.config.nextArrow;

		self.navigationCurrentMonth = createElement("span", "flatpickr-current-month");
		self.navigationCurrentMonth.appendChild(self.currentMonthElement);
		self.navigationCurrentMonth.appendChild(yearInput);

		monthNavFragment.appendChild(self.prevMonthNav);
		monthNavFragment.appendChild(self.navigationCurrentMonth);
		monthNavFragment.appendChild(self.nextMonthNav);
		self.monthNav.appendChild(monthNavFragment);

		Object.defineProperty(self, "_hidePrevMonthArrow", {
			get () {
				return this.__hidePrevMonthArrow;
			},
			set (bool) {
				if (this.__hidePrevMonthArrow !== bool)
					self.prevMonthNav.style.display = bool ? "none" : "block";
				this.__hidePrevMonthArrow = bool;
			}
		});

		Object.defineProperty(self, "_hideNextMonthArrow", {
			get () {
				return this.__hideNextMonthArrow;
			},
			set (bool) {
				if (this.__hideNextMonthArrow !== bool)
					self.nextMonthNav.style.display = bool ? "none" : "block";
				this.__hideNextMonthArrow = bool;
			}
		});

		updateNavigationCurrentMonth();

		return self.monthNav;
	}

	function buildTime() {
		self.calendarContainer.classList.add("hasTime");
		if (self.config.noCalendar)
			self.calendarContainer.classList.add("noCalendar");
		self.timeContainer = createElement("div", "flatpickr-time");
		self.timeContainer.tabIndex = -1;
		const separator = createElement("span", "flatpickr-time-separator", ":");

		const hourInput = createNumberInput("flatpickr-hour");
		self.hourElement =  hourInput.childNodes[0];

		const minuteInput = createNumberInput("flatpickr-minute");
		self.minuteElement =  minuteInput.childNodes[0];

		self.hourElement.tabIndex = self.minuteElement.tabIndex = -1;

		self.hourElement.value = self.pad(self.latestSelectedDateObj
			? self.latestSelectedDateObj.getHours()
			: self.config.defaultHour
		);

		self.minuteElement.value = self.pad(self.latestSelectedDateObj
			? self.latestSelectedDateObj.getMinutes()
			: self.config.defaultMinute
		);

		self.hourElement.step = self.config.hourIncrement;
		self.minuteElement.step = self.config.minuteIncrement;

		self.hourElement.min = self.config.time_24hr ? 0 : 1;
		self.hourElement.max = self.config.time_24hr ? 23 : 12;

		self.minuteElement.min = 0;
		self.minuteElement.max = 59;

		self.hourElement.title = self.minuteElement.title = self.l10n.scrollTitle;

		self.timeContainer.appendChild(hourInput);
		self.timeContainer.appendChild(separator);
		self.timeContainer.appendChild(minuteInput);

		if (self.config.time_24hr)
			self.timeContainer.classList.add("time24hr");

		if (self.config.enableSeconds) {
			self.timeContainer.classList.add("hasSeconds");

			const secondInput = createNumberInput("flatpickr-second");
			self.secondElement =  secondInput.childNodes[0];

			self.secondElement.value =
				self.latestSelectedDateObj ? self.pad(self.latestSelectedDateObj.getSeconds()) : "00";

			self.secondElement.step = self.minuteElement.step;
			self.secondElement.min = self.minuteElement.min;
			self.secondElement.max = self.minuteElement.max;

			self.timeContainer.appendChild(
				createElement("span", "flatpickr-time-separator", ":")
			);
			self.timeContainer.appendChild(secondInput);
		}

		if (!self.config.time_24hr) { // add self.amPM if appropriate
			self.amPM = createElement(
				"span",
				"flatpickr-am-pm",
				["AM", "PM"][(self.hourElement.value > 11) | 0]
			);
			self.amPM.title = self.l10n.toggleTitle;
			self.amPM.tabIndex = -1;
			self.timeContainer.appendChild(self.amPM);
		}

		return self.timeContainer;
	}

	function buildWeekdays() {
		if (!self.weekdayContainer)
			self.weekdayContainer = createElement("div", "flatpickr-weekdays");

		const firstDayOfWeek = self.l10n.firstDayOfWeek;
		let	weekdays = self.l10n.weekdays.shorthand.slice();

		if (firstDayOfWeek > 0 && firstDayOfWeek < weekdays.length) {
			weekdays = [].concat(
				weekdays.splice(firstDayOfWeek, weekdays.length),
				weekdays.splice(0, firstDayOfWeek)
			);
		}

		self.weekdayContainer.innerHTML = `
		<span class=flatpickr-weekday>
			${weekdays.join("</span><span class=flatpickr-weekday>")}
		</span>
		`;

		return self.weekdayContainer;
	}

	/* istanbul ignore next */
	function buildWeeks() {
		self.calendarContainer.classList.add("hasWeeks");
		self.weekWrapper = createElement("div", "flatpickr-weekwrapper");
		self.weekWrapper.appendChild(
			createElement("span", "flatpickr-weekday", self.l10n.weekAbbreviation)
		);
		self.weekNumbers = createElement("div", "flatpickr-weeks");
		self.weekWrapper.appendChild(self.weekNumbers);

		return self.weekWrapper;
	}

	function changeMonth(value, is_offset) {
		is_offset = typeof is_offset === "undefined" || is_offset;
		const delta = is_offset ? value : value - self.currentMonth;

		if (
			(delta < 0 && self._hidePrevMonthArrow) ||
			(delta > 0 && self._hideNextMonthArrow)
		)
			return;

		self.currentMonth += delta;

		if (self.currentMonth < 0 || self.currentMonth > 11) {
			self.currentYear += (self.currentMonth > 11 ? 1 : -1);
			self.currentMonth = (self.currentMonth + 12) % 12;

			triggerEvent("YearChange");
		}

		updateNavigationCurrentMonth();
		buildDays(delta);

		triggerEvent("MonthChange");

		if (!self.config.animate)
			return;

		if (delta > 0) {
			self.daysContainer.lastChild.classList.add("slideLeftNew");
			self.daysContainer.firstChild.classList.add("slideLeft");
		}

		else if (delta < 0) {
			self.daysContainer.lastChild.classList.add("slideRight");
			self.daysContainer.firstChild.classList.add("slideRightNew");
		}
	}

	function clear(triggerChangeEvent) {
		self.input.value = "";

		if (self.altInput)
			self.altInput.value = "";

		if (self.mobileInput)
			self.mobileInput.value = "";

		self.selectedDates = [];
		self.latestSelectedDateObj = null;
		self.showTimeInput = false;

		self.redraw();

		if (triggerChangeEvent !== false)
			// triggerChangeEvent is true (default) or an Event
			triggerEvent("Change");
	}

	function close() {
		self.isOpen = false;

		if (!self.isMobile) {
			self.calendarContainer.classList.remove("open");
			(self.altInput || self.input).classList.remove("active");
		}

		triggerEvent("Close");
	}

	function destroy(instance) {
		instance = instance || self;
		instance.clear(false);

		window.removeEventListener("resize", instance.debouncedResize);

		window.document.removeEventListener("click", documentClick);
		window.document.removeEventListener("touchstart", documentClick);
		window.document.removeEventListener("blur", documentClick);

		if (instance.timeContainer)
			instance.timeContainer.removeEventListener("transitionend", positionCalendar);

		if (instance.mobileInput) {
			if (instance.mobileInput.parentNode)
				instance.mobileInput.parentNode.removeChild(instance.mobileInput);
			delete instance.mobileInput;
		}

		else if (instance.calendarContainer && instance.calendarContainer.parentNode)
			instance.calendarContainer.parentNode.removeChild(instance.calendarContainer);

		if (instance.altInput) {
			instance.input.type = "text";
			if (instance.altInput.parentNode)
				instance.altInput.parentNode.removeChild(instance.altInput);
			delete instance.altInput;
		}

		instance.input.type = instance.input._type;
		instance.input.classList.remove("flatpickr-input");
		instance.input.removeEventListener("focus", open);
		instance.input.removeAttribute("readonly");

		delete instance.input._flatpickr;
	}

	function isCalendarElem(elem) {
		if (self.config.appendTo && self.config.appendTo.contains(elem))
			return true;

		return self.calendarContainer.contains(elem);
	}

	function documentClick(e) {
		if (self.isOpen && !self.config.inline) {
			const isCalendarElement = isCalendarElem(e.target);
			const isInput = e.target === self.input
				|| e.target === self.altInput
				|| self.element.contains(e.target)
				|| (
					// web components
					e.path && e.path.indexOf &&
					(~e.path.indexOf(self.input) || ~e.path.indexOf(self.altInput))
				);

			const lostFocus = e.type === "blur"
				? isInput && e.relatedTarget && !isCalendarElem(e.relatedTarget)
				: !isInput && !isCalendarElement;

			if(lostFocus) {
				e.preventDefault();
				self.close();

				if (self.config.mode === "range" && self.selectedDates.length === 1) {
					self.clear();
					self.redraw();
				}
			}
		}
	}

	function changeYear(newYear) {
		if (
			!newYear
			|| (self.currentYearElement.min && newYear < self.currentYearElement.min)
			|| (self.currentYearElement.max && newYear > self.currentYearElement.max)
		)
			return;

		const newYearNum = parseInt(newYear, 10),
			isNewYear = self.currentYear !== newYearNum;

		self.currentYear = newYearNum || self.currentYear;

		if (self.config.maxDate	&& self.currentYear === self.config.maxDate.getFullYear()) {
			self.currentMonth = Math.min(
				self.config.maxDate.getMonth(),
				self.currentMonth
			);
		}

		else if (
			self.config.minDate && self.currentYear === self.config.minDate.getFullYear()) {
			self.currentMonth = Math.max(
				self.config.minDate.getMonth(),
				self.currentMonth
			);
		}

		if (isNewYear) {
			self.redraw();
			triggerEvent("YearChange");
		}
	}

	function isEnabled(date, timeless) {
		if (
			(self.config.minDate && compareDates(
				date,
				self.config.minDate,
				timeless !== undefined ? timeless : !self.minDateHasTime
			) < 0) || (self.config.maxDate && compareDates(
				date,
				self.config.maxDate,
				timeless !== undefined ? timeless : !self.maxDateHasTime
			) > 0)
		)
			return false;

		if (!self.config.enable.length && !self.config.disable.length)
			return true;

		const dateToCheck = self.parseDate(date, null, true); // timeless

		const bool = self.config.enable.length > 0,
			array = bool ? self.config.enable : self.config.disable;

		for (let i = 0, d; i < array.length; i++) {
			d = array[i];

			if (d instanceof Function && d(dateToCheck)) // disabled by function
				return bool;

			else if (d instanceof Date && d.getTime() === dateToCheck.getTime())
				// disabled by date
				return bool;

			else if (typeof d === "string" && self.parseDate(d, null, true).getTime() === dateToCheck.getTime())
				// disabled by date string
				return bool;

			else if ( // disabled by range
				typeof d === "object" && d.from && d.to &&
				dateToCheck >= d.from && dateToCheck <= d.to
			)
				return bool;
		}

		return !bool;
	}

	function onKeyDown(e) {
		const isInput = e.target === (self.altInput || self.input);
		const calendarElem = isCalendarElem(e.target);

		if (e.key === "Enter" && self.config.allowInput && isInput) {
			self.setDate(
				(self.altInput || self.input).value,
				true,
				e.target === self.altInput
					? self.config.altFormat
					: self.config.dateFormat
			);
			return e.target.blur();
		}

		else if (self.isOpen || (self.config.inline && (isInput || calendarElem))) {
			const isTimeObj = self.timeContainer
				&& self.timeContainer.contains(e.target);
			switch (e.key) {
				case "Enter":
					if (isTimeObj)
						updateValue();

					else
						selectDate(e);

					break;


				case "Escape": // escape
					e.preventDefault();
					self.close();
					break;

				case "ArrowLeft":
				case "ArrowRight": {
					e.preventDefault();
					const isTimeObj = self.timeContainer
						&& self.timeContainer.contains(e.target);
					if (self.daysContainer) {
						const delta = e.key === "ArrowRight" ? 1 : -1;
						if (!e.ctrlKey)
							focusOnDay(e.target.$i, delta);

						else {
							changeMonth(delta, true);
							focusOnDay(e.target.$i, 0);
						}
					}

					else if (self.config.enableTime && !isTimeObj)
						self.hourElement.focus();

					break;
				}


				case "ArrowUp":
				case "ArrowDown":
					e.preventDefault();
					const delta = e.key === "ArrowDown" ? 1 : -1;
					const isTimeObj = self.timeContainer
						&& self.timeContainer.contains(e.target);

					if (self.daysContainer) {
						if (e.ctrlKey) {
							changeYear(self.currentYear-delta);
							focusOnDay(e.target.$i, 0);
						}

						else if (!isTimeObj)
							focusOnDay(e.target.$i, delta*7);
					}

					else if (self.config.enableTime) {
						if (!isTimeObj)
							self.hourElement.focus();
						updateTime(e);
					}

					break;

				case "Tab":
					if (e.target === self.hourElement) {
						e.preventDefault();
						self.minuteElement.select();
					}

					else if (e.target === self.minuteElement && self.amPM) {
						e.preventDefault();
						self.amPM.focus();
					}

					break;

				case "a":
					if (e.target === self.amPM) {
						self.amPM.textContent = "AM";
						setHoursFromInputs();
						updateValue();
					}
					break;

				case "p":
					if (e.target === self.amPM) {
						self.amPM.textContent = "PM";
						setHoursFromInputs();
						updateValue();
					}
					break;

				default: break;

			}

			triggerEvent("KeyDown", e);
		}
	}

	function onMouseOver(elem) {
		if (self.selectedDates.length !== 1 || !elem.classList.contains("flatpickr-day"))
			return;

		let hoverDate = elem.dateObj,
			initialDate = self.parseDate(self.selectedDates[0], null, true),
			rangeStartDate = Math.min(hoverDate.getTime(), self.selectedDates[0].getTime()),
			rangeEndDate = Math.max(hoverDate.getTime(), self.selectedDates[0].getTime()),
			containsDisabled = false;

		for (let t = rangeStartDate; t < rangeEndDate; t += self.utils.duration.DAY) {
			if (!isEnabled(new Date(t))) {
				containsDisabled = true;
				break;
			}
		}

		for (
			let timestamp = self.days.childNodes[0].dateObj.getTime(), i = 0;
			i < 42;
			i++, timestamp += self.utils.duration.DAY
		) {
			const outOfRange = timestamp < self.minRangeDate.getTime()
				|| timestamp > self.maxRangeDate.getTime(),
				dayElem = self.days.childNodes[i];

			if (outOfRange) {
				self.days.childNodes[i].classList.add("notAllowed");
				["inRange", "startRange", "endRange"].forEach(c => {
					dayElem.classList.remove(c)
				});
				continue;
			}

			else if (containsDisabled && !outOfRange)
				continue;

			["startRange", "inRange", "endRange", "notAllowed"].forEach(c => {
				dayElem.classList.remove(c)
			});

			const minRangeDate = Math.max(self.minRangeDate.getTime(), rangeStartDate),
				maxRangeDate = Math.min(self.maxRangeDate.getTime(), rangeEndDate);

			elem.classList.add(hoverDate < self.selectedDates[0] ? "startRange" : "endRange");

			if (initialDate < hoverDate && timestamp === initialDate.getTime())
				dayElem.classList.add("startRange");
{'fraction_non_alphanumeric': 0.14726111899327618, 'fraction_numerical': 0.006754672753068904, 'mean_word_length': 3.7197758206565252, 'pattern_counts': {'":': 28, '<': 61, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '607575', 'n_tokens_mistral': 25079, 'n_tokens_neox': 20680, 'n_words': 3496}