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";
export let IgcCheckboxListComponent = /*@__PURE__*/ (() => {
    class IgcCheckboxListComponent extends IgcHTMLElement {
        constructor() {
            super();
            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(() => {
                this._checkboxList.notifySizeChanged();
            });
        }
        set height(value) {
            this._height = value;
            this.style.height = value;
            this.i.notifySizeChanged();
        }
        get height() {
            return this._height;
        }
        set width(value) {
            this._width = value;
            this.style.width = value;
            this.i.notifySizeChanged();
        }
        get width() {
            return this._width;
        }
        set dataSource(value) {
            this._dataSource = value;
            if (this._checkboxList != null) {
                this._checkboxList.itemsSource = this._dataSource;
            }
        }
        get dataSource() {
            return this._dataSource;
        }
        // supports angular themes or custom properties set in CSS
        updateStyle() {
            this._styling(this, this);
        }
        destroy() {
            this._checkboxList.destroy();
        }
        createImplementation() {
            return new CheckboxList();
        }
        disconnectedCallback() {
            this._disconnected = true;
        }
        connectedCallback() {
            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();
        }
        afterContentInit() {
            this.i.notifySizeChanged();
        }
        /**
         * @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);
        }
        _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;
        }
        static get observedAttributes() {
            if (IgcCheckboxListComponent._observedAttributesIgcCheckboxListComponent == null) {
                let names = getAllPropertyNames(IgcCheckboxListComponent);
                for (let i = 0; i < names.length; i++) {
                    names[i] = toSpinal(names[i]);
                }
                IgcCheckboxListComponent._observedAttributesIgcCheckboxListComponent = names;
            }
            return IgcCheckboxListComponent._observedAttributesIgcCheckboxListComponent;
        }
        attributeChangedCallback(name, oldValue, newValue) {
            if (this._settingAttributes) {
                return;
            }
            let setName = fromSpinal(name);
            this._updatingFromAttribute = true;
            this[setName] = newValue;
            this._updatingFromAttribute = false;
        }
        static register() {
            if (!IgcCheckboxListComponent._isElementRegistered) {
                IgcCheckboxListComponent._isElementRegistered = true;
                RegisterElementHelper.registerElement(IgcCheckboxListComponent.htmlTagName, IgcCheckboxListComponent);
            }
        }
        /**
         * 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 keys() {
            if (this._keys === null) {
                let coll = new IgcGridSelectedKeysCollection();
                let innerColl = this.i.g;
                if (!innerColl) {
                    innerColl = new GridSelectedKeysCollection_internal();
                }
                this._keys = coll._fromInner(innerColl);
            }
            return this._keys;
        }
        set keys(v) {
            if (this._keys !== null) {
                this._keys._setSyncTarget(null);
                this._keys = null;
            }
            let coll = new IgcGridSelectedKeysCollection();
            this._keys = coll._fromOuter(v);
            let syncColl = new SyncableObservableCollection$1(PrimaryKeyValue.$type);
            let innerColl = this.i.g;
            if (!innerColl) {
                innerColl = new GridSelectedKeysCollection_internal();
            }
            syncColl._inner = innerColl;
            syncColl.clear();
            this._keys._setSyncTarget(syncColl);
        }
        /**
         * Gets or sets the primary key to use for the CheckboxList.
        */
        get primaryKey() {
            return this.i.b;
        }
        set primaryKey(v) {
            this.i.b = v;
        }
        /**
         * Gets or Sets the property name that contains the values.
        */
        get dataMemberPath() {
            return this.i.a2;
        }
        set dataMemberPath(v) {
            this.i.a2 = v;
        }
        /**
         * Gets or Sets the property name that contains the values.
        */
        get selectedMemberPath() {
            return this.i.bj;
        }
        set selectedMemberPath(v) {
            this.i.bj = v;
        }
        /**
         * Gets or Sets the property name that contains the values.
        */
        get filterPlaceholderText() {
            return this.i.a6;
        }
        set filterPlaceholderText(v) {
            this.i.a6 = v;
        }
        /**
         * Gets or Sets the property name that contains the values.
        */
        get searchInputType() {
            return this.i.x;
        }
        set searchInputType(v) {
            this.i.x = ensureEnum(InputGroupDisplayType_$type, v);
            this._a("searchInputType", enumToString(InputGroupDisplayType_$type, this.i.x));
        }
        /**
         * Gets or Sets the property name that contains the values.
        */
        get rowHeight() {
            return this.i.as;
        }
        set rowHeight(v) {
            this.i.as = +v;
            this._a("rowHeight", this.i.as);
        }
        get actualRowHeight() {
            return this.i.aq;
        }
        /**
         * Gets or Sets the property name that contains the values.
        */
        get cellTextStyle() {
            if (this.i.ab == null) {
                return null;
            }
            return this.i.ab.fontString;
        }
        set cellTextStyle(v) {
            let fi = new FontInfo();
            fi.fontString = v;
            this.i.ab = fi;
            this._a("cellTextStyle", this.i.ab != null ? this.i.ab.fontString : "");
        }
        /**
         * Gets or Sets the property name that contains the values.
        */
        get indexType() {
            return this.i.p;
        }
        set indexType(v) {
            this.i.p = ensureEnum(CheckboxListIndexType_$type, v);
            this._a("indexType", enumToString(CheckboxListIndexType_$type, this.i.p));
        }
        /**
         * Gets or Sets the property name that contains the values.
        */
        get baseTheme() {
            return this.i.l;
        }
        set baseTheme(v) {
            this.i.l = ensureEnum(BaseControlTheme_$type, v);
            this._a("baseTheme", enumToString(BaseControlTheme_$type, this.i.l));
        }
        /**
         * Gets or Sets the property name that contains the values.
        */
        get density() {
            return this.i.n;
        }
        set density(v) {
            this.i.n = ensureEnum(ControlDisplayDensity_$type, v);
            this._a("density", enumToString(ControlDisplayDensity_$type, this.i.n));
        }
        /**
         * Gets / sets the caption of the "Select All" checkbox.
        */
        get selectAllCaption() {
            return this.i.bg;
        }
        set selectAllCaption(v) {
            this.i.bg = v;
        }
        /**
         * Gets or sets the color to use for the "Select All" label.
        */
        get selectAllCaptionTextColor() {
            return brushToString(this.i.cu);
        }
        set selectAllCaptionTextColor(v) {
            this.i.cu = stringToBrush(v);
            this._a("selectAllCaptionTextColor", brushToString(this.i.cu));
        }
        /**
         * Gets or sets the color to use for the actual header selectAllCaption text.
        */
        get actualSelectAllCaptionTextColor() {
            return brushToString(this.i.cq);
        }
        set actualSelectAllCaptionTextColor(v) {
            this.i.cq = stringToBrush(v);
            this._a("actualSelectAllCaptionTextColor", brushToString(this.i.cq));
        }
        /**
         * Gets / sets whether the "Select all" checkbox is visible.
        */
        get showSelectAll() {
            return this.i.ao;
        }
        set showSelectAll(v) {
            this.i.ao = ensureBool(v);
            this._a("showSelectAll", this.i.ao);
        }
        /**
         * Gets or sets the color to use for the background of the component.
        */
        get backgroundColor() {
            return brushToString(this.i.cr);
        }
        set backgroundColor(v) {
            this.i.cr = stringToBrush(v);
            this._a("backgroundColor", brushToString(this.i.cr));
        }
        /**
         * Gets or sets the color to use for the text of the component.
        */
        get textColor() {
            return brushToString(this.i.cw);
        }
        set textColor(v) {
            this.i.cw = stringToBrush(v);
            this._a("textColor", brushToString(this.i.cw));
        }
        /**
         * Gets or sets whether the filter input is visible.
        */
        get showFilter() {
            return this.i.am;
        }
        set showFilter(v) {
            this.i.am = ensureBool(v);
            this._a("showFilter", this.i.am);
        }
        /**
         * Gets or sets whether row hover highlighting is enabled.
        */
        get isRowHoverEnabled() {
            return this.i.aj;
        }
        set isRowHoverEnabled(v) {
            this.i.aj = ensureBool(v);
            this._a("isRowHoverEnabled", this.i.aj);
        }
        findByName(name) {
            if (this.keys != null && this.keys.findByName && this.keys.findByName(name)) {
                return this.keys.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("CheckboxListComponent");
            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;
        }
        /**
     * selects all the items in the checkbox list.
    
    */
        selectAll() {
            this.i.ch();
        }
        /**
         * Deselects all the items in the checkbox list.
        
        */
        deselectAll() {
            this.i.bs();
        }
        notifySetItem(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.
        
        */
        notifyClearItems() {
            this.i.bw();
        }
        notifyInsertItem(index, newItem) {
            this.i.bx(index, newItem);
        }
        notifyRemoveItem(index, oldItem) {
            this.i.by(index, oldItem);
        }
        addKeyValue(value) {
            this.i.bp(value);
        }
        removeKeyValue(value) {
            this.i.cg(value);
        }
        /**
         * Returns true if no items are selected / checked; otherwise false.
        
        */
        isNothingSelected() {
            let iv = this.i.ah();
            return (iv);
        }
        /**
         * Returns true if all of the items are selected / checked; otherwise false.
        
        */
        isEverythingSelected() {
            let iv = this.i.ag();
            return (iv);
        }
        /**
         * Called when a checkbox is checked or unchecked.
        */
        get checkedChanged() {
            return this._checkedChanged;
        }
        set checkedChanged(ev) {
            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 = (o, e) => {
                let 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);
        }
        /**
         * Called when the SelectAll checkbox is checked or unchecked.
        */
        get selectAllCheckboxChanged() {
            return this._selectAllCheckboxChanged;
        }
        set selectAllCheckboxChanged(ev) {
            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 = (o, e) => {
                let 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);
        }
    }
    IgcCheckboxListComponent._observedAttributesIgcCheckboxListComponent = null;
    IgcCheckboxListComponent.htmlTagName = "igc-checkbox-list";
    IgcCheckboxListComponent._isElementRegistered = false;
    return IgcCheckboxListComponent;
})();
//# sourceMappingURL=igc-checkbox-list-component.js.map
