/*!
 *
 * 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

    signal sectionPressuresClicked()
    signal treatmentHDFEditClicked()

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

    Connections { target: vTDOpMode
        function onInTreatmentChanged ( vValue ) { if ( vValue ) { _chart.updateXAxis() } }
    }

    Column { id: _column
        objectName:    "column"

        spacing: Variables.defaultMargin

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

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

        Row { id: _topRow
            objectName:    "topRow"

            spacing : Variables.defaultMargin
            height  : _column.cellHeight

            TreatmentPressures { id: _treatmentPressures
                objectName      : "_treatmentPressures"
                width           : _column.cellWidth
                height          : _column.cellHeight
                onEditClicked   : sectionPressuresClicked()

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

            BaseChart { id: _chart
                width               : _column.cellWidth
                height              : _column.cellHeight
                lineSeries1Value    : vTreatmentPressureOcclusion.arterialPressure
                lineSeries1Color    : Colors.pressuresArterialBar

                lineSeries2Value    : vTreatmentPressureOcclusion.venousPressure
                lineSeries2Color    : Colors.pressuresVenousBar

                lineSeries3Value    : vTreatmentPressureOcclusion.tmpPressure
                lineSeries3Color    : Colors.pressuresTmpBar
            }
        }

        TreatmentHDFComponent { id: _treatmentHdfComponent
            objectName      : "_treatmentHdfComponent"
            width           : _column.width
            height          : _column.cellHeight
            statusColor     : _root.statusColor

            onSubstitutionFlowClicked   : print ("Substitution Flow Clicked")

            onEditClicked               :  _root.treatmentHDFEditClicked()
        }
    }
}
