'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-7a477838.js');
const randomIdGenerator_util = require('./randomIdGenerator.util-e7f4b6de.js');
const detectClickOutside_util = require('./detectClickOutside.util-3e764eb3.js');
const detectFocusOutside_util = require('./detectFocusOutside.util-03c62976.js');
const logger_util = require('./logger.util-fdafc086.js');
const text = require('./text-3157012b.js');
const index$1 = require('./index-e8333bcc.js');
const index$2 = require('./index-cad91a90.js');
require('./detectClosest.util-85b3507b.js');

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 = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.afOnDateSelectedChange = index.createEvent(this, "afOnDateSelectedChange", 7);
        this.afOnFocusOutside = index.createEvent(this, "afOnFocusOutside", 7);
        this.afOnClickOutside = index.createEvent(this, "afOnClickOutside", 7);
        this.afOnDirty = index.createEvent(this, "afOnDirty", 7);
        this.activeCalendar = [];
        this.months = [];
        this.selectedDates = [];
        this.focusedDate = undefined;
        this.dirty = false;
        this.afId = randomIdGenerator_util.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 (index$1.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) => !index$1.isValid(date));
                if (invalidDate === undefined) {
                    this.selectedDates = this.afSelectedDates;
                }
            }
            else if (index$1.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_util.detectFocusOutside(target, selector)) {
            this.afOnFocusOutside.emit(e);
        }
    }
    clickHandler(e) {
        const target = e.target;
        const selector = `#${this.afId}-calendar`;
        if (detectClickOutside_util.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 index$2.isBefore(this.dateWithoutTime(a), this.dateWithoutTime(b));
    }
    isAfter(a, b) {
        return index$2.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_util.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(text._t.locale, {
            day: 'numeric',
            month: 'numeric',
            year: 'numeric'
        });
    }
    getDateName(date) {
        return date.toLocaleString(text._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 (index$1.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 (index.h("div", { key: 'f2d44d7100e9aec3a91c56663360624f83745c0f', class: {
                'digi-calendar': true,
                'digi-calendar--hide': !this.afActive
            }, id: `${this.afId}-calendar` }, this.afYearSelect && (index.h("div", { key: 'fbc3332a363201be4ece13ce849fa10ab324ac13', class: "digi-calendar__header" }, index.h("div", { key: '88de6a25891a17617d6d59cc79ff40a16c1f8467', class: "digi-calendar__header--year-select" }, index.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$1) => {
            return index.h("option", { value: index$1 }, month);
        })), index.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) => (index.h("option", { value: year.toString() }, year))))))), !this.afYearSelect && (index.h("div", { key: 'f51013760c858eb00656e8596fb04adb619cc0eb', class: "digi-calendar__header" }, index.h("div", { key: 'a37f3fd65b74345d4c8bfeaa64185a0ba046317d', class: "digi-calendar__header--month-step" }, index.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() }, index.h("digi-icon-chevron-left", { key: '6019efab7ae1dc1fa643459d7c2b5feb977cf6aa', slot: "icon", "aria-hidden": "true" }), index.h("span", { key: 'f5e14ed6c5e6cbf31bceeed46bf78454a30e76d5', class: "digi-calendar__month-select-name" }, this.getMonthName(this.afInitSelectedMonth - 1))), index.h("div", { key: '5426dea9943af11f1e537318b44450c4504f63a4', class: "digi-calendar__month" }, this.getFullMonthName(this.afInitSelectedMonth)), index.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() }, index.h("span", { key: '9403efa5fa67432f7f23f885d8f99ebc54473516', class: "digi-calendar__month-select-name" }, this.getMonthName(this.afInitSelectedMonth + 1)), index.h("digi-icon-chevron-right", { key: '02eafcde2c6327a23e8ffe82682430af43eb4d02', slot: "icon", "aria-hidden": "true" }))))), index.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) }, index.h("table", { key: 'ea2e505e70411a3d07119130b0788dafbbbeef07', role: "grid", class: "digi-calendar__table" }, index.h("thead", { key: 'eace14b22601d0f85cf6f8c276716491140389fb' }, index.h("tr", { key: 'f6678cdfa52220c5e19729fc7bc567ba8c5e06c6', role: "row" }, this.afShowWeekNumber && (index.h("th", { key: '7fa670bd34fd0186c8f154ed6cac0481c30b90cd', role: "columnheader", abbr: text._t.calendar.week, class: "digi-calendar__table-header-week" }, text._t.calendar.week.toLowerCase())), Object.keys(text._t.calendar.weekdays).map((day) => (index.h("th", { role: "columnheader", "aria-label": text._t.calendar.weekdays[day], abbr: text._t.calendar.weekdays[day], class: "digi-calendar__table-header" }, text._t.calendar.weekdays_short[day].toLowerCase()))))), index.h("tbody", { key: '7ecdf08d9a497dfe74f7e95b3d89566ea8789489', ref: (el) => (this._tbody = el) }, this.activeCalendar.map((week) => {
            return (index.h("tr", null, week.map((day, i) => {
                if (this.afShowWeekNumber && i === 0) {
                    return (index.h("th", { role: "rowheader", "aria-label": text._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) ? (index.h("td", null)) : (index.h("td", { role: "gridcell", class: "digi-calendar__td" }, index.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)
                            ? text._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 }, index.h("span", { "aria-hidden": "true" }, day.getDate()))));
                }
            })));
        })))), index.h("slot", { key: 'ed2cf3c305f6db73a00e838beb786fc088045634', name: "calendar-footer" })));
    }
    static get watchers() { return {
        "afSelectedDate": ["afSelectedDateChangeHandler"],
        "afSelectedDates": ["afSelectedDatesChangeHandler"]
    }; }
};
Calendar.style = DigiCalendarStyle0;

