/*!
 *
 * Copyright (c) 2019-2020 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    SDItem.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      16-Apr-2021
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  16-Apr-2021
 *
 */

// Qt
import QtQuick 2.12

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

/*!
 * \brief   SDItem is the component to provide user information about the SDCard.
 * \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 "SD" if the device is not present/ready.
 */
Rectangle { id: _root // TEST : SD-Card not present may need to be handled with better indication(s).

    signal  clicked
    signal  doubleClicked

    color           : Colors.transparent
    anchors {
        top         : parent.top
        right       : parent.right
        topMargin   : 5
        rightMargin : 5
    }
    width : 30
    height: width
    radius: width
    Text { id: _SDText
        anchors.centerIn: parent
        color: ! _GuiView.sdIsReady ? Colors.red : _GuiView.sdIsReadOnly ? "gray" : Colors.white
        text : ! _GuiView.sdIsReady ? qsTr("SD") : _GuiView.sdPercent
        font.pixelSize: 12
        font.bold: true
    }

    ProgressCircle  {
        anchors.fill: parent
        diameter: _root.width
        minimum : 0
        maximum : _GuiView.sdTotal / 1000000 // convert to MB since the value in byte is too big for ProgressCircle.
        value   : _GuiView.sdAvail / 1000000 // convert to MB since the value in byte is too big for ProgressCircle.
        color   : ! _GuiView.sdIsReady ? "red" : _GuiView.sdIsReadOnly ? "gray" : _GuiView.sdIsLow ? Colors.red : "green"
    }

    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()
    }
}
