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";
export let IgcPropertyEditorPropertyDescriptionComponent = /*@__PURE__*/ (() => {
    class IgcPropertyEditorPropertyDescriptionComponent extends IgcHTMLElement {
        constructor() {
            super();
            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();
        }
        createImplementation() {
            return new PropertyEditorPropertyDescription();
        }
        /**
         * @hidden
         */
        get i() {
            return this._implementation;
        } /**
                                     * @hidden
                                     */
        static _createFromInternal(internal) {
            if (!internal) {
                return null;
            }
            if (!internal.$type) {
                return null;
            }
            let name = internal.$type.name;
            let externalName = "Igc" + name + "Component";
            if (!TypeRegistrar.isRegistered(externalName)) {
                return null;
            }
            return TypeRegistrar.create(externalName);
        }
        onImplementationCreated() {
        }
        _enqueueSetAttribute(attrName, attrValue) {
            this._queuedSetAttributes.push({ attrName: attrName, attrValue: attrValue });
        }
        _flushQueuedAttributes() {
            this._settingAttributes = true;
            for (let i = 0; i < this._queuedSetAttributes.length; i++) {
                this.setAttribute(this._queuedSetAttributes[i].attrName, this._queuedSetAttributes[i].attrValue);
            }
            this._settingAttributes = false;
            this._queuedSetAttributes.length = 0;
        }
        _a(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;
        }
        connectedCallback() {
            if (super["connectedCallback"]) {
                super["connectedCallback"]();
            }
            if (!this._attached) {
                this._attached = true;
                this._flushQueuedAttributes();
            }
        }
        static get observedAttributes() {
            if (IgcPropertyEditorPropertyDescriptionComponent._observedAttributesIgcPropertyEditorPropertyDescriptionComponent == null) {
                let names = getAllPropertyNames(IgcPropertyEditorPropertyDescriptionComponent);
                for (let i = 0; i < names.length; i++) {
                    names[i] = toSpinal(names[i]);
                }
                IgcPropertyEditorPropertyDescriptionComponent._observedAttributesIgcPropertyEditorPropertyDescriptionComponent = names;
            }
            return IgcPropertyEditorPropertyDescriptionComponent._observedAttributesIgcPropertyEditorPropertyDescriptionComponent;
        }
        attributeChangedCallback(name, oldValue, newValue) {
            if (this._settingAttributes) {
                return;
            }
            let setName = fromSpinal(name);
            this._updatingFromAttribute = true;
            this[setName] = newValue;
            this._updatingFromAttribute = false;
        }
        static register() {
            if (!IgcPropertyEditorPropertyDescriptionComponent._isElementRegistered) {
                IgcPropertyEditorPropertyDescriptionComponent._isElementRegistered = true;
                RegisterElementHelper.registerElement(IgcPropertyEditorPropertyDescriptionComponent.htmlTagName, IgcPropertyEditorPropertyDescriptionComponent);
            }
        }
        get propertyPath() {
            return this.i.y;
        }
        set propertyPath(v) {
            this.i.y = v;
        }
        get label() {
            return this.i.w;
        }
        set label(v) {
            this.i.w = v;
        }
        get valueType() {
            return this.i.k;
        }
        set valueType(v) {
            this.i.k = ensureEnum(PropertyEditorValueType_$type, v);
            this._a("valueType", enumToString(PropertyEditorValueType_$type, this.i.k));
        }
        get propertyDescriptionType() {
            return this.i.x;
        }
        set propertyDescriptionType(v) {
            this.i.x = v;
        }
        get shouldOverrideDefaultEditor() {
            return this.i.n;
        }
        set shouldOverrideDefaultEditor(v) {
            this.i.n = ensureBool(v);
            this._a("shouldOverrideDefaultEditor", this.i.n);
        }
        get elementDescriptionType() {
            return this.i.v;
        }
        set elementDescriptionType(v) {
            this.i.v = v;
        }
        get dropDownNames() {
            return this.i.c;
        }
        set dropDownNames(v) {
            this.i.c = v;
        }
        get dropDownValues() {
            return this.i.d;
        }
        set dropDownValues(v) {
            this.i.d = v;
        }
        get primitiveValue() {
            return this.i.q;
        }
        set primitiveValue(v) {
            this.i.q = v;
        }
        get complexValue() {
            if (this.i.g == null) {
                return null;
            }
            if (!this.i.g.externalObject) {
                let e = new IgcPropertyEditorDescriptionObject();
                e._implementation = this.i.g;
                this.i.g.externalObject = e;
            }
            return this.i.g.externalObject;
        }
        set complexValue(v) {
            v == null ? this.i.g = null : this.i.g = v.i;
        }
        get complexValues() {
            if (this._complexValues === null) {
                let coll = new IgcPropertyEditorDescriptionObjectCollection();
                let innerColl = this.i.i;
                if (!innerColl) {
                    innerColl = new PropertyEditorDescriptionObjectCollection_internal();
                }
                this._complexValues = coll._fromInner(innerColl);
                this.i.i = innerColl;
            }
            return this._complexValues;
        }
        set complexValues(v) {
            if (this._complexValues !== null) {
                this._complexValues._setSyncTarget(null);
                this._complexValues = null;
            }
            let coll = new IgcPropertyEditorDescriptionObjectCollection();
            this._complexValues = coll._fromOuter(v);
            let syncColl = new SyncableObservableCollection$1(PropertyEditorDescriptionObject.$type);
            let innerColl = this.i.i;
            if (!innerColl) {
                innerColl = new PropertyEditorDescriptionObjectCollection_internal();
            }
            syncColl._inner = innerColl;
            syncColl.clear();
            this._complexValues._setSyncTarget(syncColl);
            this.i.i = innerColl;
        }
        findByName(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;
        }
        get hasUserValues() {
            return this._hasUserValues;
        }
        __m(propertyName) {
            if (!this._inStyling) {
                this._hasUserValues.add(propertyName);
            }
        }
        _styling(container, component, parent) {
            if (this._inStyling) {
                return;
            }
            this._inStyling = true;
            this._stylingContainer = container;
            this._stylingParent = component;
            let genericPrefix = "";
            let typeName = this.i.$type.name;
            if (typeName.indexOf("Xam") === 0) {
                typeName = typeName.substring(3);
            }
            genericPrefix = toSpinal("PropertyEditorPropertyDescriptionComponent");
            let additionalPrefixes = [];
            let prefix = toSpinal(typeName);
            additionalPrefixes.push(prefix + "-");
            let 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);
                }
                let basePrefix = toSpinal(typeName);
                additionalPrefixes.push(basePrefix + "-");
                b = b.baseType;
            }
            if (parent) {
                let parentTypeName = parent.i.$type.name;
                if (parentTypeName.indexOf("Xam") === 0) {
                    parentTypeName = parentTypeName.substring(3);
                }
                let 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;
})();
//# sourceMappingURL=igc-property-editor-property-description-component.js.map
