/*!
 *
 * Copyright (c) 2020-2024 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    TreatmentAdjustmentDurationConfirm.qml
 * \author  (last)      Stephen Quong
 * \date    (last)      11-Nov-2025
 * \author  (original)  Stephen Quong
 * \date    (original)  11-Nov-2025
 *
 */

// Qt
import QtQuick 2.12

// Project

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

/*!
 * \brief   TreatmentAdjustmentDurationConfirm.qml is the screen
 *          to confirm the treatment duration
 */
Item { id: _root
    objectName: "_TreatmentAdjustmentDurationConfirm"

    property real   ufVolumeGoal            : 0
    property real   ufRate                  : 0
    property int    newTreatmentDuration    : 0

    signal confirmClicked(int vNewTreatmentDuration)

    Row { id: _infoRow
        objectName: "_infoRow"

        readonly property int cellWidth: _root.width / 3.5

        anchors {
            top             : parent.top
            topMargin       : Variables.defaultMargin * 2
            horizontalCenter: parent.horizontalCenter
        }
        spacing: Variables.defaultMargin * 2

        LabelUnitText { id: _newTreatmentDuration
            objectName: "_newTreatmentDuration"
            width       : _infoRow.cellWidth
            label       : qsTr("New Treatment Duration")
            unit        : Variables.unitTextDuration
            value       : _root.newTreatmentDuration
            valueColor  : Colors.ufVolumeGoalText
        }

        LabelUnitText { id: _ufVolumeGoal
            objectName  : "_ufVolumeGoal"
            width       : _infoRow.cellWidth
            label       : qsTr("UF Volume Goal")
            unit        : Variables.unitVolume
            value       : _root.ufVolumeGoal.toFixed(Variables.ultrafiltrationPrecision)
            valueColor  : Colors.ufVolumeGoalText
        }
    }

    Rectangle { id: _divider
        objectName: "_divider"
        anchors {
            top: _infoRow.bottom
            topMargin: Variables.defaultMargin * 3
            left: parent.left
            leftMargin: 50
            right: parent.right
            rightMargin: anchors.leftMargin
        }
        height  : 2
        color   : Colors.panelBorderColor
    }

    Text { id: _description
        objectName  : "_description"
        anchors {
            top: _divider.bottom
            topMargin: _divider.anchors.topMargin
            horizontalCenter: parent.horizontalCenter
        }
        text            : qsTr("A new UF rate will be applied to achieve the ultrafiltration volume goal.")
        color           : Colors.offWhite
        font.pixelSize  : Fonts.fontPixelContainerTitleSmall
    }

    LabelUnitText { id: _ufRate
        objectName  : "_ufRate"
        anchors {
            top: _description.bottom
            topMargin: _description.anchors.topMargin
            horizontalCenter: parent.horizontalCenter
        }
        width       : _infoRow.cellWidth
        label       : qsTr("New UF Rate")
        unit        : Variables.unitTextRate
        value       : _root.ufRate.toFixed(Variables.ultrafiltrationPrecision)
        valueColor  : Colors.ufVolumeGoalText
    }

    TouchRect { id: _confirmButton
        objectName  : "_confirmButton"
        anchors {
            bottom          : parent.bottom
            bottomMargin    : Variables.defaultMargin
            horizontalCenter: parent.horizontalCenter
        }
        width       : Variables.defaultButtonWidth
        height      : Variables.defaultButtonHeight
        text {
            text        : qsTr("Confirm")
            font.weight : Font.Medium
        }
        isDefault   : true

        onClicked   : {
            _root.confirmClicked(_root.newTreatmentDuration)
        }
    }
}
