import { __extends } from "tslib";
import { Component } from 'react';
import { findDOMNode } from 'react-dom';
import Context from './Context';
var PopoverAnchor = (function (_super) {
    __extends(PopoverAnchor, _super);
    function PopoverAnchor() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    PopoverAnchor.prototype.getElement = function () {
        var getElement = this.props.getElement;
        var node = findDOMNode(this);
        return getElement ? getElement(node) : node;
    };
    PopoverAnchor.prototype.componentDidMount = function () {
        var _this = this;
        this.context.popover.getAnchor = function () { return _this.getElement(); };
    };
    PopoverAnchor.prototype.componentWillUnmount = function () {
        this.context.popover.getAnchor = null;
    };
    PopoverAnchor.prototype.render = function () {
        if (process.env.NODE_ENV !== 'production') {
            if (!this.props.children) {
                throw new Error('Popover Anchor requires a child');
            }
        }
        return this.props.children;
    };
    PopoverAnchor.contextType = Context;
    return PopoverAnchor;
}(Component));
export { PopoverAnchor };
export default PopoverAnchor;
