/*!
 *
 * 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"
import "qrc:/components/pretreatment"


/*!
 * \brief   ManagerHome is the screen
 * which is the default screen in the "Manager" stack
 */
ScreenItem { id: _root
    objectName: "_treatmentPrime"

    signal clickedBack()
    signal clickedContinue()

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

    Text { id: _titleText
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: _root.top
        anchors.topMargin: 150
        text: qsTr("Priming")
        color: Colors.textMain
        font.pixelSize: Fonts.fontPixelTitle
    }

    ProgressCircle { id: _circle
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: _titleText.bottom
        anchors.topMargin: 25
        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
        anchors.top: _circle.bottom
        anchors.topMargin: 30

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

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

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

    Text { id: _priming_complete
        objectName: "_primingCompleteText"
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: _checklist.bottom
        anchors.topMargin: 45
        text: qsTr("Priming Complete!")
        color: vPriming.primingComplete ? Colors.textMain : Colors.transparent
        font.pixelSize: Fonts.primingFontSize
    }

    TouchRect { id : _continueRect
        objectName: "_treatmentPrimeContinueButton"
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: _priming_complete.bottom
        anchors.topMargin: 50
        width: 490
        height: 60
        text.text:   vPriming.continueBtnText
        disabled : false  // it has not been implemeted in the FW so it is enabled always.
        // /*! vPriming.primingComplete // */vPriming.continueEnabled
        onEnabledChanged: {
            if (enabled) {
                borderColor = Colors.primingReady
                textColor = Colors.primingReady
            } else {
                borderColor = Colors.primingNotReady
                textColor = Colors.primingNotReady
            }
        }

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

    //    }

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