/*!
 *
 * Copyright (c) 2022-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    WifiStatusIndicator.qml
 * \author  (last)      Vy Duong
 * \date    (last)      28-Aug-2023
 * \author  (original)  Vy Duong
 * \date    (original)  28-Aug-2023
 *
 */

// Qt
import QtQuick 2.12
import QtQuick.Controls 2.12 // Dialog

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

/*!
 * \brief   WifiStatusIndicator is the component to provide user information about the Wifi Connection
 * \detials This item includes connection status of Wifi.
 *          The ProgressCircle turns green if the Wifi is connected and grey when not connected to a network
 *          The ProgressCircle will indicate the wifi strength of the network
 *          Single click will open a small dialog with additional info
 */
TouchRect { id: _wifiStatusRoot
    readonly property bool isConnected  : vNetwork.macAddress !== "" // The macAddress property is empty if there is no connection

    property alias thickness            : _batteryLevelCircle.thickness
    property bool  displayInformation   : true

    touchExpanding  : 20 // since the object visual is so small make the mouseArea bigger for the human finger to easier touch.
    enabled         : _wifiStatusRoot.isConnected
    color           : Colors.transparent

    width : 30
    height: width
    radius: width

    ProgressCircle  { id: _batteryLevelCircle
        anchors.fill: parent
        diameter: _wifiStatusRoot.width
        minimum : 0
        maximum : 5
        value   : vNetwork.wifiSignalStrength
        color   : _wifiStatusRoot.isConnected ? Colors.progressCircleConnected : Colors.progressCircleNotReady
    }

    Image { id: _btIcon
        anchors.centerIn: parent
        anchors.fill    : parent
        source          : _wifiStatusRoot.isConnected ? "qrc:/images/WifiLogoConnected" : "qrc:/images/WifiLogoNotConnected"
    }

    onClicked: if(displayInformation) _wifiInfoDialog.open()

    Item {
        // To allow better positioning control, wrapping ModalDialog in Item
        anchors {
            top         : _wifiStatusRoot.bottom
            topMargin   : Variables.dialogSpaceFromIcon

            right       : _wifiStatusRoot.right
        }

        width : _wifiInfoDialog.width
        height: _wifiInfoDialog.height

        StatusDialog{ id: _wifiInfoDialog
            dialogTitleText : qsTr("Wifi Info")
            infoLabels      : [
                qsTr("SSID"                 ),
                qsTr("IP Address"           ),
                qsTr("Signal Strength Level"),
                qsTr("Security Type"        )
            ]
            statusInfo      : [
                vNetwork.ssid                ,
                vNetwork.ipAddress           ,
                vNetwork.wifiSignalStrength  ,
                vNetwork.wifiSecurityType
            ]
        }
    }
}
