// #region Imports
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var DateTimeBoxElement_1;
import { Key } from '../../../../Controls/Types/Key';
import { DomServiceLocator } from '../../../../Dom/Dom';
import { isDate } from '../../../../Extensions/DateExtensions';
import { DateTimeFormatter } from '../../../../Intl/Formatters/DateTimeFormatter';
import { DateParser } from '../../../../Intl/parsers/DateParser';
import { Appearanceable } from '../../../Behaviors/Appearanceable';
import { Clearable } from '../../../Behaviors/Clearable';
import { Disableable } from '../../../Behaviors/Disableable';
import { DropDownable } from '../../../Behaviors/DropDownable';
import { Invalidable } from '../../../Behaviors/Invalidable';
import { Labelable } from '../../../Behaviors/Labelable';
import { Localeable } from '../../../Behaviors/Localeable';
import { Slottable } from '../../../Behaviors/Slottable';
import { Themeable } from '../../../Behaviors/Themeable';
import { Valueable } from '../../../Behaviors/Valueable';
import { Variantable } from '../../../Behaviors/Variantable';
import { ClickOutsideController } from '../../../Controllers/ClickOutsideController';
import { KeyboardController } from '../../../Controllers/KeyboardController';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Property } from '../../../Decorators/PropertyDecorator';
import { Watch } from '../../../Decorators/WatchDecorator';
import { CalendarView } from '../../../Types/CalendarView';
import { DayOfWeek } from '../../../Types/DayOfWeek';
import { TextAlignment } from '../../../Types/TextAlignment';
import { IconElement } from '../../Media/Icon/IconElement';
import { FloatingElement } from '../../Primitives/Floating/FloatingElement';
import { FocusRingElement } from '../../Primitives/FocusRing/FocusRingElement';
import { PopupElement } from '../../Primitives/Popup/PopupElement';
import { PortalElement } from '../../Primitives/Portal/PortalElement';
import { ProjectionController } from '../../Primitives/Portal/ProjectionController';
import { WheelPickerElement } from '../../Primitives/WheelPicker/WheelPickerElement';
import { InputBaseElement } from '../Abstracts/InputBase';
import { CalendarElement } from '../Calendar/CalendarElement';
import { dateTimeBoxElementTemplate } from './DateTimeBoxElementTemplate';
import { dateTimeBoxElementCosmopolitanStyle } from './Themes/DateTimeBoxElement.Cosmopolitan';
import { dateTimeBoxElementJoyStyle } from './Themes/DateTimeBoxElement.Joy';
import { dateTimeBoxElementMemphisStyle } from './Themes/DateTimeBoxElement.Memphis';
// #endregion
/**
 * Date Time Box - A user interface component for selecting date and time values.
 *
 * @description
 * The Datetime Box component allows users to select both date and time values.
 * It provides a user-friendly interface for choosing dates using a calendar picker and time using dropdowns or input fields.
 * Datetime boxes are commonly used in scheduling applications, forms, and event planners.
 *
 * @element mosaik-datetimebox
 * @category Forms
 *
 * @slot prefix - The prefix slot.
 * @slot suffix - The suffix slot.
 *
 * @csspart ampm-button - The ampm-button part.
 * @csspart ampm-toggle - The ampm-toggle part.
 * @csspart calendar - The calendar part.
 * @csspart clear - The clear part.
 * @csspart datetime-content - The datetime-content part.
 * @csspart focusRing - The focusRing part.
 * @csspart hour-column - The hour-column part.
 * @csspart inner - The inner part.
 * @csspart input - The input part.
 * @csspart label - The label part.
 * @csspart minute-column - The minute-column part.
 * @csspart picker - The picker part.
 * @csspart popup - The popup part.
 * @csspart portal - The portal part.
 * @csspart prefix - The prefix part.
 * @csspart suffix - The suffix part.
 * @csspart time-columns - The time-columns part.
 * @csspart time-divider - The time-divider part.
 * @csspart time-picker - The time-picker part.
 *
 * @cssprop {String} --date-time-box-background-color - The time box background color CSS custom property.
 * @cssprop {String} --date-time-box-border-color - The time box border color CSS custom property.
 * @cssprop {String} --date-time-box-border-radius - The time box border radius CSS custom property.
 * @cssprop {String} --date-time-box-border-style - The time box border style CSS custom property.
 * @cssprop {String} --date-time-box-border-width - The time box border width CSS custom property.
 * @cssprop {String} --date-time-box-font-family - The time box font family CSS custom property.
 * @cssprop {String} --date-time-box-font-letter-spacing - The time box font letter spacing CSS custom property.
 * @cssprop {String} --date-time-box-font-line-height - The time box font line height CSS custom property.
 * @cssprop {String} --date-time-box-font-size - The time box font size CSS custom property.
 * @cssprop {String} --date-time-box-font-text-decoration - The time box font text decoration CSS custom property.
 * @cssprop {String} --date-time-box-font-text-transform - The time box font text transform CSS custom property.
 * @cssprop {String} --date-time-box-font-weight - The time box font weight CSS custom property.
 * @cssprop {String} --date-time-box-foreground-color - The time box foreground color CSS custom property.
 * @cssprop {String} --date-time-box-gap - The time box gap CSS custom property.
 * @cssprop {String} --date-time-box-height - The time box height CSS custom property.
 * @cssprop {String} --date-time-box-padding-bottom - The time box padding bottom CSS custom property.
 * @cssprop {String} --date-time-box-padding-left - The time box padding left CSS custom property.
 * @cssprop {String} --date-time-box-padding-right - The time box padding right CSS custom property.
 * @cssprop {String} --date-time-box-padding-top - The time box padding top CSS custom property.
 * @cssprop {String} --date-time-box-shadow - The time box shadow CSS custom property.
 * @cssprop {String} --date-time-box-shadow-blur - The time box shadow blur CSS custom property.
 * @cssprop {String} --date-time-box-shadow-color - The time box shadow color CSS custom property.
 * @cssprop {String} --date-time-box-shadow-offset-x - The time box shadow offset x CSS custom property.
 * @cssprop {String} --date-time-box-shadow-offset-y - The time box shadow offset y CSS custom property.
 * @cssprop {String} --date-time-box-shadow-spread - The time box shadow spread CSS custom property.
 * @cssprop {String} --date-time-box-transition-duration - The time box transition duration CSS custom property.
 * @cssprop {String} --date-time-box-transition-mode - The time box transition mode CSS custom property.
 * @cssprop {String} --date-time-box-transition-property - The time box transition property CSS custom property.
 * @cssprop {String} --date-time-box-translate - The time box translate CSS custom property.
 *
 * @fires cleared {ClearedEvent} - Fired when the value is cleared.
 *
 * @dependency mosaik-button - The Button element.
 * @dependency mosaik-calendar - The Calendar element.
 * @dependency mosaik-floating - The Floating element.
 * @dependency mosaik-focus-ring - The Focus Ring element.
 * @dependency mosaik-portal - The Portal element.
 * @dependency mosaik-wheel-picker - The Wheel Picker element.
 *
 * @example
 * Basic date time picker:
 * ```html
 * <mosaik-datetimebox placeholder="Select date and time" required></mosaik-datetimebox>
 * ```
 *
 * @example
 * With custom format and view:
 * ```html
 * <mosaik-datetimebox
 *   format="dd.MM.yyyy HH:mm"
 *   view="month">
 * </mosaik-datetimebox>
 * ```
 *
 * @public
 *
 * @keyhandle Space - Toggles the dropdown.
 * @keyhandle Enter - Toggles the dropdown.
 * @keyhandle Escape - Closes the dropdown if it is open, otherwise clears the value.
 * @keyhandle Tab - Closes the dropdown.
 */
