import * as tslib_1 from "tslib";
import * as React from 'react';
import { isValidProp, getModifiedProps, toSpinal, initializePropertiesFromCss, NamePatcher } from "igniteui-react-core";
export var LegendBaseStyles = ["\n:host {\n    display: block;\n}\n.ig-legend {\n    border: none;\n    border: var(--legend-border, none);\n    overflow: auto;\n    overflow: var(--legend-item-overflow, auto);\n}\n.ig-chart-legend-item-text {\n    font: 12px Verdana, Arial, sans-serif;\n    font: var(--legend-item-font, 12px Verdana, Arial, sans-serif);\n    vertical-align: middle;\n    vertical-align: var(--legend-item-vertical-align, middle);\n}\n.ig-chart-legend-items-list\n{\n    padding: 5px;\n    padding: var(--legend-item-padding, 5px);\n    margin: 0px;\n    margin: var(--legend-item-margin, 0px);\n    background-color: transparent;\n    background-color: var(--legend-list-background-color, transparent);\n}\n.ig-chart-legend-item-badge, .ui-chart-legend-item-badge canvas\n{\n    vertical-align: middle;\n    vertical-align: var(--legend-item-badge-vertical-align, middle);\n}\n.ig-chart-legend-item\n{\n    background-color: transparent;\n    background-color: var(--legend-item-background-color, transparent);\n}\n"];
/**
 * Represents the base class for a legend in IgxDataChartComponent.
*/
var IgrLegendBase = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(IgrLegendBase, _super);
    function IgrLegendBase(props) {
        var _this = _super.call(this, props) || this;
        _this._zoneRunner = null;
        _this.__p = null;
        _this._hasUserValues = new Set();
        _this._stylingContainer = null;
        _this._stylingParent = null;
        _this._inStyling = false;
        IgrLegendBase.ensureCss();
        if (_this._styling) {
            NamePatcher.ensureStylablePatched(Object.getPrototypeOf(_this));
        }
        _this._implementation = _this.createImplementation();
        _this._implementation.externalObject = _this;
        _this.onImplementationCreated();
        if (document) {
            //introduce styles globally for now.
        }
        return _this;
    }
    Object.defineProperty(IgrLegendBase.prototype, "i", {
        get: function () {
            return this._implementation;
        },
        enumerable: true,
        configurable: true
    });
    IgrLegendBase.prototype.onImplementationCreated = function () {
    };
    IgrLegendBase.ensureCss = function () {
        if (!document) {
            return;
        }
        if (IgrLegendBase._checked.has(document)) {
            return;
        }
        for (var i = 0; i < document.head.children.length; i++) {
            var child = document.head.children[i];
            if (child.tagName == "link" && child.hasAttribute("data-ig-legend-style")) {
                return;
            }
        }
        var link = document.createElement("link");
        link.setAttribute('rel', 'stylesheet');
        link.setAttribute('type', 'text/css');
        link.setAttribute('href', 'data:text/css;charset=UTF-8,' + encodeURIComponent(LegendBaseStyles[0]));
        link.setAttribute('data-ig-legend-style', 'true');
        document.head.appendChild(link);
        IgrLegendBase._checked.set(document, true);
    };
    IgrLegendBase.prototype.componentDidMount = function () {
        var e_1, _a;
        try {
            for (var _b = tslib_1.__values(Object.keys(this.props)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var p = _c.value;
                if (isValidProp(this, p)) {
                    {
                        this[p] = this.props[p];
                    }
                }
            }
        }
        catch (e_1_1) {
            e_1 = { error: e_1_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_1)
                    throw e_1.error;
            }
        }
    };
    IgrLegendBase.prototype.shouldComponentUpdate = function (nextProps, nextState) {
        var e_2, _a;
        var mod = getModifiedProps(this.props, nextProps);
        try {
            for (var _b = tslib_1.__values(Object.keys(mod)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var p = _c.value;
                if (isValidProp(this, p)) {
                    this[p] = mod[p];
                }
            }
        }
        catch (e_2_1) {
            e_2 = { error: e_2_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_2)
                    throw e_2.error;
            }
        }
        return true;
    };
    IgrLegendBase.prototype.render = function () {
        return null;
    };
    Object.defineProperty(IgrLegendBase.prototype, "isItemwise", {
        /**
     * Gets if the legend is item-wise.
    */
        get: function () {
            return this.i.isItemwise;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgrLegendBase.prototype, "isFinancial", {
        /**
         * Gets if the legend is a financial legend.
        */
        get: function () {
            return this.i.isFinancial;
        },
        enumerable: true,
        configurable: true
    });
    IgrLegendBase.prototype.findByName = function (name) {
        return null;
    };
    Object.defineProperty(IgrLegendBase.prototype, "hasUserValues", {
        get: function () {
            return this._hasUserValues;
        },
        enumerable: true,
        configurable: true
    });
    IgrLegendBase.prototype.__m = function (propertyName) {
        if (!this._inStyling) {
            this._hasUserValues.add(propertyName);
        }
    };
    IgrLegendBase.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("LegendBase");
        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;
    };
    /**
 * Returns the legend visuals expressed as a serialized string.

*/
    IgrLegendBase.prototype.exportSerializedVisualData = function () {
        var iv = this.i.exportSerializedVisualData();
        return (iv);
    };
    IgrLegendBase._checked = new WeakMap();
    return IgrLegendBase;
}(React.Component));
export { IgrLegendBase };
//# sourceMappingURL=igr-legend-base.js.map
