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 { delegateCombine, delegateRemove } from "igniteui-webcomponents-core";
import { SyncableObservableCollection$1 } from "igniteui-webcomponents-core";
import { TypeRegistrar } from "igniteui-webcomponents-core";
import { RegisterElementHelper } from "igniteui-webcomponents-core";
import { CheckboxList } from './CheckboxList';
import { IgcCheckedChangedEventArgs } from "./igc-checked-changed-event-args";
import { IgcSelectAllCheckboxChangedEventArgs } from "./igc-select-all-checkbox-changed-event-args";
import { PrimaryKeyValue } from "./PrimaryKeyValue";
import { IgcGridSelectedKeysCollection } from "./igc-grid-selected-keys-collection";
import { GridSelectedKeysCollection as GridSelectedKeysCollection_internal } from "./GridSelectedKeysCollection";
import { CheckboxListIndexType_$type } from "./CheckboxListIndexType";
import { InputGroupDisplayType_$type } from "igniteui-webcomponents-inputs";
import { BaseControlTheme_$type } from "igniteui-webcomponents-core";
import { ControlDisplayDensity_$type } from "igniteui-webcomponents-core";
import { IgcHTMLElement } from "igniteui-webcomponents-core";
var IgcCheckboxListComponent = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(IgcCheckboxListComponent, _super);
    function IgcCheckboxListComponent() {
        var _this = _super.call(this) || this;
        _this._dataSource = null;
        _this._disconnected = false;
        _this._settingAttributes = false;
        _this._attached = false;
        _this._queuedSetAttributes = [];
        _this._updatingFromAttribute = false;
        _this._keys = null;
        _this.__p = null;
        _this._hasUserValues = new Set();
        _this._stylingContainer = null;
        _this._stylingParent = null;
        _this._inStyling = false;
        _this._checkedChanged = null;
        _this._checkedChanged_wrapped = null;
        _this._selectAllCheckboxChanged = null;
        _this._selectAllCheckboxChanged_wrapped = null;
        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._container.setStyleProperty("display", "block");
        _this._container.setStyleProperty("width", "100%");
        _this._container.setStyleProperty("height", "100%");
        var checkboxList = _this.i;
        _this._checkboxList = checkboxList;
        _this._renderer.addSizeWatcher(function () {
            _this._checkboxList.notifySizeChanged();
        });
        return _this;
    }
    Object.defineProperty(IgcCheckboxListComponent.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(IgcCheckboxListComponent.prototype, "width", {
        get: function () {
            return this._width;
        },
        set: function (value) {
            this._width = value;
            this.style.width = value;
            this.i.notifySizeChanged();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "dataSource", {
        get: function () {
            return this._dataSource;
        },
        set: function (value) {
            this._dataSource = value;
            if (this._checkboxList != null) {
                this._checkboxList.itemsSource = this._dataSource;
            }
        },
        enumerable: true,
        configurable: true
    });
    // supports angular themes or custom properties set in CSS
    IgcCheckboxListComponent.prototype.updateStyle = function () {
        this._styling(this, this);
    };
    IgcCheckboxListComponent.prototype.destroy = function () {
        this._checkboxList.destroy();
    };
    IgcCheckboxListComponent.prototype.createImplementation = function () {
        return new CheckboxList();
    };
    IgcCheckboxListComponent.prototype.disconnectedCallback = function () {
        this._disconnected = true;
    };
    IgcCheckboxListComponent.prototype.connectedCallback = function () {
        if (this._disconnected) {
            this._disconnected = false;
            return;
        }
        this.classList.add("ig-checkbox-list");
        this.classList.add("igc-checkbox-list");
        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 filterContainer = this._renderer.createElement("div");
        this._container.append(filterContainer);
        var filterHr = this._renderer.createElement("hr");
        this._container.append(filterHr);
        filterHr.setStyleProperty("margin", "3px 0px");
        filterHr.setStyleProperty("border-top", "1px solid #dde2eb");
        filterHr.setStyleProperty("border-left", "0px");
        filterHr.setStyleProperty("border-right", "0px");
        filterHr.setStyleProperty("border-bottom", "0px");
        this.i.provideHrElement(filterHr);
        /*var filterInput = this._renderer.createElement("input");
        filterInput.getNativeElement().type = "text";
        filterContainer.append(filterInput);*/
        var selectAllSection = this._renderer.createElement("div");
        this._container.append(selectAllSection);
        var grid = this._renderer.createElement("igc-data-grid");
        grid.getNativeElement().scrollbarStyle = 0 /* Default */;
        grid.getNativeElement().headerHeight = 0;
        this._container.append(grid);
        this._checkboxList.provideContainer(this._renderer, grid.getNativeElement().i, selectAllSection);
        this._checkboxList.notifySizeChanged();
        this._flushQueuedAttributes();
        // supports themes or custom properties set in CSS 
        this._styling(this, this);
        this.afterContentInit();
    };
    IgcCheckboxListComponent.prototype.afterContentInit = function () {
        this.i.notifySizeChanged();
    };
    Object.defineProperty(IgcCheckboxListComponent.prototype, "i", {
        /**
         * @hidden
         */
        get: function () {
            return this._implementation;
        } /**
                                     * @hidden
                                     */,
        enumerable: true,
        configurable: true
    });
    IgcCheckboxListComponent._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);
    };
    IgcCheckboxListComponent.prototype._enqueueSetAttribute = function (attrName, attrValue) {
        this._queuedSetAttributes.push({ attrName: attrName, attrValue: attrValue });
    };
    IgcCheckboxListComponent.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;
    };
    IgcCheckboxListComponent.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(IgcCheckboxListComponent, "observedAttributes", {
        get: function () {
            if (IgcCheckboxListComponent._observedAttributesIgcCheckboxListComponent == null) {
                var names = getAllPropertyNames(IgcCheckboxListComponent);
                for (var i = 0; i < names.length; i++) {
                    names[i] = toSpinal(names[i]);
                }
                IgcCheckboxListComponent._observedAttributesIgcCheckboxListComponent = names;
            }
            return IgcCheckboxListComponent._observedAttributesIgcCheckboxListComponent;
        },
        enumerable: true,
        configurable: true
    });
    IgcCheckboxListComponent.prototype.attributeChangedCallback = function (name, oldValue, newValue) {
        if (this._settingAttributes) {
            return;
        }
        var setName = fromSpinal(name);
        this._updatingFromAttribute = true;
        this[setName] = newValue;
        this._updatingFromAttribute = false;
    };
    IgcCheckboxListComponent.register = function () {
        if (!IgcCheckboxListComponent._isElementRegistered) {
            IgcCheckboxListComponent._isElementRegistered = true;
            RegisterElementHelper.registerElement(IgcCheckboxListComponent.htmlTagName, IgcCheckboxListComponent);
        }
    };
    Object.defineProperty(IgcCheckboxListComponent.prototype, "keys", {
        /**
         * Gets the collection responsible for selection in the CheckboxList. Selection is determined by two factors:
         * whether everything is selected or deselected and the values present in this collection. If everything is
         * selected then any items in this collection will be deselected. If everything is deselected then any items in
         * this collection will be selected. The CheckboxList defaults all items as deselected. This state can change
         * when you use the SelectAll and DeselectAll methods.
        */
        get: function () {
            if (this._keys === null) {
                var coll = new IgcGridSelectedKeysCollection();
                var innerColl = this.i.g;
                if (!innerColl) {
                    innerColl = new GridSelectedKeysCollection_internal();
                }
                this._keys = coll._fromInner(innerColl);
            }
            return this._keys;
        },
        set: function (v) {
            if (this._keys !== null) {
                this._keys._setSyncTarget(null);
                this._keys = null;
            }
            var coll = new IgcGridSelectedKeysCollection();
            this._keys = coll._fromOuter(v);
            var syncColl = new SyncableObservableCollection$1(PrimaryKeyValue.$type);
            var innerColl = this.i.g;
            if (!innerColl) {
                innerColl = new GridSelectedKeysCollection_internal();
            }
            syncColl._inner = innerColl;
            syncColl.clear();
            this._keys._setSyncTarget(syncColl);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "primaryKey", {
        /**
         * Gets or sets the primary key to use for the CheckboxList.
        */
        get: function () {
            return this.i.b;
        },
        set: function (v) {
            this.i.b = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "dataMemberPath", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.a2;
        },
        set: function (v) {
            this.i.a2 = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "selectedMemberPath", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.bj;
        },
        set: function (v) {
            this.i.bj = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "filterPlaceholderText", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.a6;
        },
        set: function (v) {
            this.i.a6 = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "searchInputType", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.x;
        },
        set: function (v) {
            this.i.x = ensureEnum(InputGroupDisplayType_$type, v);
            this._a("searchInputType", enumToString(InputGroupDisplayType_$type, this.i.x));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "rowHeight", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.as;
        },
        set: function (v) {
            this.i.as = +v;
            this._a("rowHeight", this.i.as);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "actualRowHeight", {
        get: function () {
            return this.i.aq;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "cellTextStyle", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            if (this.i.ab == null) {
                return null;
            }
            return this.i.ab.fontString;
        },
        set: function (v) {
            var fi = new FontInfo();
            fi.fontString = v;
            this.i.ab = fi;
            this._a("cellTextStyle", this.i.ab != null ? this.i.ab.fontString : "");
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "indexType", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.p;
        },
        set: function (v) {
            this.i.p = ensureEnum(CheckboxListIndexType_$type, v);
            this._a("indexType", enumToString(CheckboxListIndexType_$type, this.i.p));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "baseTheme", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.l;
        },
        set: function (v) {
            this.i.l = ensureEnum(BaseControlTheme_$type, v);
            this._a("baseTheme", enumToString(BaseControlTheme_$type, this.i.l));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "density", {
        /**
         * Gets or Sets the property name that contains the values.
        */
        get: function () {
            return this.i.n;
        },
        set: function (v) {
            this.i.n = ensureEnum(ControlDisplayDensity_$type, v);
            this._a("density", enumToString(ControlDisplayDensity_$type, this.i.n));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "selectAllCaption", {
        /**
         * Gets / sets the caption of the "Select All" checkbox.
        */
        get: function () {
            return this.i.bg;
        },
        set: function (v) {
            this.i.bg = v;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "selectAllCaptionTextColor", {
        /**
         * Gets or sets the color to use for the "Select All" label.
        */
        get: function () {
            return brushToString(this.i.cu);
        },
        set: function (v) {
            this.i.cu = stringToBrush(v);
            this._a("selectAllCaptionTextColor", brushToString(this.i.cu));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "actualSelectAllCaptionTextColor", {
        /**
         * Gets or sets the color to use for the actual header selectAllCaption text.
        */
        get: function () {
            return brushToString(this.i.cq);
        },
        set: function (v) {
            this.i.cq = stringToBrush(v);
            this._a("actualSelectAllCaptionTextColor", brushToString(this.i.cq));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "showSelectAll", {
        /**
         * Gets / sets whether the "Select all" checkbox is visible.
        */
        get: function () {
            return this.i.ao;
        },
        set: function (v) {
            this.i.ao = ensureBool(v);
            this._a("showSelectAll", this.i.ao);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "backgroundColor", {
        /**
         * Gets or sets the color to use for the background of the component.
        */
        get: function () {
            return brushToString(this.i.cr);
        },
        set: function (v) {
            this.i.cr = stringToBrush(v);
            this._a("backgroundColor", brushToString(this.i.cr));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "textColor", {
        /**
         * Gets or sets the color to use for the text of the component.
        */
        get: function () {
            return brushToString(this.i.cw);
        },
        set: function (v) {
            this.i.cw = stringToBrush(v);
            this._a("textColor", brushToString(this.i.cw));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "showFilter", {
        /**
         * Gets or sets whether the filter input is visible.
        */
        get: function () {
            return this.i.am;
        },
        set: function (v) {
            this.i.am = ensureBool(v);
            this._a("showFilter", this.i.am);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "isRowHoverEnabled", {
        /**
         * Gets or sets whether row hover highlighting is enabled.
        */
        get: function () {
            return this.i.aj;
        },
        set: function (v) {
            this.i.aj = ensureBool(v);
            this._a("isRowHoverEnabled", this.i.aj);
        },
        enumerable: true,
        configurable: true
    });
    IgcCheckboxListComponent.prototype.findByName = function (name) {
        if (this.keys != null && this.keys.findByName && this.keys.findByName(name)) {
            return this.keys.findByName(name);
        }
        return null;
    };
    Object.defineProperty(IgcCheckboxListComponent.prototype, "hasUserValues", {
        get: function () {
            return this._hasUserValues;
        },
        enumerable: true,
        configurable: true
    });
    IgcCheckboxListComponent.prototype.__m = function (propertyName) {
        if (!this._inStyling) {
            this._hasUserValues.add(propertyName);
        }
    };
    IgcCheckboxListComponent.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("CheckboxListComponent");
        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;
    };
    /**
 * selects all the items in the checkbox list.

*/
    IgcCheckboxListComponent.prototype.selectAll = function () {
        this.i.ch();
    };
    /**
     * Deselects all the items in the checkbox list.
    
    */
    IgcCheckboxListComponent.prototype.deselectAll = function () {
        this.i.bs();
    };
    IgcCheckboxListComponent.prototype.notifySetItem = function (index, oldItem, newItem) {
        this.i.bz(index, oldItem, newItem);
    };
    /**
     * Manually notifies the checkboxlist's grid that the data it has bound to has been cleared and needs to be re-examined.
     * This should not be called if the data that the grid is bound to is already observable.
    
    */
    IgcCheckboxListComponent.prototype.notifyClearItems = function () {
        this.i.bw();
    };
    IgcCheckboxListComponent.prototype.notifyInsertItem = function (index, newItem) {
        this.i.bx(index, newItem);
    };
    IgcCheckboxListComponent.prototype.notifyRemoveItem = function (index, oldItem) {
        this.i.by(index, oldItem);
    };
    IgcCheckboxListComponent.prototype.addKeyValue = function (value) {
        this.i.bp(value);
    };
    IgcCheckboxListComponent.prototype.removeKeyValue = function (value) {
        this.i.cg(value);
    };
    /**
     * Returns true if no items are selected / checked; otherwise false.
    
    */
    IgcCheckboxListComponent.prototype.isNothingSelected = function () {
        var iv = this.i.ah();
        return (iv);
    };
    /**
     * Returns true if all of the items are selected / checked; otherwise false.
    
    */
    IgcCheckboxListComponent.prototype.isEverythingSelected = function () {
        var iv = this.i.ag();
        return (iv);
    };
    Object.defineProperty(IgcCheckboxListComponent.prototype, "checkedChanged", {
        /**
         * Called when a checkbox is checked or unchecked.
        */
        get: function () {
            return this._checkedChanged;
        },
        set: function (ev) {
            var _this = this;
            if (this._checkedChanged_wrapped !== null) {
                this.i.checkedChanged = delegateRemove(this.i.checkedChanged, this._checkedChanged_wrapped);
                this._checkedChanged_wrapped = null;
                this._checkedChanged = null;
            }
            this._checkedChanged = ev;
            this._checkedChanged_wrapped = function (o, e) {
                var outerArgs = new IgcCheckedChangedEventArgs();
                outerArgs._provideImplementation(e);
                if (_this.beforeCheckedChanged) {
                    _this.beforeCheckedChanged(_this, outerArgs);
                }
                if (_this._checkedChanged) {
                    _this._checkedChanged(_this, outerArgs);
                }
            };
            this.i.checkedChanged = delegateCombine(this.i.checkedChanged, this._checkedChanged_wrapped);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgcCheckboxListComponent.prototype, "selectAllCheckboxChanged", {
        /**
         * Called when the SelectAll checkbox is checked or unchecked.
        */
        get: function () {
            return this._selectAllCheckboxChanged;
        },
        set: function (ev) {
            var _this = this;
            if (this._selectAllCheckboxChanged_wrapped !== null) {
                this.i.selectAllCheckboxChanged = delegateRemove(this.i.selectAllCheckboxChanged, this._selectAllCheckboxChanged_wrapped);
                this._selectAllCheckboxChanged_wrapped = null;
                this._selectAllCheckboxChanged = null;
            }
            this._selectAllCheckboxChanged = ev;
            this._selectAllCheckboxChanged_wrapped = function (o, e) {
                var outerArgs = new IgcSelectAllCheckboxChangedEventArgs();
                outerArgs._provideImplementation(e);
                if (_this.beforeSelectAllCheckboxChanged) {
                    _this.beforeSelectAllCheckboxChanged(_this, outerArgs);
                }
                if (_this._selectAllCheckboxChanged) {
                    _this._selectAllCheckboxChanged(_this, outerArgs);
                }
            };
            this.i.selectAllCheckboxChanged = delegateCombine(this.i.selectAllCheckboxChanged, this._selectAllCheckboxChanged_wrapped);
        },
        enumerable: true,
        configurable: true
    });
    IgcCheckboxListComponent._observedAttributesIgcCheckboxListComponent = null;
    IgcCheckboxListComponent.htmlTagName = "igc-checkbox-list";
    IgcCheckboxListComponent._isElementRegistered = false;
    return IgcCheckboxListComponent;
}(IgcHTMLElement));
export { IgcCheckboxListComponent };
//# sourceMappingURL=igc-checkbox-list-component.js.map
