(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react", "react-dom", "../helpers/getPosition/helpers", "./components/TooltipContent", "./styles"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var react_1 = (0, tslib_1.__importStar)(require("react"));
    var react_dom_1 = require("react-dom");
    var helpers_1 = require("../helpers/getPosition/helpers");
    var TooltipContent_1 = (0, tslib_1.__importDefault)(require("./components/TooltipContent"));
    var styles_1 = require("./styles");
    var Tooltip = function (_a) {
        var children = _a.children, _b = _a.direction, direction = _b === void 0 ? "top" : _b, text = _a.text, onVisibleChange = _a.onVisibleChange, isTrail = _a.isTrail, trailText = _a.trailText, isShadow = _a.isShadow, _c = _a.defaultIsVisible, defaultIsVisible = _c === void 0 ? false : _c, className = _a.className, _d = _a.isShow, isShow = _d === void 0 ? true : _d;
        var _e = (0, tslib_1.__read)((0, react_1.useState)(typeof defaultIsVisible === "undefined" ? false : defaultIsVisible), 2), isVisible = _e[0], setIsVisible = _e[1];
        var _f = (0, tslib_1.__read)((0, react_1.useState)(null), 2), containerTooltip = _f[0], setContainerTooltip = _f[1];
        var anchorComponentRef = (0, react_1.useRef)(null);
        var anchorSizeAndPosition = (0, react_1.useMemo)(function () { return (0, helpers_1.calculateSizeAnPositionElement)(anchorComponentRef.current); }, [isVisible]);
        (0, react_1.useEffect)(function () {
            var container = document.getElementsByTagName("body").item(0);
            setContainerTooltip(container);
        }, []);
        (0, react_1.useEffect)(function () {
            onVisibleChange && onVisibleChange(isVisible || false);
        }, [isVisible]);
        var isTouch = "ontouchstart" in window || navigator.maxTouchPoints > 0;
        var handleMouseEnter = function () {
            if (isShow) {
                setIsVisible(true);
            }
        };
        var handleMouseLeave = function () {
            setIsVisible(false);
        };
        return isTouch ? (children) : (react_1.default.createElement(styles_1.TooltipStyled, { ref: anchorComponentRef, onMouseOver: handleMouseEnter, onMouseOut: handleMouseLeave, className: className },
            children,
            containerTooltip &&
                isVisible &&
                text &&
                (0, react_dom_1.createPortal)(react_1.default.createElement(TooltipContent_1.default, { direction: direction, anchorSizeAndPosition: anchorSizeAndPosition, text: text, trailText: trailText, isShadow: isShadow, isTrail: isTrail }), containerTooltip)));
    };
    Tooltip.displayName = "Tooltip";
    exports.default = Tooltip;
});
