/*!
 *
 * 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    TreatmentAdjustmentVitalsInterval.qml
 * \author  (last)      Nico Ramirez
 * \date    (last)      03-Oct-2025
 * \author  (original)  Nico Ramirez
 * \date    (original)  03-Oct-2025
 *
 */

// Qt
import QtQuick 2.12

// Project
import "qrc:/globals"
import "qrc:/components"
import "qrc:/compounds"

TreatmentAdjustmentBase { id: _root
    contentItem.objectName: "TreatmentAdjustmentVitalsInterval"
    titleText           : qsTr("Vitals Interval")

    titlePixelSize      : Fonts.fontPixelSection
    height              : 500
    width               : 1000

    function confirm() {
        vTreatmentCreate.bloodPressureMeasureInterval = _bpMeasurementIntervalControl.value
        vTreatmentVitals.doTimerStart()
        _root.close()
    }

    onOpened: { _bpMeasurementIntervalControl.value = vTreatmentCreate.bloodPressureMeasureInterval }

    LabelUnitContainer { id: _bpMeasurementInterval
        anchors {
            top             : _root.contentItem.top
            topMargin       : Variables.defaultMargin * 2
            horizontalCenter: _root.contentItem.horizontalCenter
        }

        text        : qsTr("BP Measurement Interval")
        unitText    : Variables.unitTextDuration
        valid       : ! vTreatmentCreate.bloodPressureMeasureIntervalRejectReason
        width       : Variables.adjustmentLabelUnitContainerWidth
        height      : Variables.adjustmentLabelUnitContainerHeight

        contentItem : ValueAdjuster { id: _bpMeasurementIntervalControl
            minimum         : vTreatmentRanges.bloodPressureMeasureIntervalMin
            maximum         : vTreatmentRanges.bloodPressureMeasureIntervalMax
            step            : vTreatmentRanges.bloodPressureMeasureIntervalRes
            defaultValue    : vTreatmentRanges.bloodPressureMeasureIntervalDef
            value           : vTreatmentCreate.bloodPressureMeasureInterval
            canOff          : true
            isActive        : vTreatmentCreate.bloodPressureMeasureIntervalSet

            onDidActiveChange       : function(vState) {  vTreatmentCreate.bloodPressureMeasureIntervalSet = vState }
            onDidChange     : function(vValue) {
                if ( ! _bpMeasurementInterval.valid ) { vTreatmentCreate.bloodPressureMeasureIntervalRejectReason = Variables.noRejectReason }
                value = vValue
            }
        }
    }

    ConfirmButton { id : _confirmButton
        anchors {
            bottom          : _root.contentItem.bottom
            bottomMargin    : Variables.defaultMargin * 4
            horizontalCenter: _root.contentItem.horizontalCenter
        }

        width       : Variables.defaultButtonWidth
        height      : Variables.defaultButtonHeight
        enabled     : _bpMeasurementIntervalControl.isActive

        anchors {
            top     : undefined
            right   : undefined
            margins : 0
        }
        onClicked   : {
            _root.confirm()
        }
    }
}
