/*!
 *
 * Copyright (c) 2019-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    ManagerStack.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      11-May-2021
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  21-Oct-2019
 *
 */

// Qt
import QtQuick 2.12

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


import "qrc:/pages/pretreatment"
import "qrc:/pages/pretreatment/create"

/*!
 * \brief   ManagerStack is the screen
 * which contains the main stack for all the Trearment Manager screens
 * This is the screen which will show up when "Manager" option
 * is selected from the main menu.
 */
StackItem { id : _root
    stackView.initialItem   : _managerHome
    RxManager               { id:       _managerHome
        onShow      :true
        onAddProfile:{
            if ( vTreatmentCreate.parametersValidated ) { vTreatmentCreate.doCancel() }
            _createProfile.clear(true)
            page( _createProfile)
        }
        onLoadProfile:{
            if ( vTreatmentCreate.parametersValidated ) { vTreatmentCreate.doCancel() }
            _createProfile.activateAndRefresh()
            _createProfile.patientIdText = vTreatmentCreate.patientID
            page( _createProfile)
        }
        onVisibleChanged: {
            if (visible){
                _mainMenu.hidden = false
            }
        }
    }

    PreTreatmentCreate{id: _createProfile
        isRxProfile             : true
        header.stepNames        :  []
        onConfirmClicked        : vTreatmentCreate.parametersValidated
                                  ? _root.confirm()
                                  : _createProfile.validate()
        onBackClicked           : vTreatmentCreate.parametersValidated
                                  ? vTreatmentCreate.doCancel()
                                  : pop()

    }
    function confirm(){
        print("confirm")
        vTreatmentCreate.doAddRxProfile()
        pop()
    }

    onVisibleChanged: {
        if (visible) {
            _mainMenu.hidden = false
            vRxProfiles.doInitRxProfilesList()
        }
        else {
            stackView.initialItem = null
        }

    }
}
