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 { UmbChangeEvent } from '../../core/event/index.js';
import { html, customElement, property, state } from '../../../external/lit/index.js';
import { UmbLitElement } from '../../core/lit-element/index.js';
import { UMB_VALIDATION_EMPTY_LOCALIZATION_KEY, UmbFormControlMixin } from '../../core/validation/index.js';
/**
 * @element umb-property-editor-ui-radio-button-list
 */
let UmbPropertyEditorUIRadioButtonListElement = class UmbPropertyEditorUIRadioButtonListElement extends UmbFormControlMixin(UmbLitElement) {
    constructor() {
        super(...arguments);
        this._list = [];
        /**
         * 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.mandatoryMessage = UMB_VALIDATION_EMPTY_LOCALIZATION_KEY;
    }
    set config(config) {
        if (!config)
            return;
        const items = config.getValueByAlias('items');
        if (Array.isArray(items) && items.length > 0) {
            this._list =
                typeof items[0] === 'string'
                    ? items.map((item) => ({ label: item, value: item }))
                    : items.map((item) => ({ label: item.name, value: item.value }));
            // If selection includes a value that is not in the list, add it to the list
            if (this.value && !this._list.find((item) => item.value === this.value)) {
                this._list.push({ label: this.value, value: this.value, invalid: true });
            }
        }
    }
    firstUpdated() {
        this.addFormControlElement(this.shadowRoot.querySelector('umb-input-radio-button-list'));
    }
    #onChange(event) {
        this.value = event.target.value;
        this.dispatchEvent(new UmbChangeEvent());
    }
    render() {
        return html `
			<umb-input-radio-button-list
				.list=${this._list}
				.required=${this.mandatory}
				.requiredMessage=${this.mandatoryMessage}
				.value=${this.value ?? ''}
				?readonly=${this.readonly}
				@change=${this.#onChange}>
			</umb-input-radio-button-list>
		`;
    }
};
__decorate([
    state()
], UmbPropertyEditorUIRadioButtonListElement.prototype, "_list", void 0);
__decorate([
    property({ type: Boolean, reflect: true })
], UmbPropertyEditorUIRadioButtonListElement.prototype, "readonly", void 0);
__decorate([
    property({ type: Boolean })
], UmbPropertyEditorUIRadioButtonListElement.prototype, "mandatory", void 0);
__decorate([
    property({ type: String })
], UmbPropertyEditorUIRadioButtonListElement.prototype, "mandatoryMessage", void 0);
UmbPropertyEditorUIRadioButtonListElement = __decorate([
    customElement('umb-property-editor-ui-radio-button-list')
], UmbPropertyEditorUIRadioButtonListElement);
export { UmbPropertyEditorUIRadioButtonListElement };
export default UmbPropertyEditorUIRadioButtonListElement;
