'use client';
"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = __importDefault(require("react"));
var stores_1 = require("../../hooks/stores");
var styles_1 = __importStar(require("../../utils/styles"));
var Container = styles_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  position: fixed;\n  z-index: ", ";\n  width: 100%;\n  height: 0;\n  pointer-events: none;\n  opacity: ", ";\n  transition: opacity ", "ms;\n"], ["\n  position: fixed;\n  z-index: ", ";\n  width: 100%;\n  height: 0;\n  pointer-events: none;\n  opacity: ", ";\n  transition: opacity ", "ms;\n"])), styles_1.theme.zIndex.tooltip, function (_a) {
    var $isDisplay = _a.$isDisplay;
    return ($isDisplay ? 1 : 0);
}, styles_1.theme.durationNumber * 2);
var TooltipContainer = styles_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n  position: absolute;\n  pointer-events: none;\n  transform: translate(-50%, calc(100% + 2px));\n"], ["\n  position: absolute;\n  pointer-events: none;\n  transform: translate(-50%, calc(100% + 2px));\n"])));
exports.default = react_1.default.memo(function () {
    var _a = react_1.default.useState(false), isDocumentFocused = _a[0], setIsDocumentFocused = _a[1];
    var _b = react_1.default.useState({ x: 0, y: 0 }), cursorPosition = _b[0], setCursorPosition = _b[1];
    var containerStyle = react_1.default.useMemo(function () { return ({ top: "".concat(cursorPosition.y, "px"), left: "".concat(cursorPosition.x, "px") }); }, [cursorPosition]);
    var tooltips = (0, stores_1.useTooltipStore)().tooltips;
    var content = ((tooltips === null || tooltips === void 0 ? void 0 : tooltips[0]) || {}).content;
    react_1.default.useEffect(function () {
        var moveEventListener = function (event) {
            return setCursorPosition({ x: event.clientX, y: event.clientY });
        };
        var enterEventListener = function () { return setIsDocumentFocused(true); };
        var leaveEventListener = function () { return setIsDocumentFocused(false); };
        document.addEventListener('mousemove', moveEventListener);
        document.addEventListener('mouseenter', enterEventListener);
        document.addEventListener('mouseleave', leaveEventListener);
        return function () {
            document.removeEventListener('mousemove', moveEventListener);
            document.removeEventListener('mouseenter', enterEventListener);
            document.removeEventListener('mouseleave', leaveEventListener);
        };
    }, [setCursorPosition, setIsDocumentFocused]);
    return ((0, jsx_runtime_1.jsx)(Container, { "$isDisplay": isDocumentFocused && !!content, style: containerStyle, children: (0, jsx_runtime_1.jsx)(TooltipContainer, { children: content }) }));
});
var templateObject_1, templateObject_2;
//# sourceMappingURL=TooltipProvider.js.map