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

// Qt
import QtQuick 2.12

// Project

//  Qml imports
import "qrc:/globals"
import "qrc:/components"
import "qrc:/compounds"
import "qrc:/pages/treatment/sections"

ScreenItem  { id: _root
    readonly property int margin        : Variables.defaultMargin * 5
    readonly property color statusColor : Colors.statusActive
    readonly property real minimum      : vTreatmentRanges.substitutionVolumeMin
    readonly property real maximum      : vTreatmentRanges.substitutionVolumeMax
    readonly property real resolution   : vTreatmentRanges.substitutionVolumeRes

    signal sectionPressuresClicked()
    signal treatmentModeEditClicked()

    // onStatusColorChanged: TODO update to this
    Component.onCompleted : vListModel.setHeaderbarStatusColor(HeaderBar.HDF, _root.statusColor.toString())

    Row { id: _row
        objectName:    "_row"

        spacing: Variables.defaultMargin

        anchors {
            fill        : parent
            topMargin   : 30
            leftMargin  : _root.margin
            rightMargin : _root.margin
            margins: Variables.defaultMargin
        }

        readonly property int cellWidth : width / 2 - ( Variables.defaultMargin / 2 )

        TreatmentHDFComponent { id: _treatmentHdfComponent
            objectName      : "_treatmentHdfComponent"
            width           : _row.cellWidth
            height          : _column.implicitHeight
            statusColor     : _root.statusColor

            onSubstitutionFlowClicked: print ("Substitution Flow Clicked")
        }


        Column { id: _column
            objectName:    "_column"

            spacing : Variables.defaultMargin
            height  : _row.height

            TreatmentPressures { id: _treatmentPressures
                objectName      : "_treatmentPressures"
                width           : _row.cellWidth
                height          : Variables.treatmentCellHeight
                onEditClicked   : sectionPressuresClicked()

                color           : Colors.panelBackgroundColor
                header.color    : Colors.heparinSectionHeader
                enableDropShadow: false
            }

            Item  { id: _autoSub
                width   : _row.cellWidth
                height  : Variables.contentHeight

                Text { id: _autoSubText
                    anchors {
                        verticalCenter  : _autoSub.verticalCenter
                        right           : _autoSub.right
                    }
                    text    : qsTr("Auto Sub")
                    color   : Colors.offWhite
                    height  : Variables.contentHeight
                    width   : implicitWidth
                    verticalAlignment   : Text.AlignVCenter

                    font {
                        pixelSize       : 22
                        family          : Fonts.fontFamilyFixed
                        weight          : Font.Medium
                    }
                }

                BaseSwitch { id: _autoSubSwitch
                    anchors {
                        verticalCenter  : _autoSubText.verticalCenter
                        right           : _autoSubText.left
                        rightMargin     :  Variables.defaultMargin
                    }
                    checked : true  // TODO
                    height  : Variables.contentHeight

                    onClicked: {
                        print (("Auto Sub Switch set to %1").arg(_autoSubSwitch.checked ? "On" : "Off"))
                    }
                }
            }

            LabelUnitContainer { id: _treatmentMode
                objectName      : "_treatmentMode"
                text            : qsTr("Treatment Mode")
                width           : _row.cellWidth
                height          : Variables.adjustmentLabelUnitContainerHeight
                showEdit        : true
                onEditClicked   : _root.treatmentModeEditClicked()

                contentItem : ValueAdjusterCustom { id: _treatmentModeControl
                    value       : vTreatmentCreate.hdfTreatmentMode
                    model       : vTreatmentRanges.hdfTreatmentModeOptions
                    editable    : false
                    onDidChange : function(vValue) {
                        vTreatmentCreate.hdfTreatmentMode = vValue
                    }
                }
            }

            LabelUnitValueAdjuster { id: _prescribedFluidVolume
                objectName          : "_prescribedFluidVolume"
                text                : qsTr("Prescribed Sub. Fluid Volume")
                unitText            : Variables.unitVolume
                decimal             : Variables.substitutionPrecision
                isActive            : true
                minimum             : _root.minimum
                maximum             : _root.maximum
                step                : _root.resolution
                width               : _row.cellWidth
                value               : 24.0
                defaultValue        : 24.0

                onDidChange         : function(vValue) {
                    value = vValue
                }
            }
        }
    }
}
