import { p as proxyCustomElement, H, c as createEvent, h } from './p-a53686b3.js';
import { r as randomIdGenerator } from './p-ffe5c0e8.js';
import { d as detectClickOutside } from './p-430607cb.js';
import { d as detectFocusOutside } from './p-ee33960b.js';
import { l as logger } from './p-e3d2e899.js';
import { _ as _t } from './p-08cf2c0e.js';
import { d as defineCustomElement$b } from './p-d1fc55fd.js';
import { d as defineCustomElement$a } from './p-7811ea5a.js';
import { d as defineCustomElement$9 } from './p-f630b5d3.js';
import { d as defineCustomElement$8 } from './p-c90fed99.js';
import { d as defineCustomElement$7 } from './p-2c01b4f7.js';
import { d as defineCustomElement$6 } from './p-11278347.js';
import { d as defineCustomElement$5 } from './p-e6a40b0a.js';
import { d as defineCustomElement$4 } from './p-013b272d.js';
import { d as defineCustomElement$3 } from './p-5bbb5a67.js';
import { d as defineCustomElement$2 } from './p-33f08ec3.js';
import { d as defineCustomElement$1 } from './p-2f619b66.js';
import { r as requiredArgs, t as toDate, i as isValid } from './p-7aacd45f.js';

/**
 * @name isAfter
 * @category Common Helpers
 * @summary Is the first date after the second one?
 *
 * @description
 * Is the first date after the second one?
 *
 * ### v2.0.0 breaking changes:
 *
 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
 *
 * @param {Date|Number} date - the date that should be after the other one to return true
 * @param {Date|Number} dateToCompare - the date to compare with
 * @returns {Boolean} the first date is after the second date
 * @throws {TypeError} 2 arguments required
 *
 * @example
 * // Is 10 July 1989 after 11 February 1987?
 * var result = isAfter(new Date(1989, 6, 10), new Date(1987, 1, 11))
 * //=> true
 */

function isAfter(dirtyDate, dirtyDateToCompare) {
  requiredArgs(2, arguments);
  var date = toDate(dirtyDate);
  var dateToCompare = toDate(dirtyDateToCompare);
  return date.getTime() > dateToCompare.getTime();
}

/**
 * @name isBefore
 * @category Common Helpers
 * @summary Is the first date before the second one?
 *
 * @description
 * Is the first date before the second one?
 *
 * ### v2.0.0 breaking changes:
 *
 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
 *
 * @param {Date|Number} date - the date that should be before the other one to return true
 * @param {Date|Number} dateToCompare - the date to compare with
 * @returns {Boolean} the first date is before the second date
 * @throws {TypeError} 2 arguments required
 *
 * @example
 * // Is 10 July 1989 before 11 February 1987?
 * var result = isBefore(new Date(1989, 6, 10), new Date(1987, 1, 11))
 * //=> false
 */

function isBefore(dirtyDate, dirtyDateToCompare) {
  requiredArgs(2, arguments);
  var date = toDate(dirtyDate);
  var dateToCompare = toDate(dirtyDateToCompare);
  return date.getTime() < dateToCompare.getTime();
}

