import { delegateCombine, delegateRemove } from "igniteui-webcomponents-core";
import { CellContentHorizontalAlignment_$type } from "./CellContentHorizontalAlignment";
import { CellContentVerticalAlignment_$type } from "./CellContentVerticalAlignment";
import { TextCellLineBreakMode_$type } from "./TextCellLineBreakMode";
import { IgcDataBindingEventArgs } from "./igc-data-binding-event-args";
import { IgcCellStyleRequestedEventArgs } from "./igc-cell-style-requested-event-args";
import { TypeRegistrar } from "igniteui-webcomponents-core";
import { NamePatcher, getAllPropertyNames, fromSpinal, toSpinal, brushToString, stringToBrush, ensureEnum, enumToString, initializePropertiesFromCss } from "igniteui-webcomponents-core";
import { FontInfo } from "igniteui-webcomponents-core";
import { ColumnPropertyUpdatingAnimationMode } from "./ColumnPropertyUpdatingAnimationMode";
import { IgcHTMLElement } from "igniteui-webcomponents-core";
/**
 * Base class for various definition types for the grid.
*/
export let IgcDefinitionBaseComponent = /*@__PURE__*/ (() => {
    class IgcDefinitionBaseComponent extends IgcHTMLElement {
        constructor() {
            super();
            this._renderer = null;
            this.__p = null;
            this._hasUserValues = new Set();
            this._stylingContainer = null;
            this._stylingParent = null;
            this._inStyling = false;
            this._settingAttributes = false;
            this._attached = false;
            this._queuedSetAttributes = [];
            this._updatingFromAttribute = false;
            this._dataBinding = null;
            this._dataBinding_wrapped = null;
            this._dataBound = null;
            this._dataBound_wrapped = null;
            this._cellStyleKeyRequested = null;
            this._cellStyleKeyRequested_wrapped = null;
            if (this._styling) {
                NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this));
            }
            this._implementation = this.createImplementation();
            this._implementation.externalObject = this;
            this.onImplementationCreated();
        }
        createImplementation() {
            return null;
        }
        /**
         * @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() {
        }
        _provideRenderer(renderer) {
            this._renderer = renderer;
        }
        get hasUserValues() {
            return this._hasUserValues;
        }
        __m(propertyName) {
            if (!this._inStyling) {
                this._hasUserValues.add(propertyName);
            }
        }
        _styling(container, component, parent) {
            this._stylingContainer = container;
            this._stylingParent = component;
            if (this._inStyling) {
                return;
            }
            this._inStyling = true;
            let grid = component._grid;
            var prev;
            if (grid) {
                prev = grid.columnPropertyUpdatingAnimationMode;
                grid.columnPropertyUpdatingAnimationMode = ColumnPropertyUpdatingAnimationMode.None;
            }
            let genericPrefix = "";
            let typeName = this.i.$type.name;
            let lowerTypeName = typeName.toLowerCase();
            if (lowerTypeName.indexOf("column") >= 0) {
                genericPrefix = "column";
            }
            else if (lowerTypeName.indexOf("sectionheader") >= 0) {
                genericPrefix = "section-header";
            }
            else if (lowerTypeName.indexOf("sectionfooter") >= 0) {
                genericPrefix = "section-footer";
            }
            else if (lowerTypeName.indexOf("rowseparator") >= 0) {
                genericPrefix = "row-separator";
            }
            else if (lowerTypeName.indexOf("summaryrowroot") >= 0) {
                genericPrefix = "summary-row-root";
            }
            else if (lowerTypeName.indexOf("summaryrowsection") >= 0) {
                genericPrefix = "summary-row-section";
            }
            else if (lowerTypeName.indexOf("headerseparator") >= 0) {
                genericPrefix = "header-separator";
            }
            else {
                genericPrefix = "header";
            }
            let additionalPrefixes = [];
            let prefix = toSpinal(typeName);
            additionalPrefixes.push(prefix + "-");
            if (parent) {
                let parentTypeName = parent.i.$type.name;
                if (parentTypeName == "Grid") {
                    parentTypeName = "DataGrid";
                }
                let parentPrefix = toSpinal(parentTypeName);
                additionalPrefixes.push(parentPrefix + "-" + genericPrefix + "-");
                additionalPrefixes.push(parentPrefix + "-" + prefix + "-");
            }
            initializePropertiesFromCss(container, this, genericPrefix + "-", this.hasUserValues, false, additionalPrefixes);
            if (grid) {
                grid.columnPropertyUpdatingAnimationMode = prev;
            }
            this._inStyling = false;
        }
        _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 (IgcDefinitionBaseComponent._observedAttributesIgcDefinitionBaseComponent == null) {
                let names = getAllPropertyNames(IgcDefinitionBaseComponent);
                for (let i = 0; i < names.length; i++) {
                    names[i] = toSpinal(names[i]);
                }
                IgcDefinitionBaseComponent._observedAttributesIgcDefinitionBaseComponent = names;
            }
            return IgcDefinitionBaseComponent._observedAttributesIgcDefinitionBaseComponent;
        }
        attributeChangedCallback(name, oldValue, newValue) {
            if (this._settingAttributes) {
                return;
            }
            let setName = fromSpinal(name);
            this._updatingFromAttribute = true;
            this[setName] = newValue;
            this._updatingFromAttribute = false;
        }
        /**
     * Gets or sets the background color to use.
    */
        get background() {
            return brushToString(this.i.d7);
        }
        set background(v) {
            this.i.d7 = stringToBrush(v);
            this._a("background", brushToString(this.i.d7));
        }
        /**
         * Gets or sets the background color to use.
        */
        get border() {
            return brushToString(this.i.d8);
        }
        set border(v) {
            this.i.d8 = stringToBrush(v);
            this._a("border", brushToString(this.i.d8));
        }
        /**
         * Gets or sets the background color to use.
        */
        get activationBorder() {
            return brushToString(this.i.dy);
        }
        set activationBorder(v) {
            this.i.dy = stringToBrush(v);
            this._a("activationBorder", brushToString(this.i.dy));
        }
        /**
         * Gets or sets the error border color to use.
        */
        get errorBorder() {
            return brushToString(this.i.d9);
        }
        set errorBorder(v) {
            this.i.d9 = stringToBrush(v);
            this._a("errorBorder", brushToString(this.i.d9));
        }
        /**
         * Gets the actual border color that will be used.
        */
        get actualBorder() {
            return brushToString(this.i.d1);
        }
        set actualBorder(v) {
            this.i.d1 = stringToBrush(v);
            this._a("actualBorder", brushToString(this.i.d1));
        }
        /**
         * Gets or sets the amount of left border to use for the cell content for this column.
        */
        get borderLeftWidth() {
            return this.i.be;
        }
        set borderLeftWidth(v) {
            this.i.be = +v;
            this._a("borderLeftWidth", this.i.be);
        }
        /**
         * Gets or sets the amount of top border to use for the cell content for this column.
        */
        get borderTopWidth() {
            return this.i.bg;
        }
        set borderTopWidth(v) {
            this.i.bg = +v;
            this._a("borderTopWidth", this.i.bg);
        }
        /**
         * Gets or sets the amount of right border to use for the cell content of this column.
        */
        get borderRightWidth() {
            return this.i.bf;
        }
        set borderRightWidth(v) {
            this.i.bf = +v;
            this._a("borderRightWidth", this.i.bf);
        }
        /**
         * Gets or sets the amount of bottom border to use for the cell content of this column.
        */
        get borderBottomWidth() {
            return this.i.bd;
        }
        set borderBottomWidth(v) {
            this.i.bd = +v;
            this._a("borderBottomWidth", this.i.bd);
        }
        /**
         * Gets or sets the amount of left activation border to use for the cell content for this column.
        */
        get activationBorderLeftWidth() {
            return this.i.ba;
        }
        set activationBorderLeftWidth(v) {
            this.i.ba = +v;
            this._a("activationBorderLeftWidth", this.i.ba);
        }
        /**
         * Gets or sets the amount of top activation border to use for the cell content for this column.
        */
        get activationBorderTopWidth() {
            return this.i.bc;
        }
        set activationBorderTopWidth(v) {
            this.i.bc = +v;
            this._a("activationBorderTopWidth", this.i.bc);
        }
        /**
         * Gets or sets the amount of right activation border to use for the cell content of this column.
        */
        get activationBorderRightWidth() {
            return this.i.bb;
        }
        set activationBorderRightWidth(v) {
            this.i.bb = +v;
            this._a("activationBorderRightWidth", this.i.bb);
        }
        /**
         * Gets or sets the amount of bottom activation border to use for the cell content of this column.
        */
        get activationBorderBottomWidth() {
            return this.i.a9;
        }
        set activationBorderBottomWidth(v) {
            this.i.a9 = +v;
            this._a("activationBorderBottomWidth", this.i.a9);
        }
        get errorBorderLeftWidth() {
            return this.i.bi;
        }
        set errorBorderLeftWidth(v) {
            this.i.bi = +v;
            this._a("errorBorderLeftWidth", this.i.bi);
        }
        get errorBorderTopWidth() {
            return this.i.bk;
        }
        set errorBorderTopWidth(v) {
            this.i.bk = +v;
            this._a("errorBorderTopWidth", this.i.bk);
        }
        get errorBorderRightWidth() {
            return this.i.bj;
        }
        set errorBorderRightWidth(v) {
            this.i.bj = +v;
            this._a("errorBorderRightWidth", this.i.bj);
        }
        get errorBorderBottomWidth() {
            return this.i.bh;
        }
        set errorBorderBottomWidth(v) {
            this.i.bh = +v;
            this._a("errorBorderBottomWidth", this.i.bh);
        }
        /**
         * Gets the actual background color that will be used.
        */
        get actualBackground() {
            return brushToString(this.i.d0);
        }
        set actualBackground(v) {
            this.i.d0 = stringToBrush(v);
            this._a("actualBackground", brushToString(this.i.d0));
        }
        /**
         * Gets the actual background color that will be used.
        */
        get actualActivationBorder() {
            return brushToString(this.i.dz);
        }
        set actualActivationBorder(v) {
            this.i.dz = stringToBrush(v);
            this._a("actualActivationBorder", brushToString(this.i.dz));
        }
        /**
         * Gets the actual error border color that will be used.
        */
        get actualErrorBorder() {
            return brushToString(this.i.d2);
        }
        set actualErrorBorder(v) {
            this.i.d2 = stringToBrush(v);
            this._a("actualErrorBorder", brushToString(this.i.d2));
        }
        /**
         * Gets or sets the background color for content that sticks to the top of the grid.
        */
        get stickyRowBackground() {
            return brushToString(this.i.ej);
        }
        set stickyRowBackground(v) {
            this.i.ej = stringToBrush(v);
            this._a("stickyRowBackground", brushToString(this.i.ej));
        }
        /**
         * Gets the actual background color for content that sticks to the top of the grid.
        */
        get actualStickyRowBackground() {
            return brushToString(this.i.d5);
        }
        set actualStickyRowBackground(v) {
            this.i.d5 = stringToBrush(v);
            this._a("actualStickyRowBackground", brushToString(this.i.d5));
        }
        /**
         * Gets or sets the background color for cells belonging to rows marked as pinned.
        */
        get pinnedRowBackground() {
            return brushToString(this.i.ei);
        }
        set pinnedRowBackground(v) {
            this.i.ei = stringToBrush(v);
            this._a("pinnedRowBackground", brushToString(this.i.ei));
        }
        /**
         * Gets the actual background color for cells belonging to rows marked as pinned.
        */
        get actualPinnedRowBackground() {
            return brushToString(this.i.d4);
        }
        set actualPinnedRowBackground(v) {
            this.i.d4 = stringToBrush(v);
            this._a("actualPinnedRowBackground", brushToString(this.i.d4));
        }
        /**
         * Gets or sets the color for the last row in the sticky row area.
        */
        get lastStickyRowBackground() {
            return brushToString(this.i.eh);
        }
        set lastStickyRowBackground(v) {
            this.i.eh = stringToBrush(v);
            this._a("lastStickyRowBackground", brushToString(this.i.eh));
        }
        /**
         * Gets the actual color for the last row in the sticky row area.
        */
        get actualLastStickyRowBackground() {
            return brushToString(this.i.d3);
        }
        set actualLastStickyRowBackground(v) {
            this.i.d3 = stringToBrush(v);
            this._a("actualLastStickyRowBackground", brushToString(this.i.d3));
        }
        /**
         * Gets or sets the opacity of the content.
        */
        get contentOpacity() {
            return this.i.au;
        }
        set contentOpacity(v) {
            this.i.au = +v;
            this._a("contentOpacity", this.i.au);
        }
        /**
         * Gets or sets the horizontal alignment to use for the cell content.
        */
        get horizontalAlignment() {
            return this.i.e;
        }
        set horizontalAlignment(v) {
            this.i.e = ensureEnum(CellContentHorizontalAlignment_$type, v);
            this._a("horizontalAlignment", enumToString(CellContentHorizontalAlignment_$type, this.i.e));
        }
        /**
         * Gets or sets the vertical alignment to use for the cell content.
        */
        get verticalAlignment() {
            return this.i.j;
        }
        set verticalAlignment(v) {
            this.i.j = ensureEnum(CellContentVerticalAlignment_$type, v);
            this._a("verticalAlignment", enumToString(CellContentVerticalAlignment_$type, this.i.j));
        }
        /**
         * Gets or sets the line breaking mode to use if text is present in the cell.
        */
        get lineBreakMode() {
            return this.i.y;
        }
        set lineBreakMode(v) {
            this.i.y = ensureEnum(TextCellLineBreakMode_$type, v);
            this._a("lineBreakMode", enumToString(TextCellLineBreakMode_$type, this.i.y));
        }
        /**
         * Gets the actual line break mode which will be used if text is present in the cell.
        */
        get actualLineBreakMode() {
            return this.i.x;
        }
        set actualLineBreakMode(v) {
            this.i.x = ensureEnum(TextCellLineBreakMode_$type, v);
            this._a("actualLineBreakMode", enumToString(TextCellLineBreakMode_$type, this.i.x));
        }
        /**
         * Gets or sets the color to use for displaying text.
        */
        get textColor() {
            return brushToString(this.i.ek);
        }
        set textColor(v) {
            this.i.ek = stringToBrush(v);
            this._a("textColor", brushToString(this.i.ek));
        }
        /**
         * Gets the actual color used for displaying text.
        */
        get actualTextColor() {
            return brushToString(this.i.d6);
        }
        set actualTextColor(v) {
            this.i.d6 = stringToBrush(v);
            this._a("actualTextColor", brushToString(this.i.d6));
        }
        /**
         * Gets or sets the color to use for displaying text.
        */
        get pinnedRowOpacity() {
            return this.i.aw;
        }
        set pinnedRowOpacity(v) {
            this.i.aw = +v;
            this._a("pinnedRowOpacity", this.i.aw);
        }
        /**
         * Gets or sets the color to use for displaying text.
        */
        get actualPinnedRowOpacity() {
            return this.i.at;
        }
        set actualPinnedRowOpacity(v) {
            this.i.at = +v;
            this._a("actualPinnedRowOpacity", this.i.at);
        }
        get textStyle() {
            if (this.i.textStyle == null) {
                return null;
            }
            return this.i.textStyle.fontString;
        }
        set textStyle(v) {
            let fi = new FontInfo();
            fi.fontString = v;
            this.i.textStyle = fi;
            this._a("textStyle", this.i.textStyle != null ? this.i.textStyle.fontString : "");
        }
        findByName(name) {
            return null;
        }
        setNamedValue(valueName, animationType, value) {
            this.i.c6(valueName, (animationType == null ? null : animationType), value);
        }
        /**
         * Returns if this definition has named value.
        
        */
        hasNamedValues() {
            let iv = this.i.ai();
            return (iv);
        }
        /**
         * Returns if this definition has a named value with a given name.
        
        * @param valueName  * The named value name to check for.
        */
        hasNamedValue(valueName) {
            let iv = this.i.ah(valueName);
            return (iv);
        }
        /**
         * Removes the named value from this definition by name.
        
        * @param valueName  * The named value name to remove.
        */
        removeNamedValue(valueName) {
            this.i.c4(valueName);
        }
        /**
         * Gets the value for a named value from this definition.
        
        * @param valueName  * The named value name to check for.
        */
        getNamedValue(valueName) {
            let iv = this.i.bn(valueName);
            return (iv);
        }
        /**
         * Called when a cell is data binding.
        */
        get dataBinding() {
            return this._dataBinding;
        }
        set dataBinding(ev) {
            if (this._dataBinding_wrapped !== null) {
                this.i.dataBinding = delegateRemove(this.i.dataBinding, this._dataBinding_wrapped);
                this._dataBinding_wrapped = null;
                this._dataBinding = null;
            }
            this._dataBinding = ev;
            this._dataBinding_wrapped = (o, e) => {
                let outerArgs = new IgcDataBindingEventArgs();
                outerArgs._provideImplementation(e);
                if (this.beforeDataBinding) {
                    this.beforeDataBinding(this, outerArgs);
                }
                if (this._dataBinding) {
                    this._dataBinding(this, outerArgs);
                }
            };
            this.i.dataBinding = delegateCombine(this.i.dataBinding, this._dataBinding_wrapped);
        }
        /**
         * Called when a cell has been data bound.
        */
        get dataBound() {
            return this._dataBound;
        }
        set dataBound(ev) {
            if (this._dataBound_wrapped !== null) {
                this.i.dataBound = delegateRemove(this.i.dataBound, this._dataBound_wrapped);
                this._dataBound_wrapped = null;
                this._dataBound = null;
            }
            this._dataBound = ev;
            this._dataBound_wrapped = (o, e) => {
                let outerArgs = new IgcDataBindingEventArgs();
                outerArgs._provideImplementation(e);
                if (this.beforeDataBound) {
                    this.beforeDataBound(this, outerArgs);
                }
                if (this._dataBound) {
                    this._dataBound(this, outerArgs);
                }
            };
            this.i.dataBound = delegateCombine(this.i.dataBound, this._dataBound_wrapped);
        }
        /**
         * Called when the style key for a cell is needed. Used for recycling the cell.
        */
        get cellStyleKeyRequested() {
            return this._cellStyleKeyRequested;
        }
        set cellStyleKeyRequested(ev) {
            if (this._cellStyleKeyRequested_wrapped !== null) {
                this.i.cellStyleKeyRequested = delegateRemove(this.i.cellStyleKeyRequested, this._cellStyleKeyRequested_wrapped);
                this._cellStyleKeyRequested_wrapped = null;
                this._cellStyleKeyRequested = null;
            }
            this._cellStyleKeyRequested = ev;
            this._cellStyleKeyRequested_wrapped = (o, e) => {
                let outerArgs = new IgcCellStyleRequestedEventArgs();
                outerArgs._provideImplementation(e);
                if (this.beforeCellStyleKeyRequested) {
                    this.beforeCellStyleKeyRequested(this, outerArgs);
                }
                if (this._cellStyleKeyRequested) {
                    this._cellStyleKeyRequested(this, outerArgs);
                }
            };
            this.i.cellStyleKeyRequested = delegateCombine(this.i.cellStyleKeyRequested, this._cellStyleKeyRequested_wrapped);
        }
    }
    IgcDefinitionBaseComponent._observedAttributesIgcDefinitionBaseComponent = null;
    return IgcDefinitionBaseComponent;
})();
//# sourceMappingURL=igc-definition-base-component.js.map
