/*!
 *
 * Copyright (c) 2019-2020 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 TreatmentBegin.qml
 * \author (last) Peter Lucia
 * \date (last) 05-Oct-2020
 * \author (original) Peter Lucia
 * \date (original) 03-Aug-2020
 *
 */

// Qt
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12

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

/*!
 * \brief   ManagerHome is the screen
 * which is the default screen in the "Manager" stack
 */
ScreenItem { id: _root
    objectName: "_treatmentBegin"
    backgroundRect.color: Colors.backgroundMainMenu

    signal clickedBack()
    signal clickedStart()

    TopMenuBarCreateTreatment { id: _topMenuBar
        anchors.top: parent.top
        anchors.left: parent.left
        width: parent.width
        onClickedBack: {
            _root.clickedBack();

        }
        state: "begin"
    }

    Flickable { id: _flickable
        objectName: "_treatmentBeginFlickable"
        anchors.top: _topMenuBar.bottom
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        width: parent.width
        contentWidth: parent.width
        contentHeight: _column.implicitHeight
        clip: true
        flickDeceleration: Variables.createTreatmentFlickableDeceleration

        function setInteractive(isInteractive) {
            _flickable.interactive = isInteractive
        }

        ScrollBar.vertical: ScrollBar { id: _scrollBar
            anchors.right: _flickable.right
            anchors.rightMargin: 3
            contentItem: Rectangle {
                color: Colors.backgroundRangeRect
                implicitWidth: 6
                radius: width / 2
                width: 3
            }
        }

        Column { id: _column
            spacing: Variables.treatmentSpacing
            anchors.horizontalCenter: parent.horizontalCenter;
            anchors.fill: parent;

            Text { id: _titleText
                anchors.horizontalCenter: parent.horizontalCenter;
                text: qsTr("Begin Treatment")
                color: Colors.textMain
                font.pixelSize: Fonts.fontPixelTitle
            }

            SliderCreateTreatment {
                id: _ultrafiltration
                objectName: "_ultrafiltration"
                sliderObjectName: objectName + "Slider"
                selectedValueObjectName: objectName + "Value"
                text: "Ultrafiltration Volume"
                units: qsTr("mL")
                min: vTreatmentBegin.ufVolumeMin
                max: vTreatmentBegin.ufVolumeMax
                step: vTreatmentBegin.ufVolumeRes
                onPressed: {
                    _flickable.setInteractive(false)
                    vTreatmentBegin.ufVolume = value
                }
                onReleased: {
                    vTreatmentBegin.ufVolume = value
                    _flickable.setInteractive(true)
                }
            }

            TouchRect { id : _continueRect
                objectName: "_treatmentBeginStart"
                anchors.horizontalCenter: parent.horizontalCenter
                text.text: qsTr("START")
                button.onClicked: {
                    _root.clickedStart()
                }
            }
        }
    }

    onVisibleChanged: {
        if (visible) {
            _mainMenu.hidden = true
        }
    }
}
