/**
 * Extends Array to add utility functions for accessing data type properties
 * by alias, returning either the value or the complete DataTypePropertyPresentationModel object
 */
export class UmbPropertyEditorConfigCollection extends Array {
    constructor(args) {
        super(...args);
    }
    static get [Symbol.species]() {
        return Array;
    }
    getValueByAlias(alias) {
        const property = this.getByAlias(alias);
        if (property?.value === undefined || property?.value === null) {
            return;
        }
        return property.value;
    }
    getByAlias(alias) {
        return this.find((x) => x.alias === alias);
    }
    /**
     * Convert the underlying array to an object where
     * the property value is keyed by its alias
     * eg
     * `[
     *   { 'alias': 'myProperty', 'value': 27 },
     *   { 'alias': 'anotherProperty', 'value': 'eleven' },
     * ]`
     * is returned as
     * `{
     *   myProperty: 27,
     * 	 anotherProperty: 'eleven',
     * }`
     */
    toObject() {
        return Object.fromEntries(this.map((x) => [x.alias, x.value]));
    }
    equal(other) {
        if (this.length !== other?.length) {
            return false;
        }
        return this.every((x) => {
            const otherProperty = x.alias ? other.getByAlias(x.alias) : undefined;
            return otherProperty && x.value === otherProperty.value;
        });
    }
}
