import * as tslib_1 from "tslib";
import { IgcHTMLElement } from "igniteui-webcomponents-core";
import { PropertyEditorValueType_$type } from "./PropertyEditorValueType";
import { IgcPropertyEditorDescriptionObject } from "./igc-property-editor-description-object";
import { IgcPropertyEditorDescriptionObjectCollection } from "./igc-property-editor-description-object-collection";
import { PropertyEditorPropertyDescription } from "./PropertyEditorPropertyDescription";
import { TypeRegistrar } from "igniteui-webcomponents-core";
import { NamePatcher, getAllPropertyNames, fromSpinal, toSpinal, ensureEnum, enumToString, ensureBool, initializePropertiesFromCss } from "igniteui-webcomponents-core";
import { RegisterElementHelper } from "igniteui-webcomponents-core";
import { PropertyEditorDescriptionObjectCollection as PropertyEditorDescriptionObjectCollection_internal } from "./PropertyEditorDescriptionObjectCollection";
import { PropertyEditorDescriptionObject } from "./PropertyEditorDescriptionObject";
import { SyncableObservableCollection$1 } from "igniteui-webcomponents-core";
var IgcPropertyEditorPropertyDescriptionComponent = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(IgcPropertyEditorPropertyDescriptionComponent, _super);
    function IgcPropertyEditorPropertyDescriptionComponent() {
        var _this = _super.call(this) || this;
        _this._settingAttributes = false;
        _this._attached = false;
        _this._queuedSetAttributes = [];
        _this._updatingFromAttribute = false;
        _this._complexValues = null;
        _this.__p = null;
        _this._hasUserValues = new Set();
        _this._stylingContainer = null;
        _this._stylingParent = null;
        _this._inStyling = false;
        if (_this._styling) {
            NamePatcher.ensureStylablePatched(Object.getPrototypeOf(_this));
        }
        _this._implementation = _this.createImplementation();
        _this._implementation.externalObject = _this;
        _this.onImplementationCreated();
        return _this;
    }
    IgcPropertyEditorPropertyDescriptionComponent.prototype.createImplementation = function () {
        return new PropertyEditorPropertyDescription();
    };
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "i", {
        /**
         * @hidden
         */
        get: function () {
            return this._implementation;
        } /**
                                     * @hidden
                                     */,
        enumerable: true,
        configurable: true
    });
    IgcPropertyEditorPropertyDescriptionComponent._createFromInternal = function (internal) {
        if (!internal) {
            return null;
        }
        if (!internal.$type) {
            return null;
        }
        var name = internal.$type.name;
        var externalName = "Igc" + name + "Component";
        if (!TypeRegistrar.isRegistered(externalName)) {
            return null;
        }
        return TypeRegistrar.create(externalName);
    };
    IgcPropertyEditorPropertyDescriptionComponent.prototype.onImplementationCreated = function () {
    };
    IgcPropertyEditorPropertyDescriptionComponent.prototype._enqueueSetAttribute = function (attrName, attrValue) {
        this._queuedSetAttributes.push({ attrName: attrName, attrValue: attrValue });
    };
    IgcPropertyEditorPropertyDescriptionComponent.prototype._flushQueuedAttributes = function () {
        this._settingAttributes = true;
        for (var i = 0; i < this._queuedSetAttributes.length; i++) {
            this.setAttribute(this._queuedSetAttributes[i].attrName, this._queuedSetAttributes[i].attrValue);
        }
        this._settingAttributes = false;
        this._queuedSetAttributes.length = 0;
    };
    IgcPropertyEditorPropertyDescriptionComponent.prototype._a = function (attrName, attrValue) {
        if (this._updatingFromAttribute) {
            return;
        }
        if (attrValue) {
            attrValue = attrValue.toString();
        }
        this._settingAttributes = true;
        attrName = toSpinal(attrName);
        if (this._attached) {
            this.setAttribute(attrName, attrValue);
        }
        else {
            this._enqueueSetAttribute(attrName, attrValue);
        }
        this._settingAttributes = false;
    };
    IgcPropertyEditorPropertyDescriptionComponent.prototype.connectedCallback = function () {
        if (_super.prototype["connectedCallback"]) {
            _super.prototype["connectedCallback"].call(this);
        }
        if (!this._attached) {
            this._attached = true;
            this._flushQueuedAttributes();
        }
    };
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent, "observedAttributes", {
        get: function () {
            if (IgcPropertyEditorPropertyDescriptionComponent._observedAttributesIgcPropertyEditorPropertyDescriptionComponent == null) {
                var names = getAllPropertyNames(IgcPropertyEditorPropertyDescriptionComponent);
                for (var i = 0; i < names.length; i++) {
                    names[i] = toSpinal(names[i]);
                }
                IgcPropertyEditorPropertyDescriptionComponent._observedAttributesIgcPropertyEditorPropertyDescriptionComponent = names;
            }
            return IgcPropertyEditorPropertyDescriptionComponent._observedAttributesIgcPropertyEditorPropertyDescriptionComponent;
        },
        enumerable: true,
        configurable: true
    });
    IgcPropertyEditorPropertyDescriptionComponent.prototype.attributeChangedCallback = function (name, oldValue, newValue) {
        if (this._settingAttributes) {
            return;
        }
        var setName = fromSpinal(name);
        this._updatingFromAttribute = true;
        this[setName] = newValue;
        this._updatingFromAttribute = false;
    };
    IgcPropertyEditorPropertyDescriptionComponent.register = function () {
        if (!IgcPropertyEditorPropertyDescriptionComponent._isElementRegistered) {
            IgcPropertyEditorPropertyDescriptionComponent._isElementRegistered = true;
            RegisterElementHelper.registerElement(IgcPropertyEditorPropertyDescriptionComponent.htmlTagName, IgcPropertyEditorPropertyDescriptionComponent);
        }
    };
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "propertyPath", {
        get: function () {
            return this.i.y;
        },
        set: function (v) {
            this.i.y = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "label", {
        get: function () {
            return this.i.w;
        },
        set: function (v) {
            this.i.w = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "valueType", {
        get: function () {
            return this.i.k;
        },
        set: function (v) {
            this.i.k = ensureEnum(PropertyEditorValueType_$type, v);
            this._a("valueType", enumToString(PropertyEditorValueType_$type, this.i.k));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "propertyDescriptionType", {
        get: function () {
            return this.i.x;
        },
        set: function (v) {
            this.i.x = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "shouldOverrideDefaultEditor", {
        get: function () {
            return this.i.n;
        },
        set: function (v) {
            this.i.n = ensureBool(v);
            this._a("shouldOverrideDefaultEditor", this.i.n);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "elementDescriptionType", {
        get: function () {
            return this.i.v;
        },
        set: function (v) {
            this.i.v = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "dropDownNames", {
        get: function () {
            return this.i.c;
        },
        set: function (v) {
            this.i.c = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "dropDownValues", {
        get: function () {
            return this.i.d;
        },
        set: function (v) {
            this.i.d = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "primitiveValue", {
        get: function () {
            return this.i.q;
        },
        set: function (v) {
            this.i.q = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "complexValue", {
        get: function () {
            if (this.i.g == null) {
                return null;
            }
            if (!this.i.g.externalObject) {
                var e = new IgcPropertyEditorDescriptionObject();
                e._implementation = this.i.g;
                this.i.g.externalObject = e;
            }
            return this.i.g.externalObject;
        },
        set: function (v) {
            v == null ? this.i.g = null : this.i.g = v.i;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "complexValues", {
        get: function () {
            if (this._complexValues === null) {
                var coll = new IgcPropertyEditorDescriptionObjectCollection();
                var innerColl = this.i.i;
                if (!innerColl) {
                    innerColl = new PropertyEditorDescriptionObjectCollection_internal();
                }
                this._complexValues = coll._fromInner(innerColl);
                this.i.i = innerColl;
            }
            return this._complexValues;
        },
        set: function (v) {
            if (this._complexValues !== null) {
                this._complexValues._setSyncTarget(null);
                this._complexValues = null;
            }
            var coll = new IgcPropertyEditorDescriptionObjectCollection();
            this._complexValues = coll._fromOuter(v);
            var syncColl = new SyncableObservableCollection$1(PropertyEditorDescriptionObject.$type);
            var innerColl = this.i.i;
            if (!innerColl) {
                innerColl = new PropertyEditorDescriptionObjectCollection_internal();
            }
            syncColl._inner = innerColl;
            syncColl.clear();
            this._complexValues._setSyncTarget(syncColl);
            this.i.i = innerColl;
        },
        enumerable: true,
        configurable: true
    });
    IgcPropertyEditorPropertyDescriptionComponent.prototype.findByName = function (name) {
        if (this.complexValue && this.complexValue.name && this.complexValue.name == name) {
            return this.complexValue;
        }
        if (this.complexValues != null && this.complexValues.findByName && this.complexValues.findByName(name)) {
            return this.complexValues.findByName(name);
        }
        return null;
    };
    Object.defineProperty(IgcPropertyEditorPropertyDescriptionComponent.prototype, "hasUserValues", {
        get: function () {
            return this._hasUserValues;
        },
        enumerable: true,
        configurable: true
    });
    IgcPropertyEditorPropertyDescriptionComponent.prototype.__m = function (propertyName) {
        if (!this._inStyling) {
            this._hasUserValues.add(propertyName);
        }
    };
    IgcPropertyEditorPropertyDescriptionComponent.prototype._styling = function (container, component, parent) {
        if (this._inStyling) {
            return;
        }
        this._inStyling = true;
        this._stylingContainer = container;
        this._stylingParent = component;
        var genericPrefix = "";
        var typeName = this.i.$type.name;
        if (typeName.indexOf("Xam") === 0) {
            typeName = typeName.substring(3);
        }
        genericPrefix = toSpinal("PropertyEditorPropertyDescriptionComponent");
        var additionalPrefixes = [];
        var prefix = toSpinal(typeName);
        additionalPrefixes.push(prefix + "-");
        var b = this.i.$type.baseType;
        while (b && b.name != "Object" &&
            b.name != "Base" &&
            b.name != "Control" &&
            b.Name != "DependencyObject" &&
            b.Name != "FrameworkElement") {
            typeName = b.name;
            if (typeName.indexOf("Xam") === 0) {
                typeName = typeName.substring(3);
            }
            var basePrefix = toSpinal(typeName);
            additionalPrefixes.push(basePrefix + "-");
            b = b.baseType;
        }
        if (parent) {
            var parentTypeName = parent.i.$type.name;
            if (parentTypeName.indexOf("Xam") === 0) {
                parentTypeName = parentTypeName.substring(3);
            }
            var parentPrefix = toSpinal(parentTypeName);
            additionalPrefixes.push(parentPrefix + "-" + genericPrefix + "-");
            additionalPrefixes.push(parentPrefix + "-" + prefix + "-");
        }
        initializePropertiesFromCss(container, this, genericPrefix + "-", this.hasUserValues, false, additionalPrefixes);
        if (this._otherStyling) {
            this._otherStyling(container, component, parent);
        }
        this._inStyling = false;
    };
    IgcPropertyEditorPropertyDescriptionComponent._observedAttributesIgcPropertyEditorPropertyDescriptionComponent = null;
    IgcPropertyEditorPropertyDescriptionComponent.htmlTagName = "igc-property-editor-property-description";
    IgcPropertyEditorPropertyDescriptionComponent._isElementRegistered = false;
    return IgcPropertyEditorPropertyDescriptionComponent;
}(IgcHTMLElement));
export { IgcPropertyEditorPropertyDescriptionComponent };
//# sourceMappingURL=igc-property-editor-property-description-component.js.map
