import * as tslib_1 from "tslib";
import { ensureEnum, brushToString, stringToBrush, initializePropertiesFromCss, NamePatcher, toSpinal, enumToString, getAllPropertyNames, fromSpinal } from "igniteui-webcomponents-core";
import { FontInfo } from "igniteui-webcomponents-core";
import { WebComponentRenderer } from "igniteui-webcomponents-core";
import { TypeRegistrar } from "igniteui-webcomponents-core";
import { RegisterElementHelper } from "igniteui-webcomponents-core";
import { ColumnChooser } from './ColumnChooser';
import { BaseControlTheme_$type } from "igniteui-webcomponents-core";
import { ControlDisplayDensity_$type } from "igniteui-webcomponents-core";
import { IgcHTMLElement } from "igniteui-webcomponents-core";
var IgcColumnChooserComponent = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(IgcColumnChooserComponent, _super);
    function IgcColumnChooserComponent() {
        var _this = _super.call(this) || this;
        _this._disconnected = false;
        _this._settingAttributes = false;
        _this._attached = false;
        _this._queuedSetAttributes = [];
        _this._updatingFromAttribute = false;
        _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._renderer = new WebComponentRenderer(_this, document, true, null);
        _this._implementation = _this.createImplementation();
        _this._container = _this._renderer.createElement("div");
        _this._renderer.updateRoot(_this._container);
        //this._renderer.rootWrapper.append(this._container);
        _this._container.setStyleProperty("display", "block");
        _this._container.setStyleProperty("width", "100%");
        _this._container.setStyleProperty("height", "100%");
        var columnChooser = _this.i;
        _this._columnChooser = columnChooser;
        _this._renderer.addSizeWatcher(function () {
            _this._columnChooser.notifySizeChanged();
        });
        return _this;
    }
    Object.defineProperty(IgcColumnChooserComponent.prototype, "height", {
        get: function () {
            return this._height;
        },
        set: function (value) {
            this._height = value;
            this.style.height = value;
            this.i.notifySizeChanged();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcColumnChooserComponent.prototype, "width", {
        get: function () {
            return this._width;
        },
        set: function (value) {
            this._width = value;
            this.style.width = value;
            this.i.notifySizeChanged();
        },
        enumerable: true,
        configurable: true
    });
    // supports angular themes or custom properties set in CSS
    IgcColumnChooserComponent.prototype.updateStyle = function () {
        this._styling(this, this);
    };
    IgcColumnChooserComponent.prototype.destroy = function () {
        this._columnChooser.destroy();
    };
    IgcColumnChooserComponent.prototype.createImplementation = function () {
        return new ColumnChooser();
    };
    IgcColumnChooserComponent.prototype.disconnectedCallback = function () {
        this._disconnected = true;
    };
    IgcColumnChooserComponent.prototype.connectedCallback = function () {
        if (this._disconnected) {
            this._disconnected = false;
            return;
        }
        this.classList.add("ig-column-chooser");
        this.classList.add("igc-column-chooser");
        var rootWrapper = this._renderer.rootWrapper;
        var rootElement = rootWrapper.getNativeElement();
        this.appendChild(rootElement);
        this._attached = true;
        this.style.display = "block";
        this.style.height = this._height;
        this.style.width = this._width;
        var title = this._renderer.createElement("span");
        this._container.append(title);
        var checkboxList = this._renderer.createElement("igc-checkbox-list");
        this._container.append(checkboxList);
        this._columnChooser.provideContainer(this._renderer, checkboxList.getNativeElement().i);
        this._columnChooser.notifySizeChanged();
        this._flushQueuedAttributes();
        // supports themes or custom properties set in CSS 
        this._styling(this, this);
        this.afterContentInit();
    };
    IgcColumnChooserComponent.prototype.afterContentInit = function () {
        this.i.notifySizeChanged();
    };
    Object.defineProperty(IgcColumnChooserComponent.prototype, "i", {
        /**
         * @hidden
         */
        get: function () {
            return this._implementation;
        } /**
                                     * @hidden
                                     */,
        enumerable: true,
        configurable: true
    });
    IgcColumnChooserComponent._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);
    };
    IgcColumnChooserComponent.prototype._enqueueSetAttribute = function (attrName, attrValue) {
        this._queuedSetAttributes.push({ attrName: attrName, attrValue: attrValue });
    };
    IgcColumnChooserComponent.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;
    };
    IgcColumnChooserComponent.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;
    };
    Object.defineProperty(IgcColumnChooserComponent, "observedAttributes", {
        get: function () {
            if (IgcColumnChooserComponent._observedAttributesIgcColumnChooserComponent == null) {
                var names = getAllPropertyNames(IgcColumnChooserComponent);
                for (var i = 0; i < names.length; i++) {
                    names[i] = toSpinal(names[i]);
                }
                IgcColumnChooserComponent._observedAttributesIgcColumnChooserComponent = names;
            }
            return IgcColumnChooserComponent._observedAttributesIgcColumnChooserComponent;
        },
        enumerable: true,
        configurable: true
    });
    IgcColumnChooserComponent.prototype.attributeChangedCallback = function (name, oldValue, newValue) {
        if (this._settingAttributes) {
            return;
        }
        var setName = fromSpinal(name);
        this._updatingFromAttribute = true;
        this[setName] = newValue;
        this._updatingFromAttribute = false;
    };
    IgcColumnChooserComponent.register = function () {
        if (!IgcColumnChooserComponent._isElementRegistered) {
            IgcColumnChooserComponent._isElementRegistered = true;
            RegisterElementHelper.registerElement(IgcColumnChooserComponent.htmlTagName, IgcColumnChooserComponent);
        }
    };
    Object.defineProperty(IgcColumnChooserComponent.prototype, "targetGrid", {
        /**
     * Gets or Sets the property name that contains the values.
    */
        get: function () {
            if (this.i.b == null) {
                return null;
            }
            return this.i.b.externalObject;
        },
        set: function (v) {
            if (v != null && this._stylingContainer && v._styling)
                v._styling(this._stylingContainer, this, this);
            v == null ? this.i.b = null : this.i.b = v.i;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcColumnChooserComponent.prototype, "title", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.v;
        },
        set: function (v) {
            this.i.v = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcColumnChooserComponent.prototype, "titleStyle", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            if (this.i.j == null) {
                return null;
            }
            return this.i.j.fontString;
        },
        set: function (v) {
            var fi = new FontInfo();
            fi.fontString = v;
            this.i.j = fi;
            this._a("titleStyle", this.i.j != null ? this.i.j.fontString : "");
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcColumnChooserComponent.prototype, "titleColor", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return brushToString(this.i.ar);
        },
        set: function (v) {
            this.i.ar = stringToBrush(v);
            this._a("titleColor", brushToString(this.i.ar));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcColumnChooserComponent.prototype, "filterPlaceholderText", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.s;
        },
        set: function (v) {
            this.i.s = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcColumnChooserComponent.prototype, "baseTheme", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.e;
        },
        set: function (v) {
            this.i.e = ensureEnum(BaseControlTheme_$type, v);
            this._a("baseTheme", enumToString(BaseControlTheme_$type, this.i.e));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcColumnChooserComponent.prototype, "density", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.g;
        },
        set: function (v) {
            this.i.g = ensureEnum(ControlDisplayDensity_$type, v);
            this._a("density", enumToString(ControlDisplayDensity_$type, this.i.g));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcColumnChooserComponent.prototype, "backgroundColor", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return brushToString(this.i.aq);
        },
        set: function (v) {
            this.i.aq = stringToBrush(v);
            this._a("backgroundColor", brushToString(this.i.aq));
        },
        enumerable: true,
        configurable: true
    });
    IgcColumnChooserComponent.prototype.findByName = function (name) {
        if (this.targetGrid && this.targetGrid.name && this.targetGrid.name == name) {
            return this.targetGrid;
        }
        return null;
    };
    Object.defineProperty(IgcColumnChooserComponent.prototype, "hasUserValues", {
        get: function () {
            return this._hasUserValues;
        },
        enumerable: true,
        configurable: true
    });
    IgcColumnChooserComponent.prototype.__m = function (propertyName) {
        if (!this._inStyling) {
            this._hasUserValues.add(propertyName);
        }
    };
    IgcColumnChooserComponent.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("ColumnChooserComponent");
        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.targetGrid && this.targetGrid._styling) {
            this.targetGrid._styling(container, component, this);
        }
        if (this._otherStyling) {
            this._otherStyling(container, component, parent);
        }
        this._inStyling = false;
    };
    IgcColumnChooserComponent._observedAttributesIgcColumnChooserComponent = null;
    IgcColumnChooserComponent.htmlTagName = "igc-column-chooser";
    IgcColumnChooserComponent._isElementRegistered = false;
    return IgcColumnChooserComponent;
}(IgcHTMLElement));
export { IgcColumnChooserComponent };
//# sourceMappingURL=igc-column-chooser-component.js.map
