/*!
 *
 * Copyright (c) 2020-2026 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    LabelUnitText.qml
 * \author  (last)      Stephen Quong
 * \date    (last)      06-Jan-2026
 * \author  (original)  Stephen Quong
 * \date    (original)  06-Jan-2026
 *
 */

// Qt
import QtQuick 2.12

//  Qml
import "qrc:/globals"

Rectangle { id: _root
    objectName          : "_labelUnitText"

    property alias label            : _label.text
    property alias labelColor       : _label.color
    property string unit            : ""
    property alias value            : _value.text
    property alias valueColor       : _value.color
    property alias valueWidth       : _value.width
    property int   textAlignment    : Text.AlignHCenter

    width               : Variables.adjustmentLabelUnitContainerWidth
    height              : Variables.adjustmentLabelUnitContainerHeight
    radius              : 8.5
    color               : Colors.panelBackgroundColor
    border {
        width   : Variables.panelBorderWidth
        color   : Colors.panelBorderColor
    }

    Item { id: _contentItem
        objectName      : "_contentItem"
        anchors.centerIn: parent
        width           : _root.textAlignment === Text.AlignJustify ? (parent.width - (2 * Variables.defaultMargin)) : childrenRect.width
        height          : parent.height

        Text { id: _label
            objectName      : "_label"
            anchors {
                left            : parent.left
                verticalCenter  : parent.verticalCenter
            }
            width               : contentWidth
            color           : Colors.offWhite
            font.pixelSize  : Fonts.fontPixelContainerTitleSmall
            horizontalAlignment: _root.textAlignment === Text.AlignJustify ? Text.AlignRight : Text.AlignLeft
        }

        Text { id: _unit
            objectName  : "_unit"
            anchors {
                left        : _label.right
                leftMargin  : 5
                baseline    : _label.baseline
            }
            width       : contentWidth
            text        : _root.unit.length > 0 ? ("(%1)").arg(_root.unit) : ""
            color       : _label.color
            font {
                pixelSize  : Fonts.fontPixelContainerUnitSmall
                weight     : Font.Thin
            }
        }

        Text { id: _value
            objectName          : "_value"
            anchors{
                left        : _unit.right
                leftMargin  : Variables.defaultMargin
                right       : _root.textAlignment === Text.AlignJustify ? parent.right : undefined
                baseline    : _label.baseline
            }
            width               : 60
            horizontalAlignment : Text.AlignRight
            color               : Colors.offWhite
            font {
                pixelSize   : Fonts.fontPixelContainerTitle
                weight      : Font.DemiBold
            }
        }
    }
}
