/*!
 *
 * Copyright (c) 2019-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    MonitorItem.qml
 * \author  (last)      Nico Ramirez
 * \date    (last)      27-Jun-2025
 * \author  (original)  Nico Ramirez
 * \date    (original)  27-Jun-2025
 *
 */

// Qt
import QtQuick 2.12

import "qrc:/globals"
import "qrc:/components"
import "qrc:/compounds"

Rectangle { id: _root
    property string title           : ""
    property bool editEnabled       : true
    property bool showLock          : false
    property bool showEdit          : true
    property bool showExpanding     : false
    property bool showVitals        : false
    property bool showPauseResume   : false
    property bool isPaused          : true

    property int titleLeftMargin: Variables.defaultMargin * 2
    property bool setEditActive : true // set to disable edit no matter what

    signal editClicked()
    signal lockClicked()
    signal expandingClicked()
    signal vitalsClicked()
    signal pauseResumeClicked()

    color       : Colors.treatmentSectionHeader
    height      : Variables.contentHeight + (Variables.defaultMargin * 2)
    width       : parent.width
    radius      : 15

    anchors.top: parent.top

    MouseArea { id: _mouseArea
        anchors.fill    : parent
        enabled         : editEnabled && _root.setEditActive
        onClicked       : _root.editClicked()
    }

    Text { id: _title
        anchors {
            verticalCenter  : parent.verticalCenter
            left            : parent.left
            leftMargin      :  _root.titleLeftMargin
        }

        text: title
        font {
            pixelSize: 27
            weight: Font.Medium
        }
        color: Colors.textTextRectLabel
    }

    Row { id: _buttonRow
        spacing             : Variables.defaultMargin * 2
        anchors {
            verticalCenter  : _title.verticalCenter
            right           : parent.right
            rightMargin     :  Variables.defaultMargin
        }

        IconButton { id  : _pauseResume
            visible         : showPauseResume
            iconImageSource : _root.isPaused ? "qrc:/images/iPlay" : "qrc:/images/iPause"
            isDefault       : true
            onClicked       : _root.pauseResumeClicked()
        }

        IconButton {id : _vitals
            visible         : showVitals

            onClicked       : _root.vitalsClicked()
        }

        ArrowButton {id : _expandingArrows
            visible         : showExpanding
            expandingArrow  : true
            onClicked       : _root.expandingClicked()
        }

        IconButton { id  : _lockButton
            visible             : showLock
            iconImageSource     : editEnabled ? "qrc:/images/iUnlock" : "qrc:/images/iLock"
            onPressed           :  {
                editEnabled = ! editEnabled
                _root.lockClicked()
            }
        }

        IconButton { id  : _editButton
            visible         : showEdit
            enabled         : editEnabled && _root.setEditActive
            iconImageSource : enabled ? "qrc:/images/iEdit" : "qrc:/images/iEditDisabled"
            onPressed       : _root.editClicked()
        }
    }
}
