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 { UMB_PROPERTY_DATASET_CONTEXT } from '../../../../core/property/index.js';
import { UmbChangeEvent } from '../../../../core/event/index.js';
/**
 * @element umb-property-editor-ui-collection-order-by
 */
let UmbPropertyEditorUICollectionOrderByElement = class UmbPropertyEditorUICollectionOrderByElement extends UmbLitElement {
    constructor() {
        super();
        this.value = '';
        this._options = [];
        this.consumeContext(UMB_PROPERTY_DATASET_CONTEXT, async (instance) => {
            const workspace = instance;
            this.observe(await workspace?.propertyValueByAlias('includeProperties'), (includeProperties) => {
                if (!includeProperties)
                    return;
                const options = includeProperties.map((property) => ({
                    name: property.header,
                    value: property.alias,
                    selected: property.alias === this.value,
                }));
                this._options = [
                    { name: this.localize.term('general_name'), value: 'name', selected: 'name' === this.value },
                    ...options,
                ];
            }, '_observeIncludeProperties');
        });
    }
    #onChange(e) {
        this.value = e.target.value;
        this.dispatchEvent(new UmbChangeEvent());
    }
    render() {
        if (!this._options.length)
            return html `<p><em>Add a column (above) to order by.</em></p>`;
        return html `<uui-select label="select" .options=${this._options} @change=${this.#onChange}></uui-select>`;
    }
};
__decorate([
    property()
], UmbPropertyEditorUICollectionOrderByElement.prototype, "value", void 0);
__decorate([
    state()
], UmbPropertyEditorUICollectionOrderByElement.prototype, "_options", void 0);
UmbPropertyEditorUICollectionOrderByElement = __decorate([
    customElement('umb-property-editor-ui-collection-order-by')
], UmbPropertyEditorUICollectionOrderByElement);
export { UmbPropertyEditorUICollectionOrderByElement };
export default UmbPropertyEditorUICollectionOrderByElement;
