/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import * as tslib_1 from "tslib";
import * as React from 'react';
import { IgrTemplateContent } from './igr-template-content';
var requiredStyle = "\n    .ig-tooltip-container {\n        padding: 5px; \n        padding: var(--tooltip-container-padding, 5px);\n        background-color: white; \n        background-color: var(--tooltip-container-background-color, white);\n        border-style: solid; \n        border-style: var(--tooltip-container-border-style, solid);\n        border-width: 1px; \n        border-width: var(--tooltip-container-border-width, 1px);\n        color: inherit; \n        color: var(--tooltip-container-text-color, inherit);\n        pointer-events: none;\n        white-space: nowrap;\n        border-color: #666;\n        border-color: var(--tooltip-container-border-color, #666);\n    }\n";
var checked = new WeakMap();
function ensureCss() {
    if (!document) {
        return;
    }
    if (checked.has(document)) {
        return;
    }
    for (var i = document.head.children.length - 1; i >= 0; i--) {
        var child = document.head.children[i];
        if (child.tagName == "link" && child.hasAttribute("data-ig-tooltip-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(requiredStyle));
    link.setAttribute('data-ig-tooltip-style', 'true');
    document.head.appendChild(link);
    checked.set(document, true);
}
var IgrTooltipContainer = /** @class */ (function (_super) {
    tslib_1.__extends(IgrTooltipContainer, _super);
    function IgrTooltipContainer(props) {
        var _this = _super.call(this, props) || this;
        _this._template = null;
        _this._containerTemplate = null;
        _this._dataContext = null;
        ensureCss();
        if (props.owner) {
            _this._currentOwner = props.owner;
        }
        return _this;
    }
    IgrTooltipContainer.prototype.render = function () {
        if (!this._template || !this._dataContext || !this.dataContext.item) {
            return null;
        }
        var ele = React.createElement(IgrTemplateContent, { dataContext: this._dataContext, template: this._template });
        if (this._containerTemplate !== null) {
        }
        else {
            return (React.createElement("div", { className: 'ig-tooltip-container igr-tooltip-container ig-tooltip-container-background', style: {} }, ele));
        }
        return ele;
    };
    Object.defineProperty(IgrTooltipContainer.prototype, "currentOwner", {
        get: function () {
            return this._currentOwner;
        },
        enumerable: true,
        configurable: true
    });
    IgrTooltipContainer.prototype.shouldComponentUpdate = function (nextProps, nextState) {
        if (nextProps.owner !== undefined) {
            this._currentOwner = nextProps.owner;
        }
        return true;
    };
    Object.defineProperty(IgrTooltipContainer.prototype, "template", {
        get: function () {
            return this._template;
        },
        set: function (value) {
            this._template = value;
            this.setState({ template: this._template });
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgrTooltipContainer.prototype, "containerTemplate", {
        get: function () {
            return this._containerTemplate;
        },
        set: function (value) {
            this._containerTemplate = value;
            this.setState({ containerTemplate: this._containerTemplate });
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgrTooltipContainer.prototype, "dataContext", {
        get: function () {
            return this._dataContext;
        },
        set: function (value) {
            if (this._dataContext == null && value == null) {
                return;
            }
            this._dataContext = value;
            this.setState({ dataContext: this._dataContext });
        },
        enumerable: true,
        configurable: true
    });
    return IgrTooltipContainer;
}(React.Component));
export { IgrTooltipContainer };
