/*!
 *
 * Copyright (c) 2025-2025 Diality Inc. - All Rights Reserved.
 * \copyright
 * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN
 * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER.
 *
 * \file    IdleTimer.qml
 * \author  (last)      Nico Ramirez
 * \date    (last)      2-Dec-2025
 * \author  (original)  Nico Ramirez
 * \date    (original)  2-Dec-2025
 *
 */

// Description: File is used as a idle timer for any UI Page. Waits for any user interaction to reset.
// If  timer timesout then idle signal is emitted. Used to move out of a page for any given idle time.


// Qt
import QtQuick 2.15

Item { id: _root
    property int timeout: 1000 * 60 // 1000 ms * 60 sec = 1 min
    signal idle()                   // emitted when user is inactive

    focus           : true
    Keys.onPressed  : reset()

    // Call this whenever user interacts
    function reset() {
        _idleTimer.restart()
    }

    Timer {id: _idleTimer
        interval    : _root.timeout
        repeat      : false
        onTriggered : _root.idle()
    }

    MouseArea { // Mouse + touch
        anchors.fill        : parent
        onPressed           : _root.reset()
        onReleased          : _root.reset()
        onPositionChanged   : _root.reset()
    }
}
