/*!
 *
 * 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"

Rectangle { id: _root
    property string title       : ""
    property bool editEnabled   : true
    property bool showLock      : false
    property bool showEdit      : true
    property int titleLeftMargin: Variables.defaultMargin * 2
    property bool setEditActive : true // set to disable edit no matter what

    signal editClicked
    signal lockClicked

    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: 30
            weight: Font.Medium
        }
        color: Colors.textTextRectLabel
    }

    IconButton { id  : _lockButton
        anchors {
            verticalCenter  : _title.verticalCenter
            right           : _editButton.left
            rightMargin     : Variables.defaultMargin * 2
        }

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

    IconButton { id  : _editButton
        anchors {
            verticalCenter  : _title.verticalCenter
            right           : parent.right
            rightMargin     :  Variables.defaultMargin * 2
        }

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