/*!
 *
 * Copyright (c) 2022-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    USBProgressItem.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      27-Jun-2022
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  27-Jun-2022
 *
 */

// Qt
import QtQuick 2.12

// Project
//  C++ imports
//  Qml imports
import "qrc:/globals"
import "qrc:/components"

/*!
 * \brief   USBProgressItem is the component to provide user information about the USB Drive.
 * \detials This item includes the space left on the device in percent as well as the ProgressCircle for a graphical representation.
 *          The ProgressCircle turns red if the amount of free space left is less than defined (15% for now)
 *          The percent value in the circle will show "USB" if the device is not present/ready.
 */
Rectangle { id: _root // TEST : USB-Drive not present may need to be handled with better indication(s).

    signal  clicked
    signal  doubleClicked

    readonly property int   sizePowers  : 1000000

    readonly property alias totalText   : _totalText.text
    readonly property alias total       : _progressCircle.maximum
    readonly property alias avail       : _progressCircle.value
    readonly property alias percent     : _percent.text
             property alias thickness   : _progressCircle.thickness

    property bool           displayInformation    : true

    enabled         : _GuiView.usbIsReady
    color           : Colors.transparent
    anchors {
        top         : parent.top
        right       : parent.right
        topMargin   : 5
        rightMargin : 5
    }
    width : 30
    height: width
    radius: width
    Text { id: _percent
        visible         :  displayInformation
        anchors.centerIn: parent
        color: ! _GuiView.usbIsReady ? Colors.red  : Colors.white
        text : ! _GuiView.usbIsReady ? qsTr("USB") : _GuiView.usbPercent
        font.pixelSize: 12
        font.bold: true
    }

    ProgressCircle  { id: _progressCircle
        anchors.fill: parent
        diameter: _root.width
        minimum : 0
        maximum :   _GuiView.usbTotal   / sizePowers // convert to MB since the value in byte is too big for ProgressCircle.
        value   :   _GuiView.usbAvail   / sizePowers // convert to MB since the value in byte is too big for ProgressCircle.
        color   : ! _GuiView.usbIsReady ? "red" : "green"
    }
    Text { id: _totalText
        visible : _GuiView.usbIsReady && displayInformation
        anchors.top: parent.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        color   : Colors.white
        text    : Variables.sizeConverted( _GuiView.usbTotal, _root.sizePowers )
        font.pixelSize: 12
        font.bold: true
    }

    MouseArea { id: _mouseArea
        anchors.fill    : parent
        anchors.margins : -20 // since the object visual is so small make the mouseArea bigger for the human finger to easier touch.
        onClicked       : _root.clicked()
        onDoubleClicked : _root.doubleClicked()
    }
}
