(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-transition-group", "../../styles", "../../../typography/P2", "../../../helpers/getPosition/helpers", "../../../hooks/useReposition"], 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_transition_group_1 = require("react-transition-group");
    var styles_1 = require("../../styles");
    var P2_1 = (0, tslib_1.__importDefault)(require("../../../typography/P2"));
    var helpers_1 = require("../../../helpers/getPosition/helpers");
    var useReposition_1 = require("../../../hooks/useReposition");
    var DEFAULT_DIRECTION = "top";
    var TIMEOUT_TRANSITION = 100;
    var TooltipContent = function (_a) {
        var text = _a.text, direction = _a.direction, anchorSizeAndPosition = _a.anchorSizeAndPosition, isShadow = _a.isShadow, onTrailClick = _a.onTrailClick, trailText = _a.trailText, isTrail = _a.isTrail, className = _a.className;
        var _b = (0, tslib_1.__read)((0, react_1.useState)(direction || DEFAULT_DIRECTION), 2), _direction = _b[0], setDirection = _b[1];
        var _c = (0, tslib_1.__read)((0, react_1.useState)(helpers_1.DEFAULT_SIZE_AND_POSITION_ELEMENT), 2), textContentSize = _c[0], setTextContentSize = _c[1];
        var textContentRef = (0, react_1.useRef)(null);
        (0, react_1.useEffect)(function () {
            setTextContentSize((0, helpers_1.calculateSizeAnPositionElement)(textContentRef.current));
        }, []);
        var callComputedDirection = function () {
            var computedDirection = (0, helpers_1.getComputedDirection)({
                componentSizeAndPosition: anchorSizeAndPosition,
                textContentSize: textContentSize,
                offset: styles_1.MARGIN,
                direction: direction || DEFAULT_DIRECTION
            });
            setDirection(computedDirection);
        };
        (0, react_1.useEffect)(function () {
            callComputedDirection();
        }, [textContentSize]);
        (0, react_1.useEffect)(function () {
            setDirection(direction || DEFAULT_DIRECTION);
        }, [direction]);
        (0, useReposition_1.useReposition)(callComputedDirection);
        return (react_1.default.createElement(react_transition_group_1.CSSTransition, { in: textContentSize.width !== 0, timeout: TIMEOUT_TRANSITION, classNames: "tooltip-content" },
            react_1.default.createElement(styles_1.TooltipContentWrapper, { className: className, ref: textContentRef, isShadow: isShadow, direction: _direction, componentSizeAndPosition: anchorSizeAndPosition, textContentSize: textContentSize },
                react_1.default.createElement(P2_1.default, { type: "lynx" }, text),
                isTrail && (react_1.default.createElement(styles_1.TrailContentStyled, { type: "cygnus", onClick: onTrailClick }, trailText)))));
    };
    exports.default = TooltipContent;
});
