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 { customElement, html, property, state } from '../../../../external/lit/index.js';
import { UmbLitElement } from '../../../core/lit-element/index.js';
import '../../components/input-static-file/index.js';
import { UmbServerFilePathUniqueSerializer } from '../../../core/server-file-system/index.js';
import { UmbChangeEvent } from '../../../core/event/index.js';
let UmbPropertyEditorUIStaticFilePickerElement = class UmbPropertyEditorUIStaticFilePickerElement extends UmbLitElement {
    constructor() {
        super(...arguments);
        this.#singleItemMode = false;
        // TODO: get rid of UmbServerFilePathUniqueSerializer in v.15 [NL]
        this.#serverFilePathUniqueSerializer = new UmbServerFilePathUniqueSerializer();
        this._limitMin = 0;
        this._limitMax = Infinity;
    }
    #singleItemMode;
    // TODO: get rid of UmbServerFilePathUniqueSerializer in v.15 [NL]
    #serverFilePathUniqueSerializer;
    set value(value) {
        if (Array.isArray(value)) {
            this._value = value.map((unique) => this.#serverFilePathUniqueSerializer.toUnique(unique));
        }
        else if (value) {
            this._value = this.#serverFilePathUniqueSerializer.toUnique(value);
        }
        else {
            this._value = undefined;
        }
    }
    get value() {
        if (Array.isArray(this._value)) {
            return this._value.map((unique) => this.#serverFilePathUniqueSerializer.toServerPath(unique) ?? '');
        }
        else if (this._value) {
            return this.#serverFilePathUniqueSerializer.toServerPath(this._value) ?? '';
        }
        else {
            return undefined;
        }
    }
    set config(config) {
        this.#singleItemMode = config?.getValueByAlias('singleItemMode') ?? false;
        const validationLimit = config?.getValueByAlias('validationLimit');
        this._limitMin = validationLimit?.min ?? 0;
        this._limitMax = this.#singleItemMode ? 1 : (validationLimit?.max ?? Infinity);
    }
    _onChange(event) {
        if (this.#singleItemMode) {
            this._value = event.target.selection[0];
        }
        else {
            this._value = event.target.selection;
        }
        this.dispatchEvent(new UmbChangeEvent());
    }
    // TODO: Implement mandatory?
    render() {
        return html `
			<umb-input-static-file
				.selection=${this._value ? (Array.isArray(this._value) ? this._value : [this._value]) : []}
				.min=${this._limitMin ?? 0}
				.max=${this._limitMax ?? Infinity}
				@change=${this._onChange}></umb-input-static-file>
		`;
    }
};
__decorate([
    state()
], UmbPropertyEditorUIStaticFilePickerElement.prototype, "_value", void 0);
__decorate([
    property({ attribute: false })
], UmbPropertyEditorUIStaticFilePickerElement.prototype, "value", null);
__decorate([
    state()
], UmbPropertyEditorUIStaticFilePickerElement.prototype, "_limitMin", void 0);
__decorate([
    state()
], UmbPropertyEditorUIStaticFilePickerElement.prototype, "_limitMax", void 0);
UmbPropertyEditorUIStaticFilePickerElement = __decorate([
    customElement('umb-property-editor-ui-static-file-picker')
], UmbPropertyEditorUIStaticFilePickerElement);
export { UmbPropertyEditorUIStaticFilePickerElement };
export { UmbPropertyEditorUIStaticFilePickerElement as element };
export default UmbPropertyEditorUIStaticFilePickerElement;
