/*!
 *
 * Copyright (c) 2021-2023 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    PostTreatmentReview.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      28-Sep-2022
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  21-Apr-2021
 *
 */

// Qt
import QtQuick 2.12


// Project
//  Qml imports
import "qrc:/globals"
import "qrc:/components"
import "qrc:/compounds"
import "qrc:/pages/posttreatment"

/*!
 * \brief   the post treatment Treatment Log review screen
 */
PostTreatmentBase { id: _root
    signal itemClicked(int vIndex)

    readonly property alias itemsText : _parametersGrid.itemsText
    readonly property alias itemsValue: _parametersGrid.itemsValue
    readonly property alias itemsUnit : _parametersGrid.itemsUnit

    header.confirmText.text: qsTr("NEXT")

    ExportButton { id: _exportButton
        isSmall         : true
        anchors.top     : parent.top
        anchors.left    : parent.left
        enabled         : vPostTreatmentAdjustmentTreatmentLog.isIdle && _GuiView.usbIsReady && !_GuiView.exportRunning
        onClicked       : vPostTreatmentAdjustmentTreatmentLog.doExport()
    }
    USBButton { id: _usbButton
        anchors.top     : _exportButton.top
        anchors.left    : _exportButton.right
        anchors.leftMargin: Variables.minVGap
        enabled         : _GuiView.usbIsReady && !_GuiView.exportRunning
    }

    ScrollBar {
        anchors.fill: _flickable
        flickable   : _flickable
        backColor   : Colors.backgroundDialog
    }

    Label { id: _txCode
        anchors.bottom  : _flickable.top
        anchors.left    : _flickable.left
        width           : _flickable.width
        text            : qsTr("Code: ") + vPostTreatmentAdjustmentTreatmentLog.txCode
        font.pixelSize  : Fonts.fontPixelButton
    }

    Flickable { id: _flickable
        clip: true
        anchors {
            top             : _root.title.bottom
            topMargin       : Variables.minVGap * 2 // * 2 : it was too close to title and also better with rows not half cut.
            bottom          : _root.bottom
            bottomMargin    : Variables.notificationHeight + Variables.minVGap
            horizontalCenter: parent.horizontalCenter
        }
        width        : parent.width - Variables.minVGap2 * 2 // * 2 : for each side
        contentWidth : width
        contentHeight: _parametersGrid.height

        TouchGrid { id: _parametersGrid
            // TODO: fixed only for this list since it has been used other places.
            // investigate more to move these readonly properties in the TouchGrid component.
            readonly property int _itemCount: vPostTreatmentAdjustmentTreatmentLog.parametersTitle.length
            readonly property int _colCount : 2
            readonly property int _rowCount : Math.ceil( _itemCount / _colCount )

            height          : _rowCount * ( rowSpacing + itemHeight  ) + itemHeight
            width           : parent.width
            colCount        : _colCount
            rowCount        : _rowCount
            itemWidth       : 575
            rowSpacing      : 0
            colSpacing      : 50
            lineColor       : Colors.backgroundMain
            itemsText       : vPostTreatmentAdjustmentTreatmentLog.parametersTitle
            itemsValue      : vPostTreatmentAdjustmentTreatmentLog.parametersText
            itemsUnit       : vPostTreatmentAdjustmentTreatmentLog.parametersUnit
            itemsValueLeftMargin    : 350 // if decreased may be covered by title
            itemsUnitLeftMargin     : 470 // if increased will be covered by chevron if touchable
            // Note: to make the item touchable
            // set the touchable: true
            // and set the index ot the touchable item in the itemsTouchable: [] list to 1
            // like displayed below.
            touchable       : false
            // itemsTouchable  : [
            //     0,0,0,0,0,0,0,0,0,0,
            //     0,0,0,0,0,0,0,0,0,0,
            //     0,0,0,0,0,0,0,0,0,0,
            //     0,0,0,0,0,0,0,0,0,0,
            // ]
            onItemClicked: _root.itemClicked(vIndex)
        }
    }
    reasonText      : vPostTreatmentAdjustmentTreatmentLog.text()
    informationText : vPostTreatmentAdjustmentTreatmentLog.notification
}

