/*!
 *
 * Copyright (c) 2020-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    TreatmentAdjustmentIsolatedUFConfirm.qml
 * \author  (last)      Stephen Quong
 * \date    (last)      08-Oct-2025
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  18-May-2020
 *
 */

// Qt
import QtQuick 2.12

// Project

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

/*!
 * \brief   TreatmentAdjustmentIsolatedUFConfirm.qml is the screen
 *          to confirm requested changes to the treatment isolated UF settings
 */
Item { id: _root
    objectName: "_treatmentAdjustmentIsolatedUFConfirm"  // SquishQt testability

    property real volume    : 0.0
    property int  duration  : 0
    property real rate      : 0.0

    signal confirmVolumeClicked()

    QtObject { id: _private
        objectName: "_private"
        readonly property real volume   : calculatePrecisionValue(_root.volume)
        readonly property real rate     : calculatePrecisionValue(_root.rate)

        readonly property int  multiplier   : Math.pow(10, Variables.ultrafiltrationPrecision)
        function calculatePrecisionValue(value) {
            return Math.round(value * multiplier) / multiplier
        }
    }

    Item { id: _contentArea
        objectName: "_contentArea"
        anchors {
            top         : parent.top
            bottom      : _warningText.top
            left        : parent.left
            right       : parent.right
        }

        Column { id: _contentColumn
            objectName          : "_contentColumn"
            anchors.centerIn    : parent
            width               : 500
            spacing             : Variables.defaultMargin

            LabelUnitText { id: _volumeGoal
                objectName      : "_volumeGoal"
                anchors {
                    left    : parent.left
                    right   : parent.right
                }
                textAlignment   : Text.AlignJustify
                label           : qsTr("Isolated UF Volume Goal")
                unit            : Variables.unitVolume
                valueColor      : Colors.ufVolumeGoalText
                value           : _private.volume.toFixed(Variables.ultrafiltrationPrecision)
            }

            LabelUnitText { id: _duration
                objectName      : "_duration"
                anchors {
                    left    : parent.left
                    right   : parent.right
                }
                textAlignment   : Text.AlignJustify
                label           : qsTr("Isolated UF Duration")
                unit            : Variables.unitTextDuration
                valueColor      : Colors.ufVolumeGoalText
                value           : _root.duration
            }

            LabelUnitText { id: _rate
                objectName      : "_rate"
                anchors {
                    left    : parent.left
                    right   : parent.right
                }
                textAlignment   : Text.AlignJustify
                label           : qsTr("Isolated UF Rate")
                unit            : Variables.unitTextRate
                valueColor      : Colors.ufVolumeGoalText
                value           : _private.rate.toFixed(Variables.ultrafiltrationPrecision)
            }
        }
    }

    Text { id: _warningText
        objectName: "_warningText"
        anchors {
            bottom: _confirmButton.top
            bottomMargin: Variables.defaultMargin * 2
            horizontalCenter: parent.horizontalCenter
        }
        width: contentWidth
        height: Variables.adjustmentLabelUnitContainerHeight
        font.pixelSize: 24
        color: Colors.offWhite
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        text: qsTr("Progress towards the treament IsolatedUF Volume will be paused during Isolated IsolatedUF.")
    }

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

        onClicked: confirmVolumeClicked()
    }
}
