/*!
 *
 * Copyright (c) 2021-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    EndTreatmentRinsebackStack.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      19-Jul-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  11-Apr-2021
 *
 */

// Qt
import QtQuick 2.12

// Project
//  Qml imports
import "qrc:/globals"
import "qrc:/components"
import "qrc:/pages/endtreatment/rinseback"

/*!
 * \brief   the end treatment rinseback stack screen
 */
StackItem { id: _root
    objectName: "_EndTreatmentRinsebackStack"

    stackView.initialItem   : null

    property int    stackStepIndex  : 0

    // Rinseback
    EndTreatmentRinsebackInit       { id: _endTreatmentRinsebackInit        }
    EndTreatmentRinseback           { id: _endTreatmentRinseback            }
    EndTreatmentRinsebackComplete   { id: _endTreatmentRinsebackComplete    }
    EndTreatmentAdditional          { id: _endTreatmentAdditional           }
    EndTreatmentRinsebackReconnect  { id: _endTreatmentRinsebackReconnect   }

    Connections                     { target: _endTreatmentRinsebackInit
        function onRinsebackClicked             ( vValue ) { vTreatmentAdjustmentRinseback.doStart              ()} //82.0
        function onTreatmentEndClicked          ( vValue ) { vTreatmentAdjustmentRinseback.doTreatmentEnd       ()} //82.8
        function onTreatmentBackClicked         ( vValue ) { vTreatmentAdjustmentRinseback.doTreatmentBack      ()} //82.9
    }
    Connections                     { target: _endTreatmentRinseback
        function onAccelerateClicked            ( vValue ) { vTreatmentAdjustmentRinseback.doIncrement          ()} //82.1
        function onDeccelerateClicked           ( vValue ) { vTreatmentAdjustmentRinseback.doDecrement          ()} //82.2
        function onPauseClicked                 ( vValue ) { vTreatmentAdjustmentRinseback.doPause              ()} //82.3
        function onResumeClicked                ( vValue ) { vTreatmentAdjustmentRinseback.doResume             ()} //82.4
        function onEndClicked                   ( vValue ) { vTreatmentAdjustmentRinseback.doEnd                ()} //82.5
    }
    Connections                     { target: _endTreatmentRinsebackComplete
        function onAdditionalClicked            ( vValue ) { vTreatmentAdjustmentRinseback.doAdditional         ()} //82.6
        function onTreatmentBackClicked         ( vValue ) { vTreatmentAdjustmentRinseback.doTreatmentBack      ()} //82.9
        function onConfirmClicked               ( vValue ) { vTreatmentAdjustmentRinseback.doConfirm            ()} //82.7
        function onTreatmentEndClicked          ( vValue ) { vTreatmentAdjustmentRinseback.doTreatmentEnd       ()} //82.8
    }
    Connections                     { target: _endTreatmentRinsebackReconnect
        function onTreatmentBackClicked         ( vValue ) { vTreatmentAdjustmentRinseback.doResume             ()} //82.4
        function onConfirmClicked               ( vValue ) { vTreatmentAdjustmentRinseback.doTreatmentBack      ()} //82.9
        function onTreatmentEndClicked          ( vValue ) { vTreatmentAdjustmentRinseback.doTreatmentEnd       ()} //82.8
    }

    Connections { target: vHDTreatmentStates
        function onRbInitChanged                ( vValue ) { page( _endTreatmentRinsebackInit        , vValue    )}
        function onRbRunChanged                 ( vValue ) { page( _endTreatmentRinseback            , vValue    )}
        function onRbPausedChanged              ( vValue ) { page( _endTreatmentRinseback            , vValue    )}
        function onRbStopChanged                ( vValue ) { page( _endTreatmentRinsebackComplete    , vValue    )}
        function onRbAdditionalChanged          ( vValue ) { page( _endTreatmentAdditional           , vValue    )}
        function onRbReconnectChanged           ( vValue ) { page( _endTreatmentRinsebackReconnect   , vValue    )}
    }

    Connections { target: vTreatmentAdjustmentRinseback
        function onAdjustmentTriggered          ( vValue ) {
            // there is only one message to handle all the sub pages of rinseback
            // since the rejection reason will be cleared by each trasition
            // so it's fine to set all at the same time
            // and let them cleared for their own message when each get visible.
            _endTreatmentRinsebackInit      .reasonText = vTreatmentAdjustmentRinseback.text();
            _endTreatmentRinseback          .reasonText = vTreatmentAdjustmentRinseback.text();
            _endTreatmentRinsebackComplete  .reasonText = vTreatmentAdjustmentRinseback.text();
            _endTreatmentRinsebackReconnect .reasonText = vTreatmentAdjustmentRinseback.text();
        }
    }
}

//  TODO : stackView manual performance enhanced.
// // an idea that is being worked on for later performance imporovement
// // if the stackview becomes slow this idea is a manual transition with animation to be replacecd with stackView
//   PropertyAnimation { id: _rbInitAnimation
//           target: _endTreatmentRinsebackInit
//           property: "opacity"
//           duration: 1000
//           to: vHDTreatmentStates.rbInit ? 1 : 0
//   }
//   PropertyAnimation { id: _rbStopAnimation
//           target: _endTreatmentRinsebackComplete
//           property: "opacity"
//           duration: 1000
//           to: vHDTreatmentStates.rbStop ? 1 : 0
//   }
//   Connections { target: vHDTreatmentStates
//       onStateTriggered : { // this property is a TRIGGER and shall be set at the end of the property setters functions list
//           _endTreatmentRinsebackInit      .visible = vHDTreatmentStates.rbInit
//           _endTreatmentRinseback          .visible = vHDTreatmentStates.rbRun || vHDTreatmentStates.rbPaused
//           _endTreatmentRinsebackComplete  .visible = vHDTreatmentStates.rbStop
//           _endTreatmentAdditional         .visible = vHDTreatmentStates.rbAdditional
//
//       }
//       onRbInitChanged: _rbInitAnimation.running = true
//       onRbStopChanged: _rbStopAnimation.running = true
//   }
//