const iconCalendarAltCss = ".sc-digi-icon-calendar-alt-h{--digi--icon--color:var(--digi--color--icon--primary);--digi--icon--width:initial;--digi--icon--height:auto;display:flex;min-height:1.4em;align-items:center}.sc-digi-icon-calendar-alt-h svg.sc-digi-icon-calendar-alt{color:var(--digi--icon--color);max-width:var(--digi--icon--width);max-height:var(--digi--icon--height);width:var(--digi--icon--width, auto);height:var(--digi--icon--height, auto)}";
const DigiIconCalendarAltStyle0 = iconCalendarAltCss;

const IconCalendarAlt = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.afTitle = undefined;
        this.afDesc = undefined;
        this.afSvgAriaHidden = true;
        this.afSvgAriaLabelledby = undefined;
        this.titleId = randomIdGenerator_util.randomIdGenerator('icontitle');
    }
    render() {
        return (index.h("svg", { key: '8fa5ed3d91d5451738f3237262ff47aafc709ac7', class: "digi-icon-calendar-alt", width: "22", height: "26", viewBox: "0 0 22 26", "aria-hidden": this.afSvgAriaHidden ? 'true' : 'false', "aria-labelledby": this.afSvgAriaLabelledby
                ? this.afSvgAriaLabelledby
                : this.afTitle
                    ? this.titleId
                    : undefined, xmlns: "http://www.w3.org/2000/svg" }, this.afTitle && index.h("title", { key: 'd9205afd3cd9e8d3c7e39688fba26ac675ce2453', id: this.titleId }, this.afTitle), this.afDesc && index.h("desc", { key: '2d0c3d12c0ed358ddbb0d4144ae5cfce0d2ed1e0' }, this.afDesc), index.h("path", { key: 'b705ac5c5f77bb160509a716f9905a9ff94ef083', class: "digi-icon-calendar-alt__shape", d: "M21.41 8.125H.59a.601.601 0 01-.59-.61V5.689C0 4.341 1.056 3.25 2.357 3.25h2.357V.61c0-.336.265-.61.59-.61h1.964c.324 0 .59.274.59.61v2.64h6.285V.61c0-.336.265-.61.59-.61h1.963c.325 0 .59.274.59.61v2.64h2.357C20.944 3.25 22 4.342 22 5.688v1.828c0 .335-.265.609-.59.609zM.59 9.75h20.82c.325 0 .59.274.59.61v13.203C22 24.907 20.944 26 19.643 26H2.357C1.056 26 0 24.908 0 23.562V10.36c0-.335.265-.609.59-.609zm5.696 10.36a.601.601 0 00-.59-.61H3.732a.601.601 0 00-.59.61v2.03c0 .336.266.61.59.61h1.964c.325 0 .59-.274.59-.61v-2.03zm0-6.5a.601.601 0 00-.59-.61H3.732a.601.601 0 00-.59.61v2.03c0 .336.266.61.59.61h1.964c.325 0 .59-.274.59-.61v-2.03zm6.285 6.5a.601.601 0 00-.589-.61h-1.964a.601.601 0 00-.59.61v2.03c0 .336.266.61.59.61h1.964c.324 0 .59-.274.59-.61v-2.03zm0-6.5a.601.601 0 00-.589-.61h-1.964a.601.601 0 00-.59.61v2.03c0 .336.266.61.59.61h1.964c.324 0 .59-.274.59-.61v-2.03zm6.286 6.5a.601.601 0 00-.59-.61h-1.963a.601.601 0 00-.59.61v2.03c0 .336.265.61.59.61h1.964c.324 0 .59-.274.59-.61v-2.03zm0-6.5a.601.601 0 00-.59-.61h-1.963a.601.601 0 00-.59.61v2.03c0 .336.265.61.59.61h1.964c.324 0 .59-.274.59-.61v-2.03z", fill: "currentColor", "fill-rule": "nonzero" })));
    }
};
IconCalendarAlt.style = DigiIconCalendarAltStyle0;

exports.digi_calendar = Calendar;
exports.digi_icon_calendar_alt = IconCalendarAlt;
