/*!
 *
 * Copyright (c) 2025-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    TreatmentHDFComponent.qml
 * \author  (last)      Nico Ramirez
 * \date    (last)      2-Feb-2026
 * \author  (original)  Nico Ramirez
 * \date    (original)  2-Feb-2026
 *
 */

import QtQuick 2.15

import "qrc:/globals"
import "qrc:/components"
import "qrc:/compounds"
import "qrc:/pages/treatment"

TreatmentSection { id: _root
    readonly property int topTextFontSize           : 25
    readonly property int bottomTextFontSize        : 60
    readonly property real estimatedSubstitutionVal : 23.0    // TODO update later
    readonly property int substitutionRate          : 125   // TODO update later

    readonly property real minimum      : vTreatmentRanges.substitutionVolumeMin
    readonly property real maximum      : vTreatmentRanges.substitutionVolumeMax
    readonly property real resolution   : vTreatmentRanges.substitutionVolumeRes

    readonly property real substitutionValue: 10.0 // TODO update later

    readonly property string statusText     : qsTr("Active")
    /*isDispensing  ? qsTr("Active")    :
          isPaused      ? qsTr("Pause")     :
          isCompleted   ? qsTr("Complete")  :  qsTr("Active")*/

    readonly property string buttonText     : qsTr("Pause Substitution Flow")
    property color  statusColor             : Colors.transparent

    color           : Colors.panelBackgroundColor
    header.color    : Colors.heparinSectionHeader
    enableDropShadow: false
    header {
        showEdit        : false
        titleLeftMargin : Variables.defaultMargin * 3
        title           :  qsTr("Hemodiafiltration") + " (" + qsTr("HDF") + ")"

    }
    contentArea.anchors {
        topMargin   : Variables.defaultMargin * 2
        leftMargin  : Variables.defaultMargin * 3
        rightMargin : Variables.defaultMargin * 2
        bottomMargin: Variables.defaultMargin * 2
    }
    border {
        width: 1
        color: Colors.heparinPanelBorderColor
    }
    header.border {
        width: 1
        color: Colors.heparinPanelBorderColor
    }

    signal substitutionFlowClicked()

    contentItem: Item { id: _content

        LabelValue { id: _estimatedSubstitutionVol
            anchors {
                top     : parent.top
                left    : parent.left
            }
            height                  : parent.height / 3
            width                   : parent.width * 0.2
            topText                 : qsTr("Estimated Final Substitution Volume")
            topTextFont.pixelSize   : topTextFontSize
            topTextFont.weight      : Font.Medium
            bottomText              : (_root.estimatedSubstitutionVal).toFixed(Variables.substitutionPrecision)  //vTreatmentUltrafiltration.setVolume.toFixed(Variables.substitutionPrecision)
            bottomTextFont.pixelSize: bottomTextFontSize
            bottomTextFont.weight   : Font.Normal
            leftAlign               : true
            unitText                : Variables.unitVolume
            bottomTextTopMargin     : Variables.defaultMargin
        }

        LabelValue { id: _substitutionRate
            anchors {
                top         : _estimatedSubstitutionVol.bottom
                topMargin   : Variables.defaultMargin
                left        : parent.left
            }
            height                  : parent.height / 3
            width                   : parent.width * 0.2
            topText                 : qsTr("Substitution Rate")
            topTextFont.pixelSize   : topTextFontSize
            topTextFont.weight      : Font.Medium
            bottomText              : _root.substitutionRate //vTreatmentUltrafiltration.setVolume.toFixed(Variables.substitutionPrecision)
            bottomTextFont.pixelSize: bottomTextFontSize
            bottomTextFont.weight   : Font.Normal
            leftAlign               : true
            unitText                : Variables.unitTextFlowRate
            bottomTextTopMargin     : Variables.defaultMargin
        }

        ProgressBar { id: _progressbar
            anchors {
                verticalCenter      : parent.verticalCenter
                verticalCenterOffset: Variables.defaultMargin * -2
                right               : parent.right
            }
            width           : parent.width * 0.6
            height          : 20
            decimal         : Variables.substitutionPrecision
            minimum         : _root.minimum
            maximum         : _root.maximum
            value           : _root.substitutionValue
            unitText        : Variables.unitVolume
            color           : Colors.progressBarUltrafiltration
            bgColor         : Colors.heparinSectionHeader
            radius          : height
            showMarker      : false
            minText.color: "#818181"
            minText.font {
                pixelSize   : 18
                weight      : Font.Normal
            }

            maxText.color: "#818181"
            maxText.font {
                pixelSize   : 18
                weight      : Font.Normal
            }

            Text { id: _valueText
                anchors {
                    bottom      : parent.top
                    bottomMargin   : Variables.defaultMargin
                    right       : parent.right
                }
                text            : _root.substitutionValue.toFixed(Variables.substitutionPrecision) + " " + Variables.unitVolume
                color           : Colors.white
                font.pixelSize  : 40
                font.weight     : Font.DemiBold
            }

            Text { id: _substituionVolume
                anchors {
                    top         : parent.bottom
                    topMargin   : Variables.defaultMargin * 2.5
                    right       : parent.right
                }
                text            : qsTr("Substitution Volume")
                color           : Colors.textTextRectLabel
                font.pixelSize  : 20
                font.weight     : Font.Medium
            }
        }

        Rectangle { id: _status
            anchors {
                top         : parent.top
                right       : parent.right
            }
            width   : 100
            height  : 30
            radius  : height
            color   : _root.statusColor
            Text { id: _statusText
                anchors.centerIn: parent
                text            : _root.statusText
                color           : Colors.white
                font.pixelSize  : Fonts.fontPixelContainerUnitSmall
                font.weight     : Font.DemiBold
            }
        }

        TouchRect { id : _substitutionFlowButton
            width   : text.implicitWidth + Variables.defaultMargin * 2
            height  : 60
            text    {
                text            : _root.buttonText
                font.pixelSize  : Fonts.fontPixelConfirm
                font.weight     : Font.Medium
            }

            isDefault: true

            anchors {
                bottom          : parent.bottom
                bottomMargin    : Variables.defaultMargin
                horizontalCenter: parent.horizontalCenter
            }

            onClicked: substitutionFlowClicked()
        }
    }
}
