/*!
 *
 * Copyright (c) 2025-2026 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    DryDemoDialog.qml
 * \author  (last)      Dara Navaei
 * \date    (last)      28-Jan-2025
 * \author  (original)  Dara Navaei
 * \date    (original)  14-Jan-2025
 *
 */
/*!
 *
 * Copyright (c) 2025-2025 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    DryDemoDialog.qml
 * \author  (last)      Dara Navaei
 * \date    (last)      28-Jan-2025
 * \author  (original)  Dara Navaei
 * \date    (original)  14-Jan-2025
 *
 */

// Qt
import QtQuick 2.12

// Project
import Gui.Actions      0.1
import Gui.VEventSpy    0.1

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


/*!
 * \brief   DryDemo is the screen
 */
ModalDialog { id: _root

    width   : 800
    height  : 700

    readonly property int rowCount      : 12  // Number of buttons that are mapped to commands
    readonly property int colCount      : itemsText.length > rowCount ? Math.ceil(itemsText.length / rowCount) : 1

    property var itemsText  : [
        qsTr("Standby"                ), // 0:  Standy
        qsTr("Create Treatment"       ), // 1:  Create Treatment
        qsTr("Water Sample"           ), // 2:  Water sample
        qsTr("Consumables"            ), // 3:  Consumables
        qsTr("Disposables"            ), // 4:  Disposables
        qsTr("System Prime"           ), // 5:  System prime
        qsTr("BP/HR"                  ), // 6:  BP/HR
        qsTr("Ultrafiltration"        ), // 7:  Ultrafiltration
        qsTr("Connection"             ), // 8:  Connection
        qsTr("Start Treatment"        ), // 9:  Start treatment
        qsTr("End Treatment"          ), // 10: End treatment
        qsTr("Disinfection"           ), // 11: Disinfection
        qsTr("High Priority Alarm"    ), // 12: High priority alarm
        qsTr("Medium Priority Alarm"  ), // 13: Medium priority alarm
        qsTr("Low Priority Alarm"     ), // 14: Low priority alarm
    ]

    function col(idx, gap = 0) {
        return idx * 155 + gap
    }

    function row(idx, gap = 10) {
        return idx * 100 + gap
    }

    function itemClicked(vIndex) {
        vConfirm.sendDryDemoCommand(vIndex)
    }

    Connections { target: vConfirm
        function onVisibleChanged  ( vValue ) {
            if ( ! _GuiView.dryDemoMode ) return
            if ( vValue ) open  ()
            else          close ()
        }
    }

    CloseButton { id    : _closeButton
        anchors.left    : undefined
        anchors.right   : parent.right
        anchors.top     : parent.top
        anchors.margins : 6
        onClicked       : close()
    }

    TouchGrid { id: _dryDemoItems
        anchors.centerIn: parent
        onItemClicked   : _root.itemClicked(vIndex)
        rowCount        : _root.rowCount
        colCount        : _root.colCount
        itemWidth       : 325
        itemsText       : _root.itemsText
        rowSpacing      : 0
        colSpacing      : 50
    }
}

