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;
};
import { html, customElement, css, property, query, until, repeat, state } from '../../../../external/lit/index.js';
import { UmbLitElement } from '../../lit-element/index.js';
import { UmbChangeEvent } from '../../event/index.js';
import { UmbFormControlMixin } from '../../validation/index.js';
/**
 * @element umb-input-time-zone-picker
 */
let UmbInputTimeZonePickerElement = class UmbInputTimeZonePickerElement extends UmbFormControlMixin(UmbLitElement) {
    set options(value) {
        this.#options = value;
        this._filteredOptions = value;
    }
    get options() {
        return this.#options;
    }
    #options;
    /**
     *
     */
    constructor() {
        super();
        /**
         * Disables the input
         * @type {boolean}
         * @attr
         * @default false
         */
        this.disabled = false;
        /**
         * Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
         * @type {boolean}
         * @attr
         * @default false
         */
        this.readonly = false;
        this.#options = [];
        this._filteredOptions = [];
        this.#renderTimeZoneOption = (option) => html `<uui-combobox-list-option .value=${option.value} .displayValue=${option.name}>
			${option.name}
		</uui-combobox-list-option>`;
        this._filteredOptions = this.options;
    }
    async focus() {
        await this.updateComplete;
        this._input?.focus();
    }
    #onSearch(event) {
        const searchTerm = event.currentTarget?.search;
        this._filteredOptions = this.options.filter((option) => new RegExp(searchTerm, 'i').test(option.name) || option.offset === searchTerm);
    }
    #onChange(event) {
        this.value = event.currentTarget?.value ?? '';
        this.dispatchEvent(new UmbChangeEvent());
    }
    #renderTimeZoneOption;
    render() {
        return html `
			<uui-combobox
				id="input"
				pristine
				label="${this.localize.term('general_value')} ${this._input?.value}"
				.value=${this.value}
				@search="${this.#onSearch}"
				@change="${this.#onChange}"
				?disabled=${this.disabled}
				?readonly=${this.readonly}>
				<uui-combobox-list> ${until(repeat(this._filteredOptions, this.#renderTimeZoneOption))} </uui-combobox-list>
			</uui-combobox>
		`;
    }
    static { this.styles = [
        css `
			#input {
				width: 100%;
			}
		`,
    ]; }
};
__decorate([
    property({ type: Boolean, reflect: true })
], UmbInputTimeZonePickerElement.prototype, "disabled", void 0);
__decorate([
    property({ type: Boolean, reflect: true })
], UmbInputTimeZonePickerElement.prototype, "readonly", void 0);
__decorate([
    property({ type: Array })
], UmbInputTimeZonePickerElement.prototype, "options", null);
__decorate([
    state()
], UmbInputTimeZonePickerElement.prototype, "_filteredOptions", void 0);
__decorate([
    query('#input')
], UmbInputTimeZonePickerElement.prototype, "_input", void 0);
UmbInputTimeZonePickerElement = __decorate([
    customElement('umb-input-time-zone-picker')
], UmbInputTimeZonePickerElement);
export { UmbInputTimeZonePickerElement };
export default UmbInputTimeZonePickerElement;
