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

// 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: "_treatmentPrime"
    backgroundRect.color: Colors.backgroundMainMenu

    signal clickedBack()
    signal clickedContinue()

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

        }
        state: "prime"
    }

    Flickable { id: _flickable
        objectName: "_treatmentPrimeFlickable"
        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

        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("Priming")
                color: Colors.textMain
                font.pixelSize: Fonts.fontPixelTitle
            }

            ProgressCircle { id: _circle
                anchors.horizontalCenter: parent.horizontalCenter
                minimum: 0
                maximum: vPriming.secondsTotal
                diameter: 100
                value: vPriming.primingComplete ? vPriming.secondsTotal : vPriming.secondsRemaining

                PrimingTimer { id: _timeText
                    anchors.centerIn: parent
                    seconds : vPriming.secondsRemaining
                    completed: vPriming.primingComplete
                }
            }

            Column { id: _checklist
                spacing: 20
                anchors.horizontalCenter: parent.horizontalCenter

                CheckListItem { id: _checking_installation
                    anchors.horizontalCenter: parent.horizontalCenter
                    color: "transparent"
                    text: "Checking installation"
                    completed: vPriming.checkingInstallationComplete
                }

                CheckListItem { id: _creating_dialysate
                    anchors.horizontalCenter: parent.horizontalCenter
                    color: "transparent"
                    text: "Creating dialysate"
                    completed: vPriming.creatingDialysateComplete
                }

                CheckListItem { id: _priming_lines
                    anchors.horizontalCenter: parent.horizontalCenter
                    color: "transparent"
                    text: "Priming lines"
                    completed: vPriming.primingLinesComplete
                }
            }

            Text { id: _priming_complete
                objectName: "_primingCompleteText"
                anchors.horizontalCenter: parent.horizontalCenter
                text: "Priming Complete!"
                color: vPriming.primingComplete ? Colors.textMain : "transparent"
                font.pixelSize: Fonts.primingFontSize
            }

            TouchRect { id : _continueRect
                objectName: "_treatmentPrimeContinueButton"
                anchors.horizontalCenter: parent.horizontalCenter
                text.text: vPriming.continueBtnText
                enabled: vPriming.continueEnabled
                onEnabledChanged: {
                    if (enabled) {
                        borderColor = Colors.primingReady
                        textColor = Colors.primingReady
                    } else {
                        borderColor = Colors.primingNotReady
                        textColor = Colors.primingNotReady
                    }
                }

                button.onClicked: {
                    _root.clickedContinue()
                }
            }

            Rectangle {
                id: _spacer
                height: 75
                width: parent.width
                color: "transparent"
            }
        }
    }

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