const calendarCss = ".sc-digi-calendar-h{--digi--calendar--display:inline-block;--digi--calendar--header--font-family:var(--digi--global--typography--font-family--default);--digi--calendar--header--font-weight:var(--digi--global--typography--font-weight--semibold);--digi--calendar--header--display:flex;--digi--calendar--header--align-items:center;--digi--calendar--header--justify-content:space-between;--digi--calendar--header--text-align:center;--digi--calendar--header--button--padding:var(--digi--gutter--medium) var(--digi--gutter--largest);--digi--calendar--header--button--background:transparent;--digi--calendar--header--button--box-shadow:none;--digi--calendar--header--button--background--hover:var(--digi--color--background--interactive--hover--secondary);--digi--calendar--table--border-spacing:0;--digi--calendar--table--border-collapse:collapse;--digi--calendar--table--font-family:var(--digi--global--typography--font-family--default);--digi--calendar--table--font-weight:var(--digi--global--typography--font-weight--semibold);--digi--calendar--table-header--padding:var(--digi--gutter--larger) 0;--digi--calendar--table-header--font-weight-normal:var(--digi--typography--body--font-weight--desktop);--digi--calendar--date--border-color:none;--digi--calendar--date--box-shadow:none;--digi--calendar--date--background-color:var(--digi--color--background--interactive--default--secondary);--digi--calendar--date--background-color--hover:var(--digi--color--background--interactive--hover--secondary);--digi--calendar--date--padding:var(--digi--gutter--large);--digi--calendar--date--color:var(--digi--color--text--primary);--digi--calendar--date--focused--background-color:var(--digi--color--background--interactive--hover--secondary);--digi--calendar--date--today--circle-border:2px solid var(--digi--color--marking--indication--secondary);--digi--calendar--date--today--circle-margin:10%;--digi--calendar--date--selected--color:var(--digi--color--text--interactive--secondary);--digi--calendar--date--selected--background-color:var(--digi--color--background--interactive--selected--primary);--digi--calendar--date--not-selectable-strike--color:var(--digi--color--marking--indication--tertiary);--digi--calendar--week--font-style:italic;--digi--calendar--week--font-size:var(--digi--global--typography--font-size--small);--digi--calendar--week--border-color:var(--digi--color--divider--primary);--digi--calendar--week--border-width:var(--digi--border-width--primary)}.sc-digi-calendar-h .digi-calendar.sc-digi-calendar{display:var(--digi--calendar--display);background:var(--digi--calendar--header--button--background);padding:0px 1px 3px 1px;overflow:hidden;max-width:23.4375rem}.sc-digi-calendar-h .digi-calendar--hide.sc-digi-calendar{--digi--calendar--display:none}.sc-digi-calendar-h .digi-calendar__header.sc-digi-calendar{display:var(--digi--calendar--header--display);align-items:var(--digi--calendar--header--align-items);justify-content:var(--digi--calendar--header--justify-content);text-align:var(--digi--calendar--header--text-align);font-size:var(--digi--global--typography--font-size--base);font-family:var(--digi--calendar--header--font-family);font-weight:var(--digi--calendar--header--font-weight)}.sc-digi-calendar-h .digi-calendar__header--year-select.sc-digi-calendar{display:inherit;justify-content:center;margin:0 auto}.sc-digi-calendar-h .digi-calendar__header--year-select.sc-digi-calendar digi-form-select.sc-digi-calendar:first-child{margin-right:var(--digi--padding--smaller)}.sc-digi-calendar-h .digi-calendar__header--year-select.sc-digi-calendar digi-form-select.sc-digi-calendar:last-child{width:5rem}.sc-digi-calendar-h .digi-calendar__header--year-select.sc-digi-calendar digi-form-select.sc-digi-calendar select.sc-digi-calendar{padding-inline-end:2rem}.sc-digi-calendar-h .digi-calendar__header--month-step.sc-digi-calendar{flex:auto;display:inherit;align-items:inherit;justify-content:inherit}.sc-digi-calendar-h .digi-calendar__header--month-step.sc-digi-calendar .digi-calendar__month-select-name.sc-digi-calendar{padding-inline:var(--digi--padding--smaller)}.sc-digi-calendar-h .digi-calendar__header--month-step.sc-digi-calendar .digi-calendar__month-select-button.sc-digi-calendar{font-family:inherit;font-size:inherit;font-weight:inherit;color:var(--digi--calendar--date--color);display:flex;align-items:center;background:var(--digi--calendar--header--button--background);border:var(--digi--calendar--date--box-shadow);padding:var(--digi--calendar--header--button--padding)}.sc-digi-calendar-h .digi-calendar__header--month-step.sc-digi-calendar .digi-calendar__month-select-button.sc-digi-calendar:last-child{border-radius:0 4px 0 0}.sc-digi-calendar-h .digi-calendar__header--month-step.sc-digi-calendar .digi-calendar__month-select-button.sc-digi-calendar:first-child{border-radius:4px 0 0 0}.sc-digi-calendar-h .digi-calendar__header--month-step.sc-digi-calendar .digi-calendar__month-select-button.sc-digi-calendar:focus-visible:not(.digi-calendar__date--not-selectable),.sc-digi-calendar-h .digi-calendar__header--month-step.sc-digi-calendar .digi-calendar__month-select-button.sc-digi-calendar:active:not(.digi-calendar__date--not-selectable){--digi--calendar--header--button--background:var(\n    --digi--calendar--header--button--background--hover\n  );text-decoration:underline;cursor:pointer}@media (any-hover: hover){.sc-digi-calendar-h .digi-calendar__header--month-step.sc-digi-calendar .digi-calendar__month-select-button.sc-digi-calendar:hover:not(.digi-calendar__date--not-selectable){--digi--calendar--header--button--background:var(\n      --digi--calendar--header--button--background--hover\n    );text-decoration:underline;cursor:pointer}}.sc-digi-calendar-h .digi-calendar__header--month-step.sc-digi-calendar .digi-calendar__month-select-button.sc-digi-calendar:focus-visible{outline:2px solid black;outline-offset:-3px;box-shadow:0px 0px 0px 5px inset white}.sc-digi-calendar-h .digi-calendar__table.sc-digi-calendar{border-collapse:var(--digi--calendar--table--border-collapse);border-spacing:var(--digi--calendar--table--border-spacing);font-family:var(--digi--calendar--table--font-family);table-layout:fixed;margin-bottom:var(--digi--margin--medium)}.sc-digi-calendar-h .digi-calendar__table-header-week.sc-digi-calendar{font-style:italic;padding:var(--digi--calendar--table-header--padding);font-weight:var(--digi--calendar--table-header--font-weight-normal);width:50px}.sc-digi-calendar-h .digi-calendar__table-header.sc-digi-calendar{padding:var(--digi--calendar--table-header--padding);font-weight:var(--digi--calendar--table--font-weight);width:46px}.sc-digi-calendar-h .digi-calendar__td-week.sc-digi-calendar{border-right:var(--digi--calendar--week--border-width) solid var(--digi--calendar--week--border-color)}.sc-digi-calendar-h .digi-calendar__td.sc-digi-calendar{text-align:right}.sc-digi-calendar-h .digi-calendar__date--week-number.sc-digi-calendar{font-style:var(--digi--calendar--week--font-style);font-size:var(--digi--calendar--week--font-size);display:table-cell;text-align:center}.sc-digi-calendar-h .digi-calendar__date--week-number.sc-digi-calendar:hover{cursor:default}.sc-digi-calendar-h .digi-calendar__date.sc-digi-calendar{position:relative;padding:var(--digi--calendar--date--padding);color:var(--digi--calendar--date--color);background-color:var(--digi--calendar--date--background-color);border-color:var(--digi--calendar--date--border-color);border-radius:var(--digi--border-radius--secondary);font-family:inherit;font-size:inherit;font-weight:inherit;text-align:center;border:none;width:44px;height:44px}.sc-digi-calendar-h .digi-calendar__date--disabled.sc-digi-calendar{--digi--calendar--date--color:transparent;pointer-events:none}.sc-digi-calendar-h .digi-calendar__date--today.sc-digi-calendar{position:relative}.sc-digi-calendar-h .digi-calendar__date--today.sc-digi-calendar::after{display:block;content:\" \";position:absolute;top:var(--digi--calendar--date--today--circle-margin);bottom:var(--digi--calendar--date--today--circle-margin);left:var(--digi--calendar--date--today--circle-margin);right:var(--digi--calendar--date--today--circle-margin);border:var(--digi--calendar--date--today--circle-border);border-radius:50%}@media (any-hover: hover){.sc-digi-calendar-h .digi-calendar__date.sc-digi-calendar:hover:not(.digi-calendar__date--not-selectable){cursor:pointer}.sc-digi-calendar-h .digi-calendar__date.sc-digi-calendar:hover:not(.digi-calendar__date--not-selectable):not(.digi-calendar__date--selected){--digi--calendar--date--box-shadow:var(--digi--calendar--date--box-shadow--hover);--digi--calendar--date--background-color:var(--digi--calendar--date--background-color--hover)}.sc-digi-calendar-h .digi-calendar__date.sc-digi-calendar:hover:not(.digi-calendar__date--not-selectable) span.sc-digi-calendar{text-decoration:underline}}.sc-digi-calendar-h .digi-calendar__date--selected.sc-digi-calendar{--digi--calendar--date--background-color:var(--digi--calendar--date--selected--background-color);--digi--calendar--date--color:var(--digi--calendar--date--selected--color)}.sc-digi-calendar-h .digi-calendar__date--selected.sc-digi-calendar:hover{--digi--calendar--date--background-color:var(--digi--calendar--date--selected--background-color)}.sc-digi-calendar-h .digi-calendar__date--selected.sc-digi-calendar:hover span.sc-digi-calendar{text-decoration:none}.sc-digi-calendar-h .digi-calendar__date--selected.sc-digi-calendar:focus-visible{outline:2px solid black;outline-offset:-3px;box-shadow:0px 0px 0px 5px inset white}.sc-digi-calendar-h .digi-calendar__date--not-selectable.sc-digi-calendar{cursor:not-allowed}.sc-digi-calendar-h .digi-calendar__date--not-selectable.sc-digi-calendar::after{display:block;content:\" \";width:0px;height:100%;border:1px solid #757575;transform:rotate(-45deg);position:absolute;top:0%;left:50%}.sc-digi-calendar-h .digi-calendar__date--focused.sc-digi-calendar:focus-visible:not(.digi-calendar__date--selected):not(.digi-calendar__date--not-selectable){--digi--calendar--date--background-color:var(--digi--calendar--date--focused--background-color);outline:2px solid black;outline-offset:-3px;box-shadow:0px 0px 0px 5px inset white}.sc-digi-calendar-s digi-form-label{border:0;clip:rect(1px, 1px, 1px, 1px);-webkit-clip-path:inset(50%);clip-path:inset(50%);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;white-space:nowrap}";
const DigiCalendarStyle0 = calendarCss;

