import * as tslib_1 from "tslib";
import { ensureEnum, brushToString, stringToBrush, ensureBool, 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 { DataGridToolbar } from './DataGridToolbar';
import { ControlDisplayDensity_$type } from "igniteui-webcomponents-core";
import { BaseControlTheme_$type } from "igniteui-webcomponents-core";
import { IgcHTMLElement } from "igniteui-webcomponents-core";
var IgcDataGridToolbarComponent = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(IgcDataGridToolbarComponent, _super);
    function IgcDataGridToolbarComponent() {
        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("width", "100%");
        //this._container.setStyleProperty("height", "100%");
        var toolbar = _this.i;
        _this._toolbar = toolbar;
        _this._renderer.addSizeWatcher(function () {
            _this._toolbar.notifySizeChanged();
        });
        return _this;
    }
    Object.defineProperty(IgcDataGridToolbarComponent.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(IgcDataGridToolbarComponent.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
    IgcDataGridToolbarComponent.prototype.updateStyle = function () {
        this._styling(this, this);
    };
    IgcDataGridToolbarComponent.prototype.destroy = function () {
        this._toolbar.destroy();
    };
    IgcDataGridToolbarComponent.prototype.createImplementation = function () {
        return new DataGridToolbar();
    };
    IgcDataGridToolbarComponent.prototype.disconnectedCallback = function () {
        this._disconnected = true;
    };
    IgcDataGridToolbarComponent.prototype.connectedCallback = function () {
        if (this._disconnected) {
            this._disconnected = false;
            return;
        }
        this.classList.add("ig-data-grid-toolbar");
        this.classList.add("igc-data-grid-toolbar");
        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 buttonsContainer = this._renderer.createElement("div");
        this._container.append(buttonsContainer);
        var hideBtnContainer = this._renderer.createElement("div");
        buttonsContainer.append(hideBtnContainer);
        var pinBtnContainer = this._renderer.createElement("div");
        buttonsContainer.append(pinBtnContainer);
        var chooserDialog = this._renderer.createElement("div");
        this._container.append(chooserDialog);
        var columnChooser = this._renderer.createElement("igc-column-chooser");
        chooserDialog.append(columnChooser);
        var pinningDialog = this._renderer.createElement("div");
        this._container.append(pinningDialog);
        var columnPinning = this._renderer.createElement("igc-column-pinning");
        pinningDialog.append(columnPinning);
        this._toolbar.provideContainer(this._renderer, columnChooser.getNativeElement().i, columnPinning.getNativeElement().i);
        this._toolbar.notifySizeChanged();
        this._flushQueuedAttributes();
        // supports themes or custom properties set in CSS 
        this._styling(this, this);
        this.afterContentInit();
    };
    IgcDataGridToolbarComponent.prototype.afterContentInit = function () {
        this.i.notifySizeChanged();
    };
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "i", {
        /**
         * @hidden
         */
        get: function () {
            return this._implementation;
        } /**
                                     * @hidden
                                     */,
        enumerable: true,
        configurable: true
    });
    IgcDataGridToolbarComponent._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);
    };
    IgcDataGridToolbarComponent.prototype._enqueueSetAttribute = function (attrName, attrValue) {
        this._queuedSetAttributes.push({ attrName: attrName, attrValue: attrValue });
    };
    IgcDataGridToolbarComponent.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;
    };
    IgcDataGridToolbarComponent.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(IgcDataGridToolbarComponent, "observedAttributes", {
        get: function () {
            if (IgcDataGridToolbarComponent._observedAttributesIgcDataGridToolbarComponent == null) {
                var names = getAllPropertyNames(IgcDataGridToolbarComponent);
                for (var i = 0; i < names.length; i++) {
                    names[i] = toSpinal(names[i]);
                }
                IgcDataGridToolbarComponent._observedAttributesIgcDataGridToolbarComponent = names;
            }
            return IgcDataGridToolbarComponent._observedAttributesIgcDataGridToolbarComponent;
        },
        enumerable: true,
        configurable: true
    });
    IgcDataGridToolbarComponent.prototype.attributeChangedCallback = function (name, oldValue, newValue) {
        if (this._settingAttributes) {
            return;
        }
        var setName = fromSpinal(name);
        this._updatingFromAttribute = true;
        this[setName] = newValue;
        this._updatingFromAttribute = false;
    };
    IgcDataGridToolbarComponent.register = function () {
        if (!IgcDataGridToolbarComponent._isElementRegistered) {
            IgcDataGridToolbarComponent._isElementRegistered = true;
            RegisterElementHelper.registerElement(IgcDataGridToolbarComponent.htmlTagName, IgcDataGridToolbarComponent);
        }
    };
    Object.defineProperty(IgcDataGridToolbarComponent.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(IgcDataGridToolbarComponent.prototype, "toolbarTitle", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.ap;
        },
        set: function (v) {
            this.i.ap = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "toolbarTitleStyle", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            if (this.i.m == null) {
                return null;
            }
            return this.i.m.fontString;
        },
        set: function (v) {
            var fi = new FontInfo();
            fi.fontString = v;
            this.i.m = fi;
            this._a("toolbarTitleStyle", this.i.m != null ? this.i.m.fontString : "");
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "toolbarTitleColor", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return brushToString(this.i.bd);
        },
        set: function (v) {
            this.i.bd = stringToBrush(v);
            this._a("toolbarTitleColor", brushToString(this.i.bd));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "backgroundColor", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return brushToString(this.i.bb);
        },
        set: function (v) {
            this.i.bb = stringToBrush(v);
            this._a("backgroundColor", brushToString(this.i.bb));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "dialogBackgroundColor", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return brushToString(this.i.bc);
        },
        set: function (v) {
            this.i.bc = stringToBrush(v);
            this._a("dialogBackgroundColor", brushToString(this.i.bc));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "columnChooser", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.p;
        },
        set: function (v) {
            this.i.p = ensureBool(v);
            this._a("columnChooser", this.i.p);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "columnChooserText", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.ab;
        },
        set: function (v) {
            this.i.ab = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "columnChooserTitle", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.ad;
        },
        set: function (v) {
            this.i.ad = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "columnPinning", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.q;
        },
        set: function (v) {
            this.i.q = ensureBool(v);
            this._a("columnPinning", this.i.q);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "columnPinningText", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.ag;
        },
        set: function (v) {
            this.i.ag = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "columnPinningTitle", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.ai;
        },
        set: function (v) {
            this.i.ai = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "density", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.i;
        },
        set: function (v) {
            this.i.i = ensureEnum(ControlDisplayDensity_$type, v);
            this._a("density", enumToString(ControlDisplayDensity_$type, this.i.i));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "baseTheme", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.g;
        },
        set: function (v) {
            this.i.g = ensureEnum(BaseControlTheme_$type, v);
            this._a("baseTheme", enumToString(BaseControlTheme_$type, this.i.g));
        },
        enumerable: true,
        configurable: true
    });
    IgcDataGridToolbarComponent.prototype.findByName = function (name) {
        if (this.targetGrid && this.targetGrid.name && this.targetGrid.name == name) {
            return this.targetGrid;
        }
        return null;
    };
    Object.defineProperty(IgcDataGridToolbarComponent.prototype, "hasUserValues", {
        get: function () {
            return this._hasUserValues;
        },
        enumerable: true,
        configurable: true
    });
    IgcDataGridToolbarComponent.prototype.__m = function (propertyName) {
        if (!this._inStyling) {
            this._hasUserValues.add(propertyName);
        }
    };
    IgcDataGridToolbarComponent.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("DataGridToolbarComponent");
        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;
    };
    IgcDataGridToolbarComponent._observedAttributesIgcDataGridToolbarComponent = null;
    IgcDataGridToolbarComponent.htmlTagName = "igc-data-grid-toolbar";
    IgcDataGridToolbarComponent._isElementRegistered = false;
    return IgcDataGridToolbarComponent;
}(IgcHTMLElement));
export { IgcDataGridToolbarComponent };
//# sourceMappingURL=igc-data-grid-toolbar-component.js.map
