/*
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 React from 'react';
import { IgrTemplateContent } from './igr-template-content';
let requiredStyle = `
    .ig-tooltip-container {
        padding: 5px; 
        padding: var(--tooltip-container-padding, 5px);
        background-color: white; 
        background-color: var(--tooltip-container-background-color, white);
        border-style: solid; 
        border-style: var(--tooltip-container-border-style, solid);
        border-width: 1px; 
        border-width: var(--tooltip-container-border-width, 1px);
        color: inherit; 
        color: var(--tooltip-container-text-color, inherit);
        pointer-events: none;
        white-space: nowrap;
        border-color: #666;
        border-color: var(--tooltip-container-border-color, #666);
    }
`;
let checked = new WeakMap();
function ensureCss() {
    if (!document) {
        return;
    }
    if (checked.has(document)) {
        return;
    }
    for (let i = document.head.children.length - 1; i >= 0; i--) {
        let child = document.head.children[i];
        if (child.tagName == "link" && child.hasAttribute("data-ig-tooltip-style")) {
            return;
        }
    }
    let 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);
}
export class IgrTooltipContainer extends React.Component {
    constructor(props) {
        super(props);
        this._template = null;
        this._containerTemplate = null;
        this._dataContext = null;
        ensureCss();
        if (props.owner) {
            this._currentOwner = props.owner;
        }
    }
    render() {
        if (!this._template || !this._dataContext || !this.dataContext.item) {
            return null;
        }
        let 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;
    }
    get currentOwner() {
        return this._currentOwner;
    }
    shouldComponentUpdate(nextProps, nextState) {
        if (nextProps.owner !== undefined) {
            this._currentOwner = nextProps.owner;
        }
        return true;
    }
    set template(value) {
        this._template = value;
        this.setState({ template: this._template });
    }
    get template() {
        return this._template;
    }
    set containerTemplate(value) {
        this._containerTemplate = value;
        this.setState({ containerTemplate: this._containerTemplate });
    }
    get containerTemplate() {
        return this._containerTemplate;
    }
    set dataContext(value) {
        if (this._dataContext == null && value == null) {
            return;
        }
        this._dataContext = value;
        this.setState({ dataContext: this._dataContext });
    }
    get dataContext() {
        return this._dataContext;
    }
}