let DateTimeBoxElement = DateTimeBoxElement_1 = class DateTimeBoxElement extends Themeable(Slottable(Clearable(Localeable(Disableable(Invalidable(Valueable(Variantable(Appearanceable(DropDownable(Labelable(InputBaseElement))))))))))) {
    // #region Fields
    _inputElement;
    _clickOutsideController;
    _keyboardController;
    _projectionController;
    _value;
    _displayValue;
    _readonly;
    _required;
    _autofocus;
    _name;
    _placeholder;
    _autocomplete;
    _values;
    _view;
    _blackoutDates;
    _specialDates;
    _minDate;
    _maxDate;
    _firstDayOfWeek;
    _isTodayHighlighted;
    _isWeekendHighlighted;
    _showWeekNumbers;
    _markerHandler;
    _showAdjacent;
    _allowedViews;
    _showNavigation;
    _format;
    _invalidInput;
    _textAlign;
    _selectedHour;
    _selectedMinute;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._value = new Date();
        this._displayValue = '';
        this._readonly = false;
        this._required = false;
        this._autofocus = false;
        this._name = '';
        this._placeholder = '';
        this._autocomplete = false;
        this._values = new Array();
        this._view = CalendarView.Day;
        this._blackoutDates = new Array();
        this._specialDates = new Array();
        this._minDate = null;
        this._maxDate = null;
        this._firstDayOfWeek = DayOfWeek.Sunday;
        this._isTodayHighlighted = false;
        this._isWeekendHighlighted = false;
        this._showWeekNumbers = false;
        this._markerHandler = (_item) => [];
        this._showAdjacent = false;
        this._allowedViews = [CalendarView.Day, CalendarView.Month, CalendarView.Year];
        this._showNavigation = true;
        this._format = 'yyyy-MM-dd HH:mm:ss';
        this._invalidInput = false;
        this._textAlign = TextAlignment.Left;
        this._selectedHour = new Date().getHours();
        this._selectedMinute = new Date().getMinutes();
        this._clickOutsideController = new ClickOutsideController(this, {
            skipInitial: true,
            ignored: () => {
                const portal = this.shadowRoot?.querySelector('mosaik-portal');
                const projection = portal?.projection;
                return projection ? [projection] : [];
            },
            callback: () => this.close()
        });
        this._keyboardController = new KeyboardController(this);
        this._projectionController = new ProjectionController(this, {
            slotName: '',
            targetSelector: '[part="projection"]',
            projecting: (element) => {
                element.setAttribute(`${DateTimeBoxElement_1.is}-projection`, '');
            }
        });
        // REMARK: This is a workaround for the issue with the docs generation.
        Object.assign(this, { dropDownMaxHeight: 'auto' });
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     * The `is` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-datetimebox';
    }
    /**
     * Returns the `displayDate` property.
     * The `displayDate` property represents the initial date to display in the calendar.
     *
     * @public
     */
    get displayDate() {
        return this.value;
    }
    set displayDate(value) {
        this.value = value;
    }
    /**
     * Returns the `displayDateStart` property.
     * The `displayDateStart` property represents the start date to display in the calendar.
     *
     * @public
     */
    get displayDateStart() {
        return this._value;
    }
    set displayDateStart(value) {
        this._value = value;
    }
    /**
     * Returns the `displayDateEnd` property.
     * The `displayDateEnd` property represents the end date to display in the calendar.
     *
     * @public
     */
    get displayDateEnd() {
        return this._value;
    }
    set displayDateEnd(value) {
        this._value = value;
    }
    /**
     * Gets or sets the `value` property.
     *
     * @public
     * @override
     */
    get value() {
        return this._value;
    }
    set value(value) {
        if (!isValidValue(value)) {
            value = null;
        }
        if (this._value !== value) {
            this._value = value;
            if (isDate(value)) {
                this._selectedHour = value.getHours();
                this._selectedMinute = value.getMinutes();
            }
            this.requestUpdate('value');
        }
    }
    /**
     * Gets or sets the `displayValue` property.
     *
     * @public
     * @readonly
     */
    get displayValue() {
        return this._displayValue;
    }
    set displayValue(value) {
        if (this._displayValue !== value) {
            this._displayValue = value;
            this.requestUpdate('displayValue');
        }
    }
    /**
     * Gets or sets the `readonly` property.
     *
     * @public
     * @attr
     */
    get readonly() {
        return this._readonly;
    }
    set readonly(value) {
        if (this._readonly !== value) {
            this._readonly = value;
            this.requestUpdate('readonly');
        }
    }
    /**
     * Gets or sets the `required` property.
     *
     * @public
     * @attr
     */
    get required() {
        return this._required;
    }
    set required(value) {
        if (this._required !== value) {
            this._required = value;
            this.requestUpdate('required');
        }
    }
    /**
     * Gets or sets the `autofocus` property.
     *
     * @public
     * @override
     */
    get autofocus() {
        return this._autofocus;
    }
    set autofocus(value) {
        if (this._autofocus !== value) {
            this._autofocus = value;
            this.requestUpdate('autofocus');
        }
    }
    /**
     * Gets or sets the `name` property.
     *
     * @public
     * @attr
     */
    get name() {
        return this._name;
    }
    set name(value) {
        if (this._name !== value) {
            this._name = value;
            this.requestUpdate('name');
        }
    }
    /**
     * Gets or sets the `placeholder` property.
     *
     * @public
     * @attr
     */
    get placeholder() {
        return this._placeholder;
    }
    set placeholder(value) {
        if (this._placeholder !== value) {
            this._placeholder = value;
            this.requestUpdate('placeholder');
        }
    }
    /**
     * Gets or sets the `autocomplete` property.
     *
     * @public
     * @attr
     */
    get autocomplete() {
        return this._autocomplete;
    }
    set autocomplete(value) {
        if (this._autocomplete !== value) {
            this._autocomplete = value;
            this.requestUpdate('autocomplete');
        }
    }
    /**
     * Gets or sets the `values` property.
     *
     * @public
     * @attr
     */
    get values() {
        return this._values;
    }
    set values(value) {
        if (this._values !== value) {
            this._values = value;
            this.requestUpdate('values');
        }
    }
    /**
     * Gets or sets the `view` property.
     *
     * @public
     * @attr
     */
    get view() {
        return this._view;
    }
    set view(value) {
        if (this._view !== value) {
            this._view = value;
            this.requestUpdate('view');
        }
    }
    /**
     * Gets or sets the `allowedViews` property.
     * Defines which views the user is allowed to navigate to.
     * Accepts a single `CalendarView` value or an array of values.
     *
     * @public
     */
    get allowedViews() {
        return this._allowedViews;
    }
    set allowedViews(value) {
        if (this._allowedViews !== value) {
            this._allowedViews = value;
            this.requestUpdate('allowedViews');
        }
    }
    /**
     * Gets or sets the `showNavigation` property.
     * Controls whether the navigation buttons (previous, today, next) are displayed.
     *
     * @public
     * @attr
     */
    get showNavigation() {
        return this._showNavigation;
    }
    set showNavigation(value) {
        if (this._showNavigation !== value) {
            this._showNavigation = value;
            this.requestUpdate('showNavigation');
        }
    }
    /**
     * Gets or sets the `blackoutDates` property.
     *
     * @public
     * @attr
     */
    get blackoutDates() {
        return this._blackoutDates;
    }
    set blackoutDates(value) {
        if (this._blackoutDates !== value) {
            this._blackoutDates = value;
            this.requestUpdate('blackoutDates');
        }
    }
    /**
     * Gets or sets the `specialDates` property.
     *
     * @public
     * @attr
     */
    get specialDates() {
        return this._specialDates;
    }
    set specialDates(value) {
        if (this._specialDates !== value) {
            this._specialDates = value;
            this.requestUpdate('specialDates');
        }
    }
    /**
     * Gets or sets the `minDate` property.
     *
     * @public
     * @attr
     */
    get minDate() {
        return this._minDate;
    }
    set minDate(value) {
        if (this._minDate !== value) {
            this._minDate = value;
            this.requestUpdate('minDate');
        }
    }
    /**
     * Gets or sets the `maxDate` property.
     *
     * @public
     * @attr
     */
    get maxDate() {
        return this._maxDate;
    }
    set maxDate(value) {
        if (this._maxDate !== value) {
            this._maxDate = value;
            this.requestUpdate('maxDate');
        }
    }
    /**
     * Gets or sets the `firstDayOfWeek` property.
     *
     * @public
     * @attr
     */
    get firstDayOfWeek() {
        return this._firstDayOfWeek;
    }
    set firstDayOfWeek(value) {
        if (this._firstDayOfWeek !== value) {
            this._firstDayOfWeek = value;
            this.requestUpdate('firstDayOfWeek');
        }
    }
    /**
     * Gets or sets the `isTodayHighlighted` property.
     *
     * @public
     * @attr
     */
    get isTodayHighlighted() {
        return this._isTodayHighlighted;
    }
    set isTodayHighlighted(value) {
        if (this._isTodayHighlighted !== value) {
            this._isTodayHighlighted = value;
            this.requestUpdate('isTodayHighlighted');
        }
    }
    /**
     * Gets or sets the `isWeekendHighlighted` property.
     *
     * @public
     * @attr
     */
    get isWeekendHighlighted() {
        return this._isWeekendHighlighted;
    }
    set isWeekendHighlighted(value) {
        if (this._isWeekendHighlighted !== value) {
            this._isWeekendHighlighted = value;
            this.requestUpdate('isWeekendHighlighted');
        }
    }
    /**
     * Gets or sets the `showWeekNumbers` property.
     *
     * @public
     * @attr
     */
    get showWeekNumbers() {
        return this._showWeekNumbers;
    }
    set showWeekNumbers(value) {
        if (this._showWeekNumbers !== value) {
            this._showWeekNumbers = value;
            this.requestUpdate('showWeekNumbers');
        }
    }
    /**
     * A handler that gets date and returns null or a tuple with circled marker data. See `CalendarMarkerData`.
     *
     * @public
     */
    get markerHandler() {
        return this._markerHandler;
    }
    set markerHandler(value) {
        if (this._markerHandler !== value) {
            this._markerHandler = value;
            this.requestUpdate('markerHandler');
        }
    }
    /**
     * Gets or sets the `showAdjacent` property.
     *
     * @public
     * @attr
     */
    get showAdjacent() {
        return this._showAdjacent;
    }
    set showAdjacent(value) {
        if (this._showAdjacent !== value) {
            this._showAdjacent = value;
            this.requestUpdate('showAdjacent');
        }
    }
    /**
     * Gets or sets the `format` property.
     *
     * Supported format specifiers:
     * - `d`   : Day of the month (1-31) without leading zero.
     * - `dd`  : Day of the month (01-31) with leading zero.
     * - `ddd` : Abbreviated name of the day of the week (e.g., Mon, Tue).
     * - `dddd`: Full name of the day of the week (e.g., Monday, Tuesday).
     * - `h`   : Hour (1-12) in 12-hour format without leading zero.
     * - `hh`  : Hour (01-12) in 12-hour format with leading zero.
     * - `H`   : Hour (0-23) in 24-hour format without leading zero.
     * - `HH`  : Hour (00-23) in 24-hour format with leading zero.
     * - `m`   : Minute (0-59) without leading zero.
     * - `mm`  : Minute (00-59) with leading zero.
     * - `M`   : Month (1-12) without leading zero.
     * - `MM`  : Month (01-12) with leading zero.
     * - `MMM` : Abbreviated name of the month (e.g., Jan, Feb).
     * - `MMMM`: Full name of the month (e.g., January, February).
     * - `s`   : Second (0-59) without leading zero.
     * - `ss`  : Second (00-59) with leading zero.
     * - `t`   : First character of the AM/PM designator (e.g., A or P).
     * - `tt`  : Full AM/PM designator (e.g., AM or PM).
     * - `y`   : Year as the last two digits without leading zero (e.g., 9 for 2009).
     * - `yy`  : Year as the last two digits with leading zero (e.g., 09 for 2009).
     * - `yyy` : Year with a minimum of three digits (e.g., 009, 2009).
     * - `yyyy`: Year as a four-digit number (e.g., 2009).
     * - `:`   : Time separator (e.g., colon).
     * - `/`   : Date separator (e.g., slash).
     *
     * @public
     * @attr
     */
    get format() {
        return this._format;
    }
    set format(value) {
        if (this._format !== value) {
            this._format = value;
            this.requestUpdate('format');
        }
    }
    /**
     * Determines the text alignment of the component.
     *
     * @public
     * @attr
     */
    get textAlign() {
        return this._textAlign;
    }
    set textAlign(value) {
        if (this._textAlign !== value) {
            this._textAlign = value;
            this.requestUpdate('textAlign');
        }
    }
    /**
     * Gets the selected hour (0-23).
     *
     * @public
     * @readonly
     */
    get selectedHour() {
        return this._selectedHour;
    }
    /**
     * Gets the selected minute (0-59).
     *
     * @public
     * @readonly
     */
    get selectedMinute() {
        return this._selectedMinute;
    }
    /**
     * Gets whether the locale uses 12-hour time format.
     *
     * @public
     * @readonly
     */
    get is12Hour() {
        const resolved = new Intl.DateTimeFormat(this.locale === 'default' ? undefined : this.locale, { hour: 'numeric' }).resolvedOptions();
        return resolved.hourCycle === 'h12' || resolved.hourCycle === 'h11';
    }
    /**
     * Gets whether the selected hour is in the AM range (0-11).
     *
     * @public
     * @readonly
     */
    get isAM() {
        return this._selectedHour < 12;
    }
    /**
     * Gets the selected hour for display in the wheel picker.
     * In 12h mode, converts 0-23 to 1-12.
     *
     * @public
     * @readonly
     */
    get selectedDisplayHour() {
        if (!this.is12Hour) {
            return this._selectedHour;
        }
        const hour12 = this._selectedHour % 12;
        return hour12 === 0 ? 12 : hour12;
    }
    /**
     * Gets the list of hour items for the wheel picker.
     * Returns 1-12 for 12h locales, 0-23 for 24h locales.
     *
     * @public
     * @readonly
     */
    get hourItems() {
        if (this.is12Hour) {
            return Array.from({ length: 12 }, (_, i) => {
                const hour = i + 1;
                return {
                    value: String(hour),
                    label: String(hour)
                };
            });
        }
        return Array.from({ length: 24 }, (_, i) => ({
            value: String(i),
            label: String(i).padStart(2, '0')
        }));
    }
    /**
     * Gets the list of minute items for the wheel picker (0-59).
     *
     * @public
     * @readonly
     */
    get minuteItems() {
        return Array.from({ length: 60 }, (_, i) => ({
            value: String(i),
            label: String(i).padStart(2, '0')
        }));
    }
    /**
     * Determines whether the element has a prefix or not.
     * The Prefix is a slot that is displayed before the input.
     *
     * @private
     * @readonly
     * @attr
     */
    get hasPrefix() {
        return this.hasSlotContent('prefix');
    }
    /**
     * Determines whether the element has a suffix or not.
     * The Suffix is a slot that is displayed after the input.
     *
     * @private
     * @readonly
     * @attr
     */
    get hasSuffix() {
        return this.hasSlotContent('suffix');
    }
    /**
     * @protected
     * @readonly
     */
    get keyboard() {
        return this._keyboardController;
    }
    // #endregion
    // #region Methods
    /**
     * @public
     * @override
     */
    connectedCallback() {
        super.connectedCallback();
        this.keyboard
            .add([Key.Space, Key.Enter], () => this.toggle(), undefined, { preventDefault: true })
            .add([Key.Escape], () => {
            if (this.isDropDownOpen) {
                this.close();
            }
            else {
                this.clear();
            }
        }, undefined, { preventDefault: true })
            .add([Key.Tab], () => this.close());
        this.on('click', () => this.focus());
    }
    /**
     * Sets focus on the input.
     *
     * @public
     * @override
     */
    focus() {
        if (this.shadowRoot) {
            DomServiceLocator.current.findDescendant(this.shadowRoot, 'input')?.focus();
        }
    }
    /**
     * Removes keyboard focus from the input.
     *
     * @public
     * @override
     */
    blur() {
        if (this.shadowRoot) {
            DomServiceLocator.current.findDescendant(this.shadowRoot, 'input')?.blur();
        }
    }
    /**
     * Clears the value of the element but not the validation.
     *
     * @public
     * @override
     */
    clear(force) {
        const isCleared = super.clear(force);
        if (isCleared) {
            this.emit('change', {
                bubbles: true,
                composed: true
            });
        }
        return isCleared;
    }
    /**
     * Resets the value, all kinds of validation and errors.
     *
     * @public
     * @override
     */
    reset() {
        super.reset();
        this.clear();
        this._invalidInput = false;
        this.invalid = false;
    }
    /**
     * Checks the validity of the element and returns `true` if it is valid; otherwise, `false`.
     *
     * @public
     * @override
     */
    checkValidity() {
        return this.shadowRoot
            ? this._inputElement.checkValidity() && !this._invalidInput
            : true;
    }
    /**
     * @protected
     * @template
     */
    onChange(event) {
        if (!event.target) {
            return;
        }
        if (event.target instanceof HTMLInputElement) {
            const inputValue = event.target.value;
            const date = DateParser.tryParse(inputValue, this._format, this.locale);
            if (date) {
                const formattedDate = DateTimeFormatter.format(date, this._format, this.locale);
                this.displayValue = formattedDate;
                this.value = date;
                this._invalidInput = false;
            }
            else {
                this.value = null;
                this._invalidInput = true;
            }
        }
        this.emit('change', { detail: this.value });
    }
    /**
     * @protected
     * @template
     * @override
     */
    onInput(event) {
        super.onInput(event);
        this.emit('input', { detail: this.value });
    }
    /**
     * @protected
     * @template
     * @override
     */
    onFocus(event) {
        super.onFocus(event);
        this.emit('focus', { detail: event });
    }
    /**
     * @protected
     * @template
     * @override
     */
    onBlur(event) {
        super.onBlur(event);
        this.emit('blur', { detail: event });
    }
    /**
     * @protected
     * @template
     */
    onDateChanged(detail, calendar) {
        const calendarView = calendar?.view ?? this._view;
        if (calendarView === CalendarView.Year) {
            this.view = CalendarView.Month;
            return;
        }
        if (calendarView === CalendarView.Month) {
            this.view = CalendarView.Day;
            return;
        }
        const date = detail.value?.date ?? null;
        if (date) {
            date.setHours(this._selectedHour, this._selectedMinute, 0, 0);
        }
        this.value = date;
        this.emit('change', { detail: this.value });
        this.close();
    }
    /**
     * Handles the AM/PM toggle.
     *
     * @param isAM - Whether AM is selected.
     * @public
     * @template
     */
    onAmPmToggled(isAM) {
        const currentIsAM = this._selectedHour < 12;
        if (isAM === currentIsAM) {
            return;
        }
        if (isAM) {
            this._selectedHour = this._selectedHour - 12;
        }
        else {
            this._selectedHour = this._selectedHour + 12;
        }
        this.applyTimeToValue();
    }
    /**
     * Handles hour wheel picker change events.
     *
     * @param event - The wheel picker change event.
     * @public
     * @template
     */
    onHourChanged(event) {
        const pickerValue = parseInt(event.detail.value, 10);
        if (this.is12Hour) {
            const isPM = this._selectedHour >= 12;
            let hour24 = pickerValue % 12;
            if (isPM) {
                hour24 += 12;
            }
            this._selectedHour = hour24;
        }
        else {
            this._selectedHour = pickerValue;
        }
        this.applyTimeToValue();
    }
    /**
     * Handles minute wheel picker change events.
     *
     * @param event - The wheel picker change event.
     * @public
     * @template
     */
    onMinuteChanged(event) {
        this._selectedMinute = parseInt(event.detail.value, 10);
        this.applyTimeToValue();
    }
    /**
     * Applies the currently selected hour and minute to the value.
     *
     * @private
     */
    applyTimeToValue() {
        if (this._value) {
            const updated = new Date(this._value.getTime());
            updated.setHours(this._selectedHour, this._selectedMinute, 0, 0);
            this.value = updated;
            this.emit('change', { detail: this.value });
        }
        this.requestUpdate();
    }
    /**
     * @protected
     * @override
     */
    onApplyTemplate() {
        super.onApplyTemplate();
        this._inputElement = this.getTemplatePart('input');
    }
    /**
     * @protected
     */
    onIsDropDownOpenPropertyChanged(_prev, next) {
        if (next) {
            this._clickOutsideController.observe();
        }
        else {
            this._clickOutsideController.unobserve();
        }
    }
    /**
     * @protected
     */
    onFormatPropertyChanged(_prev, next) {
        if (this.value && next) {
            const formattedDate = DateTimeFormatter.format(this.value, next, this.locale);
            this.displayValue = formattedDate;
        }
    }
    /**
     * @protected
     */
    onDisabledPropertyChanged(_prev, next) {
        if (next) {
            this.close();
        }
    }
    /**
     * @protected
     */
    onValuePropertyChanged(_prev, next) {
        if (next) {
            const formattedDate = DateTimeFormatter.format(next, this._format, this.locale);
            this.displayValue = formattedDate;
        }
    }
};
__decorate([
    Property({ type: Date }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], DateTimeBoxElement.prototype, "displayDate", null);
__decorate([
    Property({ type: Date }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], DateTimeBoxElement.prototype, "displayDateStart", null);
__decorate([
    Property({ type: Date }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], DateTimeBoxElement.prototype, "displayDateEnd", null);
__decorate([
    Attribute({
        type: Date,
        converter: {
            fromAttribute: (value) => value ? new Date(value) : null,
            toAttribute: (value) => value ? value.toISOString() : ''
        }
    }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], DateTimeBoxElement.prototype, "value", null);
__decorate([
    Property({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], DateTimeBoxElement.prototype, "displayValue", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DateTimeBoxElement.prototype, "readonly", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DateTimeBoxElement.prototype, "required", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DateTimeBoxElement.prototype, "autofocus", null);
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], DateTimeBoxElement.prototype, "name", null);
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], DateTimeBoxElement.prototype, "placeholder", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DateTimeBoxElement.prototype, "autocomplete", null);
__decorate([
    Attribute({
        type: (Array),
        converter: {
            fromAttribute: (value) => !value
                ? undefined
                : value
                    .split(' ')
                    .map((v) => v.trim())
                    .filter((v) => v)
                    .map((v) => new Date(v)),
            toAttribute: (value) => value.map((v) => v.toISOString()).join(' ')
        }
    }),
    __metadata("design:type", Array),
    __metadata("design:paramtypes", [Array])
], DateTimeBoxElement.prototype, "values", null);
__decorate([
    Attribute({ type: CalendarView }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], DateTimeBoxElement.prototype, "view", null);
__decorate([
    Property({ type: Array }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], DateTimeBoxElement.prototype, "allowedViews", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DateTimeBoxElement.prototype, "showNavigation", null);
__decorate([
    Attribute({ type: (Array) }),
    __metadata("design:type", Array),
    __metadata("design:paramtypes", [Array])
], DateTimeBoxElement.prototype, "blackoutDates", null);
__decorate([
    Attribute({ type: (Array) }),
    __metadata("design:type", Array),
    __metadata("design:paramtypes", [Array])
], DateTimeBoxElement.prototype, "specialDates", null);
__decorate([
    Attribute({
        type: Date,
        converter: {
            fromAttribute: (value) => value ? new Date(value) : new Date(),
            toAttribute: (value) => value ? value.toISOString() : ''
        }
    }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], DateTimeBoxElement.prototype, "minDate", null);
__decorate([
    Attribute({
        type: Date,
        converter: {
            fromAttribute: (value) => value ? new Date(value) : new Date(),
            toAttribute: (value) => value ? value.toISOString() : ''
        }
    }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], DateTimeBoxElement.prototype, "maxDate", null);
__decorate([
    Attribute({ type: DayOfWeek }),
    __metadata("design:type", Number),
    __metadata("design:paramtypes", [Number])
], DateTimeBoxElement.prototype, "firstDayOfWeek", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DateTimeBoxElement.prototype, "isTodayHighlighted", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DateTimeBoxElement.prototype, "isWeekendHighlighted", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DateTimeBoxElement.prototype, "showWeekNumbers", null);
__decorate([
    Property({ type: Function }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Function])
], DateTimeBoxElement.prototype, "markerHandler", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DateTimeBoxElement.prototype, "showAdjacent", null);
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], DateTimeBoxElement.prototype, "format", null);
__decorate([
    Attribute({ type: TextAlignment }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], DateTimeBoxElement.prototype, "textAlign", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], DateTimeBoxElement.prototype, "hasPrefix", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], DateTimeBoxElement.prototype, "hasSuffix", null);
__decorate([
    Watch('isDropDownOpen', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Boolean, Boolean]),
    __metadata("design:returntype", void 0)
], DateTimeBoxElement.prototype, "onIsDropDownOpenPropertyChanged", null);
__decorate([
    Watch('format', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String]),
    __metadata("design:returntype", void 0)
], DateTimeBoxElement.prototype, "onFormatPropertyChanged", null);
__decorate([
    Watch('disabled', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Boolean, Boolean]),
    __metadata("design:returntype", void 0)
], DateTimeBoxElement.prototype, "onDisabledPropertyChanged", null);
__decorate([
    Watch('value'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", void 0)
], DateTimeBoxElement.prototype, "onValuePropertyChanged", null);
DateTimeBoxElement = DateTimeBoxElement_1 = __decorate([
    Component({
        selector: 'mosaik-datetimebox',
        template: dateTimeBoxElementTemplate,
        themes: {
            joy: dateTimeBoxElementJoyStyle,
            memphis: dateTimeBoxElementMemphisStyle,
            cosmopolitan: dateTimeBoxElementCosmopolitanStyle
        },
        host: {
            tabIndex: '0'
        },
        options: {
            mode: 'open',
            delegatesFocus: true
        },
        imports: [
            IconElement,
            PopupElement,
            CalendarElement,
            FocusRingElement,
            FloatingElement,
            PortalElement,
            WheelPickerElement
        ]
    }),
    __metadata("design:paramtypes", [])
], DateTimeBoxElement);
export { DateTimeBoxElement };
/**
 * Checks if the provided value is valid for a input.
 * A valid value can be a Date or null
 *
 * @private
 * @param value - The value to check.
 */
function isValidValue(value) {
    return value instanceof Date || value === null;
}
//# sourceMappingURL=DateTimeBoxElement.js.map