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, property, css, map, ref } from '../../../external/lit/index.js';
import { UmbLitElement } from '../../core/lit-element/index.js';
import { UmbChangeEvent } from '../../core/event/index.js';
import { UMB_VALIDATION_EMPTY_LOCALIZATION_KEY, UmbFormControlMixin } from '../../core/validation/index.js';
/**
 * @element umb-property-editor-ui-time-zone-picker
 */
let UmbPropertyEditorUITimeZonePickerElement = class UmbPropertyEditorUITimeZonePickerElement extends UmbFormControlMixin(UmbLitElement) {
    set value(value) {
        super.value = value;
        this._selectedTimeZones = value?.timeZones ?? [];
    }
    get value() {
        return super.value;
    }
    #inputTimeZone;
    constructor() {
        super();
        this._supportedModes = ['all', 'local', 'custom'];
        this._selectedTimeZones = [];
        this.readonly = false;
        this.addValidator('valueMissing', () => UMB_VALIDATION_EMPTY_LOCALIZATION_KEY, () => !this.value?.mode || this._supportedModes.indexOf(this.value.mode) === -1);
    }
    #onModeInput(event) {
        if (!this._supportedModes.includes(event.target.value))
            throw new Error(`Unknown mode: ${event.target.value}`);
        this.value = {
            mode: event.target.value,
            timeZones: this.#inputTimeZone?.value ? Array.from(this.#inputTimeZone?.value) : [],
        };
        this.dispatchEvent(new UmbChangeEvent());
    }
    #onChange(event) {
        const target = event.target;
        const selectedOptions = target.value;
        if (this.value?.mode === 'custom') {
            this.value = { mode: this.value.mode, timeZones: selectedOptions };
        }
        else {
            this.value = { mode: this.value?.mode ?? 'all', timeZones: [] };
        }
        this.dispatchEvent(new UmbChangeEvent());
    }
    #inputTimeZoneRefChanged(input) {
        if (this.#inputTimeZone) {
            this.removeFormControlElement(this.#inputTimeZone);
        }
        this.#inputTimeZone = input;
        if (this.#inputTimeZone) {
            this.addFormControlElement(this.#inputTimeZone);
        }
    }
    render() {
        return html `
			<uui-radio-group
				required
				?readonly=${this.readonly}
				@input=${this.#onModeInput}
				.value=${this.value?.mode ?? 'all'}>
				${map(this._supportedModes, (mode) => html `<uui-radio
							name="order"
							label=${this.localize.term(`dateTimePicker_config_timeZones_${mode}`)}
							value="${mode}"></uui-radio>`)}
			</uui-radio-group>
			<div class="timezone-picker" ?hidden=${this.value?.mode !== 'custom'}>
				<umb-input-time-zone
					.value=${this._selectedTimeZones}
					?readonly=${this.readonly}
					?required=${this.value?.mode === 'custom'}
					@change=${this.#onChange}
					${ref(this.#inputTimeZoneRefChanged)}>
				</umb-input-time-zone>
			</div>
		`;
    }
    static { this.styles = [
        css `
			:host {
				display: grid;
				gap: var(--uui-size-space-3);
			}

			.timezone-picker {
				display: flex;
				flex-direction: row;
				gap: var(--uui-size-space-6);
			}

			.timezone-picker[hidden] {
				display: none;
			}
		`,
    ]; }
};
__decorate([
    property({ type: Boolean, reflect: true })
], UmbPropertyEditorUITimeZonePickerElement.prototype, "readonly", void 0);
__decorate([
    property({ attribute: false })
], UmbPropertyEditorUITimeZonePickerElement.prototype, "config", void 0);
UmbPropertyEditorUITimeZonePickerElement = __decorate([
    customElement('umb-property-editor-ui-time-zone-picker')
], UmbPropertyEditorUITimeZonePickerElement);
export { UmbPropertyEditorUITimeZonePickerElement };
export default UmbPropertyEditorUITimeZonePickerElement;
