/*!
 *
 * carbon-angular v0.0.5 | carbon-flatpickr-month-select.js
 *
 * Copyright 2014, 2019 IBM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


/**
 * This is from carbon-components.
 * We need it to format the month select according to specs.
 * Carbon currently doesn't expose this as a seperate package,
 * and we don't import the carbon-components js (on purpose)
 * so some copy pasta is required
 *
 * ref: https://github.com/carbon-design-system/carbon/blob/
 * 	f06f38f0c2ef624e409a3d5711e897a79f4c88fc/packages/components/src/components/date-picker/date-picker.js#L52-L123
 */
var monthToStr = function (monthNumber, shorthand, locale) {
    return locale.months[shorthand ? "shorthand" : "longhand"][monthNumber];
};
var ɵ0 = monthToStr;
var config = {
    selectorInit: "[data-date-picker]",
    selectorDatePickerInput: "[data-date-picker-input]",
    selectorDatePickerInputFrom: "[data-date-picker-input-from]",
    selectorDatePickerInputTo: "[data-date-picker-input-to]",
    selectorDatePickerIcon: "[data-date-picker-icon]",
    selectorFlatpickrMonthYearContainer: ".flatpickr-current-month",
    selectorFlatpickrYearContainer: ".numInputWrapper",
    selectorFlatpickrCurrentMonth: ".cur-month",
    classCalendarContainer: "bx--date-picker__calendar",
    classMonth: "bx--date-picker__month",
    classWeekdays: "bx--date-picker__weekdays",
    classDays: "bx--date-picker__days",
    classWeekday: "bx--date-picker__weekday",
    classDay: "bx--date-picker__day",
    classFocused: "bx--focused",
    classVisuallyHidden: "bx--visually-hidden",
    classFlatpickrCurrentMonth: "cur-month",
    attribType: "data-date-picker-type",
    dateFormat: "m/d/Y",
    shorthand: false
};
export var carbonFlatpickrMonthSelectPlugin = function (fp) {
    var setupElements = function () {
        var _a;
        if (!fp.monthElements) {
            return;
        }
        fp.monthElements.forEach(function (elem) {
            if (!elem.parentNode) {
                return;
            }
            elem.parentNode.removeChild(elem);
        });
        (_a = fp.monthElements).splice.apply(_a, [0,
            fp.monthElements.length].concat(fp.monthElements.map(function () {
            // eslint-disable-next-line no-underscore-dangle
            var monthElement = fp._createElement("span", config.classFlatpickrCurrentMonth);
            monthElement.textContent = monthToStr(fp.currentMonth, config.shorthand === true, fp.l10n);
            fp.yearElements[0]
                .closest(config.selectorFlatpickrMonthYearContainer)
                .insertBefore(monthElement, fp.yearElements[0].closest(config.selectorFlatpickrYearContainer));
            return monthElement;
        })));
    };
    var updateCurrentMonth = function () {
        var monthStr = monthToStr(fp.currentMonth, config.shorthand === true, fp.l10n);
        fp.yearElements.forEach(function (elem) {
            var currentMonthContainer = elem.closest(config.selectorFlatpickrMonthYearContainer);
            Array.prototype.forEach.call(currentMonthContainer.querySelectorAll(".cur-month"), function (monthElement) {
                monthElement.textContent = monthStr;
            });
        });
    };
    var register = function () {
        fp.loadedPlugins.push("carbonFlatpickrMonthSelectPlugin");
    };
    return {
        onMonthChange: updateCurrentMonth,
        onOpen: updateCurrentMonth,
        onReady: [setupElements, updateCurrentMonth, register]
    };
};
export { ɵ0 };
//# sourceMappingURL=carbon-flatpickr-month-select.js.map