"use strict";
/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module ConfigurableUi
 */
// cspell:ignore visibilitychange
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActivityTracker = void 0;
const InternalConfigurableUiManager_1 = require("./InternalConfigurableUiManager");
/** Activity Tracker utility class
 * @internal
 */
class ActivityTracker {
    constructor() {
        this._intervalTimeout = 1000;
        this._events = [
            "keydown",
            "wheel",
            "scroll",
            "mousedown",
            "mousemove",
            "touchstart",
            "touchmove",
            "pointerdown",
            "pointermove",
            "visibilitychange",
        ];
        this._bindEvents = () => {
            this._events.forEach((e) => {
                window.addEventListener(e, this._trackUiActivity, { capture: true });
            });
        };
        this._unbindEvents = () => {
            this._events.forEach((e) => {
                window.removeEventListener(e, this._trackUiActivity, { capture: true });
            });
        };
        this._trackUiInterval = () => {
            InternalConfigurableUiManager_1.InternalConfigurableUiManager.onUiIntervalEvent.emit({
                idleTimeout: this._idleTimeout,
            });
        };
        this._trackUiActivity = (event) => {
            InternalConfigurableUiManager_1.InternalConfigurableUiManager.onUiActivityEvent.emit({ event });
        };
    }
    /** Initializes the time tracker and adds event listeners
     */
    initialize(props) {
        if (props) {
            this._idleTimeout = props.idleTimeout;
            if (props.intervalTimeout !== undefined)
                this._intervalTimeout = props.intervalTimeout;
        }
        this._bindEvents();
        this._intervalId = setInterval(this._trackUiInterval, this._intervalTimeout);
    }
    /** Terminates the time tracker and removes event listeners
     */
    terminate() {
        this._unbindEvents();
        if (this._intervalId) {
            clearInterval(this._intervalId);
            this._intervalId = undefined;
        }
    }
}
exports.ActivityTracker = ActivityTracker;
//# sourceMappingURL=ActivityTracker.js.map