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 { css, html, nothing, repeat, customElement, property, classMap } from '../../../../external/lit/index.js';
import { UmbChangeEvent } from '../../event/index.js';
import { UmbLitElement } from '../../lit-element/index.js';
import { UUIRadioElement } from '../../../../external/uui/index.js';
import { UMB_VALIDATION_EMPTY_LOCALIZATION_KEY, UmbFormControlMixin } from '../../validation/index.js';
let UmbInputRadioButtonListElement = class UmbInputRadioButtonListElement extends UmbFormControlMixin(UmbLitElement, undefined) {
    set value(value) {
        this.#value = value;
    }
    get value() {
        return this.#value;
    }
    #value;
    constructor() {
        super();
        this.#value = '';
        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.addValidator('valueMissing', () => this.requiredMessage ?? UMB_VALIDATION_EMPTY_LOCALIZATION_KEY, () => !this.readonly && !!this.required && (this.value === undefined || this.value === null || this.value === ''));
    }
    #onChange(event) {
        event.stopPropagation();
        if (!(event.target instanceof UUIRadioElement))
            return;
        this.value = event.target.value;
        this.dispatchEvent(new UmbChangeEvent());
    }
    render() {
        if (!this.list)
            return nothing;
        return html `
			<uui-radio-group .value=${this.value} @change=${this.#onChange} ?readonly=${this.readonly}>
				${repeat(this.list, (item) => item, (item) => this.#renderRadioButton(item))}
			</uui-radio-group>
		`;
    }
    #renderRadioButton(item) {
        return html `
			<uui-radio
				value=${item.value}
				class=${classMap({ invalid: !!item.invalid })}
				label=${this.localize.string(item.label) +
            (item.invalid ? ` (${this.localize.term('validation_legacyOption')})` : '')}
				title=${item.invalid ? this.localize.term('validation_legacyOptionDescription') : ''}>
			</uui-radio>
		`;
    }
    static { this.styles = [
        css `
			:host {
				display: block;
			}

			uui-radio {
				&.invalid {
					text-decoration: line-through;
				}
			}
		`,
    ]; }
};
__decorate([
    property()
], UmbInputRadioButtonListElement.prototype, "value", null);
__decorate([
    property({ type: Array })
], UmbInputRadioButtonListElement.prototype, "list", void 0);
__decorate([
    property({ type: Boolean, reflect: true })
], UmbInputRadioButtonListElement.prototype, "readonly", void 0);
__decorate([
    property({ type: Boolean })
], UmbInputRadioButtonListElement.prototype, "required", void 0);
__decorate([
    property({ type: String })
], UmbInputRadioButtonListElement.prototype, "requiredMessage", void 0);
UmbInputRadioButtonListElement = __decorate([
    customElement('umb-input-radio-button-list')
], UmbInputRadioButtonListElement);
export { UmbInputRadioButtonListElement };
export default UmbInputRadioButtonListElement;
