/*!
 *
 * Copyright (c) 2020-2024 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    TreatmentAdjustmentDuration.qml
 * \author  (last)      Vy
 * \date    (last)      11-May-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  27-Apr-2020
 *
 */

// Qt
import QtQuick 2.12

// Project

//  Qml imports
import "qrc:/globals"
import "qrc:/components"

/*!
 * \brief   TreatmentAdjustmentDuration.qml is the screen
 *          To adjust the treatment duration
 */
TreatmentAdjustmentBase { id: _root
    contentItem.objectName: "TreatmentAdjustmentDuration"  //SquishQt testability

    readonly property real  durationValue   : _durationSlider.value
    readonly property alias durationMinimum : _durationSlider.minimum
    readonly property alias durationMaximum : _durationSlider.maximum
    readonly property alias durationStep    : _durationSlider.step

    readonly property alias currentTime     : _currentTimeText.seconds
    readonly property alias durationTime    : _durationText.seconds

    property int   textWidth       : 200

    // Due to how the slider is set up, a setter function is needed to set the slider value
    function setDurationValue(value) {
        _durationSlider.reset(value)
    }

    titleText: qsTr("TREATMENT DURATION")

    Item { id : _container
        readonly property int sideMarginSize: Variables.headerButtonsMargin + Variables.confirmButtonWidth/2 - _durationSliderArrows.width/2 // Centers on the confirmButton
        width   : _root.width
        height  : 200
        anchors.centerIn: parent

        TimeText { id: _currentTimeText
            seconds: vTreatmentTime.time_Elapsed
            secondsVisible: true
            textPixelSize: Fonts.fontPixelDurationCurTime
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: _container.top
            anchors.bottom: _durationSlider.top
            anchors.bottomMargin: 65
        }
        Slider { id : _durationSlider
            // The distance from parent's right side to the rightmost of slider - with slider arrows and spacings considered
            readonly property int sliderAndArrowSpacing : Variables.sliderAdjustButtonSpacing + _durationSlider.handler.width/2
            readonly property int distanceFromSide      : _durationSlider.sliderAndArrowSpacing + _durationSliderArrows.width + _container.sideMarginSize
            width   : _container.width - (distanceFromSide * 2) // determine the size of slider to center
            minimum : vTreatmentRanges.treatmentRanges_Duration_Min //  in Minutes
            maximum : vTreatmentRanges.treatmentRanges_Duration_Max //  in Minutes
            step    : Variables.durationResolution
            stepSnap        : true
            minText.visible : false
            maxText.visible : false
            ticks           : true

            anchors.right       : _durationSliderArrows.left
            anchors.rightMargin : _durationSlider.sliderAndArrowSpacing
            anchors.bottom      : _container.bottom

            TimeText { id: _durationText
                seconds: 60 * _durationSlider.value // in Minutes => to Seconds
                secondsVisible: false
                textPixelSize: Fonts.fontPixelDurationAdjTime
                textWeight: Font.Medium
                anchors {
                    top             : _durationSlider.handler.bottom
                    topMargin       : 10
                    horizontalCenter: _durationSlider.handler.horizontalCenter
                }
            }
        }
        SliderArrows{ id: _durationSliderArrows
            visible : true
            anchors.verticalCenter  : _durationSlider.verticalCenter
            anchors.right           : _container.right
            anchors.rightMargin     : _container.sideMarginSize

            onIncrementValue        : _durationSlider.incrementValue(true)
            onDecrementValue        : _durationSlider.decrementValue(true)
        }
    }

}
