/*!
 *
 * 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
    enum Status  {
        Active      = 0,
        Paused      = 1,
        Complete    = 2
    }

    readonly property int margin        : Variables.defaultMargin * 5
    readonly property int hdfState      : vTreatmentHDF.hdfState
    function statusColor ( vHeaderBar = false ) {
        return  _root.hdfState === TreatmentHDF.Active      ?   Colors.statusActive     :
                _root.hdfState === TreatmentHDF.Paused      ?   Colors.statusPaused     :
                _root.hdfState === TreatmentHDF.Complete    ?   vHeaderBar  ?   Colors.statusComplete       :
                                                                                        Colors.statusTextComplete   : Colors.transparent
    }
    property alias notification : _notification

    onHdfStateChanged       : setStatusColor()
    showCreateRxHeaderButton: true

    signal sectionPressuresClicked()
    signal treatmentHDFEditClicked()

    function setStatusColor() {
        vHeaderbarModel.setHeaderbarHDFStatusColor(_root.statusColor(true).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()

            onPauseResumeClicked    : vTreatmentHDF.hdfState === TreatmentHDFComponent.Paused ? vTreatmentAdjustmentHDFState.doResume() :
                                                                                                vTreatmentAdjustmentHDFState.doPause()

            onEditClicked   :  _root.treatmentHDFEditClicked()
        }
    }
    NotificationBarSmall { id: _notification }
}
