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 { UmbPropertyEditorUIMultipleTextStringElement } from '../multiple-text-string/property-editor-ui-multiple-text-string.element.js';
import { customElement } from '../../../external/lit/index.js';
import { UmbTemporaryFileConfigRepository } from '../../core/temporary-file/index.js';
/**
 * @element umb-property-editor-ui-accepted-upload-types
 */
let UmbPropertyEditorUIAcceptedUploadTypesElement = class UmbPropertyEditorUIAcceptedUploadTypesElement extends UmbPropertyEditorUIMultipleTextStringElement {
    #temporaryFileConfigRepository = new UmbTemporaryFileConfigRepository(this);
    async connectedCallback() {
        super.connectedCallback();
        await this.#temporaryFileConfigRepository.initialized;
        this.observe(this.#temporaryFileConfigRepository.all(), (config) => {
            if (!config)
                return;
            this.#addValidators(config);
        });
    }
    #addValidators(config) {
        this.addValidator('badInput', () => {
            let message = this.localize.term('validation_invalidExtensions');
            if (config.allowedUploadedFileExtensions.length) {
                message += `<br>${this.localize.term('validation_allowedExtensions')} ${config.allowedUploadedFileExtensions.join(', ')}`;
            }
            if (config.disallowedUploadedFilesExtensions.length) {
                message += `<br>${this.localize.term('validation_disallowedExtensions')} ${config.disallowedUploadedFilesExtensions.join(', ')}`;
            }
            return message;
        }, () => {
            const extensions = this.value;
            if (!extensions)
                return false;
            if (config.allowedUploadedFileExtensions.length &&
                !config.allowedUploadedFileExtensions.some((ext) => extensions.includes(ext))) {
                return true;
            }
            if (config.disallowedUploadedFilesExtensions.some((ext) => extensions.includes(ext))) {
                return true;
            }
            return false;
        });
    }
};
UmbPropertyEditorUIAcceptedUploadTypesElement = __decorate([
    customElement('umb-property-editor-ui-accepted-upload-types')
], UmbPropertyEditorUIAcceptedUploadTypesElement);
export { UmbPropertyEditorUIAcceptedUploadTypesElement };
export default UmbPropertyEditorUIAcceptedUploadTypesElement;
