import { h } from "@stencil/core";
import { isAfter, isBefore, isValid } from "date-fns";
import { randomIdGenerator } from "../../../global/utils/randomIdGenerator";
import { detectClickOutside } from "../../../global/utils/detectClickOutside";
import { detectFocusOutside } from "../../../global/utils/detectFocusOutside";
import { logger } from "../../../global/utils/logger";
import { _t } from "../../../text";
/**
 * @swedishName Kalender
 */
export class Calendar {
    constructor() {
        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 is() { return "digi-calendar"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "$": ["calendar.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["calendar.css"]
        };
    }
    static get properties() {
        return {
            "afId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Prefix for all id attributes inside the component. Example: 'my-cool-id' generates 'my-cool-id-calendar' and so on. Defaults to random string."
                        }],
                    "text": "Prefix f\u00F6r komponentens alla olika interna 'id'-attribut p\u00E5 kalendern etc. Ex. 'my-cool-id' genererar 'my-cool-id-calendar' osv. Ges inget v\u00E4rde genereras ett slumpm\u00E4ssigt."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-id",
                "reflect": false,
                "defaultValue": "randomIdGenerator('digi-calendar')"
            },
            "afInitSelectedMonth": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Selected month to display from start. Defaults to the month of todays month. (Januray = 0, December = 11)"
                        }],
                    "text": "Vald m\u00E5nad att visa fr\u00E5n start. F\u00F6rvalt \u00E4r den m\u00E5nad som dagens datum har. (Januari = 0, December = 11)"
                },
                "getter": false,
                "setter": false,
                "attribute": "af-init-selected-month",
                "reflect": false,
                "defaultValue": "new Date().getMonth()"
            },
            "afInitSelectedDate": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "Date",
                    "resolved": "Date",
                    "references": {
                        "Date": {
                            "location": "global",
                            "id": "global::Date"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Selected month and year to display from start. Defaults to todays month and year."
                        }],
                    "text": "Valt m\u00E5ndad och \u00E5r fr\u00E5n start. F\u00F6rvalt \u00E4r dagens m\u00E5nad och \u00E5r."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "new Date()"
            },
            "afShowWeekNumber": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Show week number in the calander. Default is false"
                        }],
                    "text": "Visa veckonummer i kalender. F\u00F6rvalt \u00E4r false"
                },
                "getter": false,
                "setter": false,
                "attribute": "af-show-week-number",
                "reflect": false,
                "defaultValue": "false"
            },
            "afSelectedDate": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "Date",
                    "resolved": "Date",
                    "references": {
                        "Date": {
                            "location": "global",
                            "id": "global::Date"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Selected date in calendar"
                        }],
                    "text": "Valt datum i kalendern"
                },
                "getter": false,
                "setter": false
            },
            "afSelectedDates": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "Date[]",
                    "resolved": "Date[]",
                    "references": {
                        "Date": {
                            "location": "global",
                            "id": "global::Date"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Selected dates in calendar"
                        }],
                    "text": "Valda datum i kalendern"
                },
                "getter": false,
                "setter": false,
                "defaultValue": "[]"
            },
            "afActive": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Toggle calendar hide/show. Defaults to true"
                        }],
                    "text": "Visar d\u00F6ljer kalendern. Visas som f\u00F6rvalt"
                },
                "getter": false,
                "setter": false,
                "attribute": "af-active",
                "reflect": false,
                "defaultValue": "true"
            },
            "afMinDate": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "Date",
                    "resolved": "Date",
                    "references": {
                        "Date": {
                            "location": "global",
                            "id": "global::Date"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Earliest selectable date"
                        }],
                    "text": "Tidigaste valbara datumet"
                },
                "getter": false,
                "setter": false
            },
            "afMaxDate": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "Date",
                    "resolved": "Date",
                    "references": {
                        "Date": {
                            "location": "global",
                            "id": "global::Date"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Latest selectable date"
                        }],
                    "text": "Senaste valbara datumet"
                },
                "getter": false,
                "setter": false
            },
            "afMultipleDates": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Set this to true to be able to select multiple dates in the calander. Default is false"
                        }],
                    "text": "S\u00E4tt denna till true f\u00F6r att kunna markera mer en ett datum i kalendern. F\u00F6rvalt \u00E4r false"
                },
                "getter": false,
                "setter": false,
                "attribute": "af-multiple-dates",
                "reflect": false,
                "defaultValue": "false"
            },
            "afYearSelect": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Set this to true to be able to select year through a select component. Default is false"
                        }],
                    "text": "S\u00E4tt denna till true f\u00F6r att kunna v\u00E4lja \u00E5r genom en v\u00E4ljare. F\u00F6rvalt \u00E4r false"
                },
                "getter": false,
                "setter": false,
                "attribute": "af-year-select",
                "reflect": false,
                "defaultValue": "false"
            }
        };
    }
    static get states() {
        return {
            "selectedDates": {},
            "focusedDate": {},
            "dirty": {}
        };
    }
    static get events() {
        return [{
                "method": "afOnDateSelectedChange",
                "name": "afOnDateSelectedChange",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "When a date is selected. Return the dates in an array."
                        }],
                    "text": "Sker n\u00E4r ett datum har valts eller avvalts. Returnerar datumen i en array."
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }, {
                "method": "afOnFocusOutside",
                "name": "afOnFocusOutside",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "When focus moves out from the calendar"
                        }],
                    "text": "Sker n\u00E4r fokus flyttas utanf\u00F6r kalendern"
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }, {
                "method": "afOnClickOutside",
                "name": "afOnClickOutside",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "When click outside the calendar"
                        }],
                    "text": "Sker vid klick utanf\u00F6r kalendern"
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }, {
                "method": "afOnDirty",
                "name": "afOnDirty",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "When the calendar dates are touched the first time, when focusedDate is changed the first time."
                        }],
                    "text": "Sker n\u00E4r kalenderdatumen har r\u00F6rts f\u00F6rsta g\u00E5ngen, n\u00E4r v\u00E4rdet p\u00E5 focusedDate har \u00E4ndrats f\u00F6rsta g\u00E5ngen."
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }];
    }
    static get watchers() {
        return [{
                "propName": "afSelectedDate",
                "methodName": "afSelectedDateChangeHandler"
            }, {
                "propName": "afSelectedDates",
                "methodName": "afSelectedDatesChangeHandler"
            }];
    }
    static get listeners() {
        return [{
                "name": "focusin",
                "method": "focusoutHandler",
                "target": "document",
                "capture": false,
                "passive": false
            }, {
                "name": "click",
                "method": "clickHandler",
                "target": "window",
                "capture": false,
                "passive": false
            }];
    }
}