const Calendar = /*@__PURE__*/ proxyCustomElement(class Calendar extends H {
    constructor() {
        super();
        this.__registerHost();
        this.afOnDateSelectedChange = createEvent(this, "afOnDateSelectedChange", 7);
        this.afOnFocusOutside = createEvent(this, "afOnFocusOutside", 7);
        this.afOnClickOutside = createEvent(this, "afOnClickOutside", 7);
        this.afOnDirty = createEvent(this, "afOnDirty", 7);
        this.activeCalendar = [];
        this.months = [];
        this.selectedDates = [];
        this.focusedDate = undefined;
        this.dirty = false;
        this.afId = randomIdGenerator('digi-calendar');
        this.afInitSelectedMonth = new Date().getMonth();
        this.afInitSelectedDate = new Date();
        this.afShowWeekNumber = false;
        this.afSelectedDate = undefined;
        this.afSelectedDates = [];
        this.afActive = true;
        this.afMinDate = undefined;
        this.afMaxDate = undefined;
        this.afMultipleDates = false;
        this.afYearSelect = false;
    }
    afSelectedDateChangeHandler() {
        if (isValid(this.afSelectedDate)) {
            this.selectedDates = [this.afSelectedDate];
        }
        else {
            this.selectedDates = [];
        }
    }
    afSelectedDatesChangeHandler() {
        if (this.afSelectedDates.length > 0) {
            if (this.afMultipleDates) {
                const invalidDate = this.afSelectedDates.find((date) => !isValid(date));
                if (invalidDate === undefined) {
                    this.selectedDates = this.afSelectedDates;
                }
            }
            else if (isValid(this.afSelectedDates[0])) {
                this.selectedDates = [this.afSelectedDates[0]];
            }
        }
        else {
            this.selectedDates = [];
        }
    }
    focusoutHandler(e) {
        const target = e.target;
        const selector = `#${this.afId}-calendar`;
        if (detectFocusOutside(target, selector)) {
            this.afOnFocusOutside.emit(e);
        }
    }
    clickHandler(e) {
        const target = e.target;
        const selector = `#${this.afId}-calendar`;
        if (detectClickOutside(target, selector)) {
            this.afOnClickOutside.emit(e);
        }
    }
    drawCalendar(focusedDate) {
        const date = {
            year: focusedDate.getFullYear(),
            month: focusedDate.getMonth()
        };
        this.lastWeekOfPreviousMonth = this.getWeekDays(this.getLastDayOfPrevMonth(date));
        this.firstWeekOfNextMonth = this.getWeekDays(this.getFirstDayOfNextMonth(date));
        this.weeksBetween = this.getWeeksBetween(this.getLastDayOfPrevMonth(date), this.getFirstDayOfNextMonth(date));
        this.weekDaysbetween = this.getWeekdaysOfMonth(this.weeksBetween);
        this.months = [
            'januari',
            'februari',
            'mars',
            'april',
            'maj',
            'juni',
            'juli',
            'augusti',
            'september',
            'oktober',
            'november',
            'december'
        ];
        this.activeCalendar = this.appendFirstWeekOfNextMonth()
            ? [
                this.lastWeekOfPreviousMonth,
                ...this.weekDaysbetween,
                this.appendFirstWeekOfNextMonth()
            ]
            : [this.lastWeekOfPreviousMonth, ...this.weekDaysbetween];
        this.appendFirstWeekOfNextMonth();
        if (this.afShowWeekNumber) {
            this.activeCalendar.forEach((el, i) => {
                this.activeCalendar[i].unshift(this.getWeekNumbers(el[0]));
            });
        }
    }
    appendFirstWeekOfNextMonth() {
        const lastArray = JSON.stringify(this.weekDaysbetween.slice(-1)[0]);
        const stringFirstweek = JSON.stringify(this.firstWeekOfNextMonth);
        if (!this.firstWeekOfNextMonth.some((date) => this.isSameMonth(date, this.focusedDate))) {
            return;
        }
        else if (lastArray !== stringFirstweek) {
            return this.firstWeekOfNextMonth;
        }
    }
    getLastDayOfPrevMonth(date) {
        return new Date(date.year, date.month, 0);
    }
    getWeekDays(date) {
        const today = date || new Date();
        const week = [];
        for (let i = 1; i <= 7; i++) {
            const first = today.getDate() - today.getDay() + i;
            const day = new Date(today.setDate(first));
            week.push(day);
        }
        return week;
    }
    getFirstDayOfNextMonth(date) {
        return new Date(date.year, date.month + 1, 1);
    }
    getWeeksBetween(lastDayOfPrevMonth, firstDayOnNextMonth) {
        const week = 7 * 24 * 60 * 60 * 1000;
        const d1ms = lastDayOfPrevMonth.getTime();
        const d2ms = firstDayOnNextMonth.getTime();
        const diff = Math.abs(d2ms - d1ms);
        return Math.floor(diff / week);
    }
    getWeekdaysOfMonth(weeksBetween) {
        let weeks = [];
        for (let i = 1; i <= weeksBetween; i++) {
            weeks = [...weeks, this.getWeekDays(this.getUpcoming(i))];
        }
        return weeks;
    }
    getUpcoming(weeks) {
        return new Date(this.focusedDate.getFullYear(), this.focusedDate.getMonth(), 7 * weeks);
    }
    onDirty() {
        if (!this.dirty) {
            this.dirty = true;
            this.afOnDirty.emit(this.dirty);
        }
    }
    selectDateHandler(dateSelected) {
        this.onDirty();
        if (!this.isDateSelectable(dateSelected))
            return;
        if (this.isDateSelected(dateSelected)) {
            this.selectedDates = this.afMultipleDates
                ? this.selectedDates.filter((d) => {
                    return !this.isSameDate(d, dateSelected);
                })
                : [];
        }
        else {
            this.selectedDates = this.afMultipleDates
                ? [...this.selectedDates, dateSelected]
                : [dateSelected];
        }
        this.focusedDate = new Date(dateSelected);
        this.afOnDateSelectedChange.emit(this.selectedDates);
    }
    getMonthName(monthNumber) {
        return new Date(1992, monthNumber, 1)
            .toLocaleDateString('default', {
            month: 'short'
        })
            .replace('.', '');
    }
    getFullMonthName(monthNumber) {
        return new Date(this.focusedDate.getFullYear(), monthNumber, 1).toLocaleDateString('default', {
            month: 'long',
            year: 'numeric'
        });
    }
    // Get the week number of a specific date. Taken from https://weeknumber.com/how-to/javascript
    getWeekNumbers(dateInput) {
        const date = new Date(dateInput);
        date.getTime();
        date.setHours(0, 0, 0, 0);
        date.setDate(date.getDate() + 3 - ((date.getDay() + 6) % 7));
        const week1 = new Date(date.getFullYear(), 0, 4);
        return (1 +
            Math.round(((date.getTime() - week1.getTime()) / 86400000 -
                3 +
                ((week1.getDay() + 6) % 7)) /
                7));
    }
    isSameMonth(date, currentDate) {
        if (date instanceof Date && date instanceof Date) {
            return (`${date.getFullYear()}${date.getMonth()}` ===
                `${currentDate.getFullYear()}${currentDate.getMonth()}`);
        }
        return false;
    }
    isSameDate(date, newDate) {
        return this.getDateString(date) === this.getDateString(newDate);
    }
    getDateString(date) {
        return `${date.getDate()}${date.getMonth()}${date.getFullYear()}`;
    }
    isDateSelected(date) {
        return !!this.selectedDates.find((d) => this.isSameDate(date, d));
    }
    isDateSelectable(date) {
        if (this.afMinDate && this.isBefore(date, this.afMinDate))
            return false;
        if (this.afMaxDate && this.isAfter(date, this.afMaxDate))
            return false;
        return true;
    }
    isBefore(a, b) {
        return isBefore(this.dateWithoutTime(a), this.dateWithoutTime(b));
    }
    isAfter(a, b) {
        return isAfter(this.dateWithoutTime(a), this.dateWithoutTime(b));
    }
    dateWithoutTime(date) {
        return new Date(date.getFullYear(), date.getMonth(), date.getDate());
    }
    isInAnotherMonth(date) {
        return !this.isSameMonth(date, this.focusedDate);
    }
    subtractMonth() {
        const month = new Date(this.focusedDate);
        const currentDay = month.getDate();
        month.setMonth(month.getMonth() - 1, 1);
        const lastDayOfPrevMonth = new Date(month.getFullYear(), month.getMonth() + 1, 0).getDate();
        month.setDate(Math.min(currentDay, lastDayOfPrevMonth));
        this.afInitSelectedMonth = month.getMonth();
        this.focusedDate = month;
    }
    addMonth() {
        const month = new Date(this.focusedDate);
        const currentDay = month.getDate();
        month.setMonth(month.getMonth() + 1, 1);
        const lastDayOfNextMonth = new Date(month.getFullYear(), month.getMonth() + 1, 0).getDate();
        month.setDate(Math.min(currentDay, lastDayOfNextMonth));
        this.afInitSelectedMonth = month.getMonth();
        this.focusedDate = month;
    }
    getCurrent(date) {
        return this.isSameDate(date, new Date()) ? 'date' : null;
    }
    setTabIndex(date) {
        if (this.dirty) {
            return this.isSameDate(date, this.focusedDate) ? 0 : -1;
        }
        else {
            return this.isSameMonth(date, new Date())
                ? this.isSameDate(date, new Date()) && !this.isInAnotherMonth(date)
                    ? 0
                    : -1
                : this.isSameMonth(date, this.focusedDate) && date.getDate() === 1
                    ? 0
                    : -1;
        }
    }
    navigateHandler(e, daysToAdd) {
        !!e.detail && e.detail.preventDefault();
        if (e.detail.key === 'Tab') {
            return;
        }
        this.onDirty();
        const date = new Date(e.detail.target.dataset.date);
        const newDate = new Date(date.setDate(date.getDate() + daysToAdd));
        this.focusedDate = newDate;
        this.afInitSelectedMonth = this.focusedDate.getMonth();
        this.resetFocus();
    }
    resetFocus() {
        setTimeout(() => {
            const dates = this._tbody.querySelectorAll('.digi-calendar__date');
            if (dates.length <= 0) {
                logger.warn(`Could not find an element with data-date attribute matching navigated date.`, this._tbody);
                return;
            }
            Array.from(dates).map((date) => {
                const d = date;
                d.tabIndex = -1;
                d.classList.remove('digi-calendar__date--focused');
                if (d.dataset.date === this.getFullDate(this.focusedDate)) {
                    d.focus();
                    d.tabIndex = 0;
                    d.classList.add('digi-calendar__date--focused');
                }
            });
        }, 100);
    }
    getFullDate(date) {
        return date.toLocaleString(_t.locale, {
            day: 'numeric',
            month: 'numeric',
            year: 'numeric'
        });
    }
    getDateName(date) {
        return date.toLocaleString(_t.locale, {
            year: 'numeric',
            month: 'long',
            day: 'numeric'
        });
    }
    setFocused(date) {
        if (this.dirty) {
            return this.isSameDate(date, this.focusedDate);
        }
        else {
            return this.isSameMonth(date, new Date())
                ? this.isSameDate(date, new Date()) && !this.isInAnotherMonth(date)
                : this.isSameMonth(date, this.focusedDate) && date.getDate() === 1;
        }
    }
    ariaPressed(date) {
        return this.selectedDates.length > 0 &&
            !!this.selectedDates.find((d) => this.isSameDate(d, date))
            ? 'true'
            : 'false';
    }
    selectMonth(evt) {
        const tempDate = new Date(this.focusedDate);
        const selectedMonth = parseInt(evt.target.value, 10);
        const currentDay = tempDate.getDate();
        tempDate.setMonth(selectedMonth, 1);
        const lastDayOfSelectedMonth = new Date(tempDate.getFullYear(), selectedMonth + 1, 0).getDate();
        tempDate.setDate(Math.min(currentDay, lastDayOfSelectedMonth));
        this.afInitSelectedMonth = selectedMonth;
        this.focusedDate = tempDate;
        this.drawCalendar(this.focusedDate);
    }
    selectYear(evt) {
        const tempDate = this.focusedDate;
        tempDate.setFullYear(evt.target.value);
        this.afInitSelectedDate = evt.target.value;
        this.focusedDate = tempDate;
        this.drawCalendar(this.focusedDate);
    }
    earliestSelectableYear() {
        if (this.afMinDate)
            return this.afMinDate.getFullYear();
        return 1900;
    }
    latestSelectableYear() {
        if (this.afMaxDate)
            return this.afMaxDate.getFullYear();
        return new Date(Date.now()).getFullYear() + 10;
    }
    allSelectableYears() {
        const allYears = [];
        let currentYear = this.earliestSelectableYear();
        while (currentYear <= this.latestSelectableYear()) {
            allYears.push(currentYear++);
        }
        return allYears;
    }
    componentWillLoad() {
        if (this.afInitSelectedDate) {
            this.afInitSelectedMonth = this.afInitSelectedDate.getMonth();
            this.focusedDate = this.afInitSelectedDate;
            this.drawCalendar(this.afInitSelectedDate);
        }
        else {
            const startSelectedMonth = new Date(new Date().getFullYear(), this.afInitSelectedMonth);
            this.focusedDate = startSelectedMonth;
            this.drawCalendar(startSelectedMonth);
        }
    }
    componentWillUpdate() {
        this.drawCalendar(this.focusedDate);
    }
    async componentDidLoad() {
        if (isValid(this.afSelectedDate))
            this.selectedDates = [this.afSelectedDate];
        else
            this.afSelectedDatesChangeHandler();
        await customElements.whenDefined('digi-form-select');
    }
    cssDateModifiers(date) {
        const shownMonth = this.focusedDate.getMonth();
        return {
            'digi-calendar__date--today': this.isSameDate(date, new Date()) && !this.isInAnotherMonth(date),
            'digi-calendar__date--disabled': this.isInAnotherMonth(date),
            'digi-calendar__date--focused': this.setFocused(date),
            'digi-calendar__date--selected': this.isDateSelected(date) && date.getMonth() === shownMonth,
            'digi-calendar__date--not-selectable': !this.isInAnotherMonth(date) && !this.isDateSelectable(date)
        };
    }
    render() {
        return (h("div", { key: 'f2d44d7100e9aec3a91c56663360624f83745c0f', class: {
                'digi-calendar': true,
                'digi-calendar--hide': !this.afActive
            }, id: `${this.afId}-calendar` }, this.afYearSelect && (h("div", { key: 'fbc3332a363201be4ece13ce849fa10ab324ac13', class: "digi-calendar__header" }, h("div", { key: '88de6a25891a17617d6d59cc79ff40a16c1f8467', class: "digi-calendar__header--year-select" }, h("digi-form-select", { key: 'bf76a067c841709388f5d8d9dc7ce572f370ca49', afLabel: "M\u00E5nad", "af-variation": "small", afValue: this.focusedDate.getMonth().toString(), onAfOnSelect: (evt) => {
                this.selectMonth(evt);
            } }, this.months.map((month, index) => {
            return h("option", { value: index }, month);
        })), h("digi-form-select", { key: '8f822faced5e7dff2aa72a0ce678ea1013d9e299', afLabel: "\u00C5r", "af-variation": "small", afValue: this.focusedDate.getFullYear().toString(), onAfOnSelect: (evt) => {
                this.selectYear(evt);
            } }, this.allSelectableYears().map((year) => (h("option", { value: year.toString() }, year))))))), !this.afYearSelect && (h("div", { key: 'f51013760c858eb00656e8596fb04adb619cc0eb', class: "digi-calendar__header" }, h("div", { key: 'a37f3fd65b74345d4c8bfeaa64185a0ba046317d', class: "digi-calendar__header--month-step" }, h("button", { key: 'da8f4803fc250194a567bcc7df6582adb35f8510', class: "digi-calendar__month-select-button", type: "button", "aria-label": this.getFullMonthName(this.afInitSelectedMonth - 1) +
                ', föregående månad', onClick: () => this.subtractMonth() }, h("digi-icon-chevron-left", { key: '6019efab7ae1dc1fa643459d7c2b5feb977cf6aa', slot: "icon", "aria-hidden": "true" }), h("span", { key: 'f5e14ed6c5e6cbf31bceeed46bf78454a30e76d5', class: "digi-calendar__month-select-name" }, this.getMonthName(this.afInitSelectedMonth - 1))), h("div", { key: '5426dea9943af11f1e537318b44450c4504f63a4', class: "digi-calendar__month" }, this.getFullMonthName(this.afInitSelectedMonth)), h("button", { key: '8c836f8ed0b7027569fdb9b2fec5d295d0fc417e', class: "digi-calendar__month-select-button", type: "button", "aria-label": this.getFullMonthName(this.afInitSelectedMonth + 1) +
                ', nästa månad', onClick: () => this.addMonth() }, h("span", { key: '9403efa5fa67432f7f23f885d8f99ebc54473516', class: "digi-calendar__month-select-name" }, this.getMonthName(this.afInitSelectedMonth + 1)), h("digi-icon-chevron-right", { key: '02eafcde2c6327a23e8ffe82682430af43eb4d02', slot: "icon", "aria-hidden": "true" }))))), h("digi-util-keydown-handler", { key: '233fc35cb48bf86f84fb8c781a5bdf1e53c153c5', onAfOnDown: (e) => this.navigateHandler(e, 7), onAfOnUp: (e) => this.navigateHandler(e, -7), onAfOnLeft: (e) => this.navigateHandler(e, -1), onAfOnRight: (e) => this.navigateHandler(e, 1) }, h("table", { key: 'ea2e505e70411a3d07119130b0788dafbbbeef07', role: "grid", class: "digi-calendar__table" }, h("thead", { key: 'eace14b22601d0f85cf6f8c276716491140389fb' }, h("tr", { key: 'f6678cdfa52220c5e19729fc7bc567ba8c5e06c6', role: "row" }, this.afShowWeekNumber && (h("th", { key: '7fa670bd34fd0186c8f154ed6cac0481c30b90cd', role: "columnheader", abbr: _t.calendar.week, class: "digi-calendar__table-header-week" }, _t.calendar.week.toLowerCase())), Object.keys(_t.calendar.weekdays).map((day) => (h("th", { role: "columnheader", "aria-label": _t.calendar.weekdays[day], abbr: _t.calendar.weekdays[day], class: "digi-calendar__table-header" }, _t.calendar.weekdays_short[day].toLowerCase()))))), h("tbody", { key: '7ecdf08d9a497dfe74f7e95b3d89566ea8789489', ref: (el) => (this._tbody = el) }, this.activeCalendar.map((week) => {
            return (h("tr", null, week.map((day, i) => {
                if (this.afShowWeekNumber && i === 0) {
                    return (h("th", { role: "rowheader", "aria-label": _t.calendar.week + ' ' + day, class: "digi-calendar__td-week digi-calendar__date--week-number", id: 'digi-calendar__week-' + day }, day));
                }
                else {
                    return this.isInAnotherMonth(day) ? (h("td", null)) : (h("td", { role: "gridcell", class: "digi-calendar__td" }, h("button", { key: this.getFullDate(day), type: "button", class: Object.assign(Object.assign({}, this.cssDateModifiers(day)), { 'digi-calendar__date': true }), onClick: () => this.selectDateHandler(day), "aria-current": this.isSameDate(day, new Date()) ? 'date' : null, "aria-label": `
                                ${!this.isDateSelectable(day)
                            ? _t.calendar.disabledDate
                            : ''} ${this.getDateName(day)}
                              `, "aria-disabled": !this.isDateSelectable(day) ? 'true' : null, tabindex: this.setTabIndex(day), "data-date": this.getFullDate(day), "aria-pressed": this.isDateSelectable(day)
                            ? this.ariaPressed(day)
                            : null }, h("span", { "aria-hidden": "true" }, day.getDate()))));
                }
            })));
        })))), h("slot", { key: 'ed2cf3c305f6db73a00e838beb786fc088045634', name: "calendar-footer" })));
    }
    static get watchers() { return {
        "afSelectedDate": ["afSelectedDateChangeHandler"],
        "afSelectedDates": ["afSelectedDatesChangeHandler"]
    }; }
    static get style() { return DigiCalendarStyle0; }
}, [6, "digi-calendar", {
        "afId": [1, "af-id"],
        "afInitSelectedMonth": [2, "af-init-selected-month"],
        "afInitSelectedDate": [16],
        "afShowWeekNumber": [4, "af-show-week-number"],
        "afSelectedDate": [16],
        "afSelectedDates": [16],
        "afActive": [4, "af-active"],
        "afMinDate": [16],
        "afMaxDate": [16],
        "afMultipleDates": [4, "af-multiple-dates"],
        "afYearSelect": [4, "af-year-select"],
        "selectedDates": [32],
        "focusedDate": [32],
        "dirty": [32]
    }, [[4, "focusin", "focusoutHandler"], [8, "click", "clickHandler"]], {
        "afSelectedDate": ["afSelectedDateChangeHandler"],
        "afSelectedDates": ["afSelectedDatesChangeHandler"]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["digi-calendar", "digi-form-label", "digi-form-select", "digi-form-validation-message", "digi-icon-chevron-left", "digi-icon-chevron-right", "digi-icon-input-select-marker", "digi-icon-validation-error", "digi-icon-validation-success", "digi-icon-validation-warning", "digi-util-keydown-handler", "digi-util-mutation-observer"];
    components.forEach(tagName => { switch (tagName) {
        case "digi-calendar":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, Calendar);
            }
            break;
        case "digi-form-label":
            if (!customElements.get(tagName)) {
                defineCustomElement$b();
            }
            break;
        case "digi-form-select":
            if (!customElements.get(tagName)) {
                defineCustomElement$a();
            }
            break;
        case "digi-form-validation-message":
            if (!customElements.get(tagName)) {
                defineCustomElement$9();
            }
            break;
        case "digi-icon-chevron-left":
            if (!customElements.get(tagName)) {
                defineCustomElement$8();
            }
            break;
        case "digi-icon-chevron-right":
            if (!customElements.get(tagName)) {
                defineCustomElement$7();
            }
            break;
        case "digi-icon-input-select-marker":
            if (!customElements.get(tagName)) {
                defineCustomElement$6();
            }
            break;
        case "digi-icon-validation-error":
            if (!customElements.get(tagName)) {
                defineCustomElement$5();
            }
            break;
        case "digi-icon-validation-success":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "digi-icon-validation-warning":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "digi-util-keydown-handler":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "digi-util-mutation-observer":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { Calendar as C, isAfter as a, defineCustomElement as d, isBefore as i };
