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 { UmbPropertyDatasetContextBase } from './property-dataset-base-context.js';
import { UmbLitElement } from '../../lit-element/index.js';
import { customElement, html, property } from '../../../../external/lit/index.js';
import { UmbChangeEvent } from '../../event/index.js';
/**
 *  @element umb-property-dataset
 *  @description - Element for hosting a property dataset. This is needed for umb-property to work.
 *  @slot default - Slot for rendering content within.
 */
let UmbPropertyDatasetElement = class UmbPropertyDatasetElement extends UmbLitElement {
    // Determine wether state change should fire an event when the value is changed.
    #allowChangeEvent = false;
    set value(value) {
        this.#allowChangeEvent = false;
        this.context.setValues(value);
        // Above might not trigger a observer callback (if no change), so set the allow change event to true:
        this.#allowChangeEvent = true;
    }
    get value() {
        return this.context.getValues();
    }
    set name(value) {
        this.#allowChangeEvent = false;
        this.context.setName(value);
        // Above might not trigger a observer callback (if no change), so set the allow change event to true:
        this.#allowChangeEvent = true;
    }
    get name() {
        return this.context.getName();
    }
    constructor() {
        super();
        // Prevent any child events escaping this element.
        this.addEventListener('change', (e) => {
            if (e.target !== this) {
                e.stopImmediatePropagation();
            }
        });
        this.context = new UmbPropertyDatasetContextBase(this);
        // prevent the first change event from firing:
        this.#allowChangeEvent = false;
        this.observe(this.context.name, this.#observerCallback);
        // prevent the first change event from firing:
        this.#allowChangeEvent = false;
        this.observe(this.context.properties, this.#observerCallback);
    }
    #observerCallback = () => {
        if (this.#allowChangeEvent) {
            this.dispatchEvent(new UmbChangeEvent());
        }
        else {
            // Set allow change event to true.
            this.#allowChangeEvent = true;
        }
    };
    render() {
        return html `<slot></slot>`;
    }
};
__decorate([
    property({ attribute: false })
    /**
     * The value of the dataset.
     * @returns {Array<UmbPropertyValueData>} - The value of the dataset
     * @example
     * ```ts
     * const dataSet = [
     * 	{
     * 		alias: 'testAlias',
     * 		value: 'value as a string',
     * 	},
     *  {
     * 		alias: 'anotherAlias',
     * 		value: 123,
     * 	}
     * ]
     *
     * html`
     * <umb-property-dataset .value="${dataSet}">
     * 	<umb-property
     * 		label="My label for this property"
     * 		description="The description to show on the property"
     * 		alias="testAlias"
     * 		property-editor-ui-alias="Umb.PropertyEditorUi.TextBox"
     * 		.config=${...}>
     * 	</umb-property>
     * </umb-property-dataset>
     * `
     * ```
     */
], UmbPropertyDatasetElement.prototype, "value", null);
__decorate([
    property({ attribute: false })
    /**
     * The name of the dataset, this name varies depending on the use-case. But this is either
     * @property name
     * @type {string}
     * @returns {string}
     * @example
     * ```ts
     * html`
     * <umb-property-dataset name="My variant name">
     * 	...
     * </umb-property-dataset>
     * `
     */
], UmbPropertyDatasetElement.prototype, "name", null);
UmbPropertyDatasetElement = __decorate([
    customElement('umb-property-dataset')
], UmbPropertyDatasetElement);
export { UmbPropertyDatasetElement };
export default UmbPropertyDatasetElement;
