/*!
 *
 * Copyright (c) 2021-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    LabelUnitContainer.qml
 * \author  (last)      Nico Ramirez
 * \date    (last)      21-Aug-2025
 * \author  (original)  Nico Ramirez
 * \date    (original)  21-Aug-2025
 *
 */

// Qt
import QtQuick 2.12

//  Qml
import "qrc:/globals"
import "qrc:/components"
import "qrc:/pages/pretreatment"

Rectangle { id: _root
    property Item contentItem       : null
    property alias contentArea      : _contentArea

    property alias text             : _title.text
    property string unitText        : ""
    property bool valid             : true
    property bool showEdit          : false
    property int titleFontSize      : Fonts.fontPixelDefaultButton
    property int unitFontSize       : Fonts.fontUnit

    height  : cellHeight
    width   : cellWidth
    radius  : 8.5
    color   : Colors.panelBackgroundColor

    border {
        width: 1
        color: valid ? Colors.panelBorderColor : Colors.panelInvalidBorderColor
    }

    signal editClicked()

    Row { id: _titleRow
        anchors {
            verticalCenter  : parent.verticalCenter
            left            : parent.left
            leftMargin      : Variables.minVGap + Variables.defaultMargin
        }
        spacing : 10

        Text { id: _title
            anchors.verticalCenter  : _titleRow.verticalCenter
            color                   : Colors.offWhite
            font.pixelSize          : _root.titleFontSize
        }

        Text { id: _unit
            anchors.baseline: _title.baseline
            text            : ("(%1)").arg(_root.unitText)
            color           : Colors.offWhite
            font.pixelSize  : _root.unitFontSize
            font.weight     : Font.Thin
            visible         : _root.unitText.length > 0
        }

        IconButton { id  : _editButton
            anchors.verticalCenter          : _title.verticalCenter
            anchors.verticalCenterOffset    : 5
            visible                 : _root.showEdit
            iconImageSource         : "qrc:/images/iEdit"
            onPressed               : _root.editClicked()
            iconSize                : Variables.iconsDiameter
        }
    }

    ContentArea { id : _contentArea
        anchors {
            top         : _root.top
            left        : _root.left
            leftMargin  : _root.width / 2
            right       : _root.right
            bottom      : _root.bottom
        }

        contentItem: _root.contentItem
    }
}
