"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useHover = void 0;
const react_1 = require("react");
const utils_1 = require("../utils");
exports.useHover = (0, utils_1.isTouchDevice)()
    ? () => {
        const [, update] = (0, react_1.useState)();
        const ref = (0, react_1.useRef)();
        if (!ref.current) {
            const handler = (e, active, hover) => {
                ref.current.startedTouching = true;
                ref.current.active = active;
                ref.current.hover = hover;
                update(e);
            };
            const mouseHandler = (e, active, hover) => {
                if (ref.current.startedTouching) {
                    return;
                }
                ref.current.active = active;
                ref.current.hover = hover;
                update(e);
            };
            ref.current = {
                startedTouching: false,
                active: false,
                hover: false,
                listeners: {
                    onTouchStart: (e) => handler(e, true, false),
                    onTouchEnd: (e) => handler(e, false, true),
                    onMouseEnter: (e) => mouseHandler(e, false, true),
                    onMouseDown: (e) => mouseHandler(e, true, false),
                    onMouseUp: (e) => mouseHandler(e, false, true),
                    onMouseLeave: (e) => mouseHandler(e, false, false),
                },
            };
        }
        return ref.current;
    }
    : () => {
        const [, update] = (0, react_1.useState)();
        const ref = (0, react_1.useRef)();
        if (!ref.current) {
            const handler = (e, active, hover) => {
                ref.current.active = active;
                ref.current.hover = hover;
                update(e);
            };
            ref.current = {
                startedTouching: false,
                active: false,
                hover: false,
                listeners: {
                    onMouseEnter: (e) => handler(e, false, true),
                    onMouseDown: (e) => handler(e, true, false),
                    onMouseUp: (e) => handler(e, false, true),
                    onMouseLeave: (e) => handler(e, false, false),
                },
            };
        }
        return ref.current;
    };
//# sourceMappingURL=useHover.js.map