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 { UMB_PROPERTY_CONTEXT } from '../../../core/property/index.js';
import { html, customElement, property, state, ifDefined } from '../../../../external/lit/index.js';
import { UmbLitElement } from '../../../core/lit-element/index.js';
import '../../components/tags-input/tags-input.element.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-tags
 */
let UmbPropertyEditorUITagsElement = class UmbPropertyEditorUITagsElement extends UmbFormControlMixin(UmbLitElement, undefined) {
    set value(value) {
        super.value = value || [];
    }
    get value() {
        return super.value;
    }
    //TODO: Use type from VariantID
    set config(config) {
        this._group = config?.getValueByAlias('group');
        this._storageType = config?.getValueByAlias('storageType');
    }
    constructor() {
        super();
        /**
         * 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;
        this.consumeContext(UMB_PROPERTY_CONTEXT, (context) => {
            this.observe(context?.variantId, (id) => {
                if (id && id.culture !== undefined) {
                    this._culture = id.culture;
                }
            });
        });
    }
    firstUpdated() {
        this.addFormControlElement(this.shadowRoot.querySelector('umb-tags-input'));
    }
    #onChange(event) {
        this.value = event.target.value.split(',');
        this.dispatchEvent(new UmbChangeEvent());
    }
    render() {
        return html `<umb-tags-input
			group=${ifDefined(this._group)}
			.culture=${this._culture}
			.items=${this.value}
			@change=${this.#onChange}
			?required=${!!this.mandatory}
			.requiredMessage=${this.mandatoryMessage}
			?readonly=${this.readonly}></umb-tags-input>`;
    }
};
__decorate([
    property({ type: Array })
], UmbPropertyEditorUITagsElement.prototype, "value", null);
__decorate([
    property({ type: Boolean, reflect: true })
], UmbPropertyEditorUITagsElement.prototype, "readonly", void 0);
__decorate([
    property({ type: Boolean })
], UmbPropertyEditorUITagsElement.prototype, "mandatory", void 0);
__decorate([
    property({ type: String })
], UmbPropertyEditorUITagsElement.prototype, "mandatoryMessage", void 0);
__decorate([
    state()
], UmbPropertyEditorUITagsElement.prototype, "_group", void 0);
__decorate([
    state()
], UmbPropertyEditorUITagsElement.prototype, "_storageType", void 0);
__decorate([
    state()
], UmbPropertyEditorUITagsElement.prototype, "_culture", void 0);
UmbPropertyEditorUITagsElement = __decorate([
    customElement('umb-property-editor-ui-tags')
], UmbPropertyEditorUITagsElement);
export { UmbPropertyEditorUITagsElement };
export default UmbPropertyEditorUITagsElement;
