/*!
 *
 * Copyright (c) 2023-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    SettingsDGScheduling.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      26-May-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  26-May-2023
 *
 */

// Qt
import QtQuick 2.12

// Project
import Gui.Actions 0.1;

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

/*!
 * \brief   SettingsDG provides user options to manually initiate the
 *              - Water Flush
 *              - Heat Disinfection
 *              - Chemical Disinfection \n
 *          or schedule the
 *              - Water Flush
 *              - Heat Disinfection     \n
 *          on daily cycle at certain time of the day
 */
SettingsBase { id: _root
    QtObject { id: _settingsDG
        property string status: ""
        function doConfirm(vWaterFlushScheduleTimeHour          ,
                           vWaterFlushScheduleTimeMinute        ,
                           vWaterFlushScheduleCycle             ,
                           vHeatDisinfectionScheduleTimeHour    ,
                           vHeatDisinfectionScheduleTimeMinute  ,
                           vHeatDisinfectionScheduleCycle       ) {
            console.debug(vWaterFlushScheduleTimeHour           , ":"  ,
                          vWaterFlushScheduleTimeMinute         , " - ",
                          vWaterFlushScheduleCycle              , " | ",
                          vHeatDisinfectionScheduleTimeHour     , ":"  ,
                          vHeatDisinfectionScheduleTimeMinute   , " - ",
                          vHeatDisinfectionScheduleCycle        )
        }
    }

    labelWidth  : 200
    entryWidth  : 100

    property int            titleIndent : 25

    readonly property bool  isValid     :
        _waterFlushScheduleTime         .isValid &&
        _waterFlushScheduleCycle        .isValid &&
        _heatDisinfectionScheduleTime   .isValid &&
        _heatDisinfectionScheduleCycle  .isValid

    firstFocusInput : _waterFlushScheduleTime
    notificationText: _settingsDG.status
    onConfirmClicked: {
        _settingsDG.doConfirm(
                    _waterFlushScheduleTime         .hour   ,
                    _waterFlushScheduleTime         .minute ,
                    _waterFlushScheduleCycle        .text   ,
                    _heatDisinfectionScheduleTime   .hour   ,
                    _heatDisinfectionScheduleTime   .minute ,
                    _heatDisinfectionScheduleCycle  .text   )
    }

    onVisibleChanged: {
        if ( ! visible ) _root.notificationText = ""
    }

    Row { id: _container
        spacing: 25
        y : Qt.inputMethod.visible && _keyboard.visible ? topMarginContent : ( (_root.height - _container.height) / 2 )
        Behavior on y { NumberAnimation { duration: Variables.keybardAnimationDuration } }
        anchors.horizontalCenter: parent.horizontalCenter

        Column {
            spacing         : 25
            leftPadding     :  titleIndent
            Label {
                leftPadding : -titleIndent
                text        : qsTr("Water Flush")
            }
            Line { x        : -titleIndent; width     : 500 }
            TimeEntry { id  : _waterFlushScheduleTime
                hour        : "02" // TODO: Settings Manufacturing
                minute      : "00" // TODO: Settings Manufacturing
                labelWidth  : _root.labelWidth
                nextInput   : _waterFlushScheduleCycle
            }
            TextEntry { id  : _waterFlushScheduleCycle
                nextInput   : _heatDisinfectionScheduleTime.firstInput
                text        : "1" // TODO: Settings Manufacturing
                label.text  :  qsTr("Cycle (Days)")
                label.width : _root.labelWidth
                validator   : IntValidator { bottom: 0;  top : 7 } // TODO: Settings Manufacturing
            }
        }

        Column {
            spacing         : 25
            leftPadding     :  titleIndent
            Label {
                leftPadding : -titleIndent
                text        : qsTr("Heat Disinfection")
            }
            Line { x        : -titleIndent;  width    : 500 }
            TimeEntry { id  : _heatDisinfectionScheduleTime
                hour        : "02" // TODO: Settings Manufacturing
                minute      : "00" // TODO: Settings Manufacturing
                labelWidth  : _root.labelWidth
                nextInput   : _heatDisinfectionScheduleCycle
            }
            TextEntry { id  : _heatDisinfectionScheduleCycle
                text        : "21" // TODO: Settings Manufacturing
                label.text  : qsTr("Cycle (Days)")
                label.width : _root.labelWidth
                validator   : IntValidator { bottom: 0;  top : 60 } // TODO: Settings Manufacturing
            }
        }
    }
}
