/*!
 *
 * 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    UserConfirmation.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      24-May-2021
 * \author  (original)  Peter Lucia
 * \date    (original)  30-Nov-2019
 *
 */

// Qt
import QtQuick 2.12

// Project

//  Qml imports
import "qrc:/globals"
import "qrc:/components"
import "qrc:/pages/settings"

/*!
 * \brief   Contains the message for user information or password entry for user to confirm.
 */
SettingsBase { id: _root
    objectName                 : "UserConfirmation" // SquishQt testability

    property bool isPassword: false
    readonly property string password: _password.textInput.text
    property alias  message : _message.text
    function clearPassword() {
        _password.textInput.text = ""
    }

    firstFocusInput : isPassword ? _password : undefined
    TextEntry { id  : _password
        clip                : true
        visible             : _root.isPassword
        label.text          : qsTr("Password")
        label       .width  : 150
        textInput   .width  : 450
        anchors {
            top             : parent.top
            topMargin       : topMarginContent + 120 // moved a little down to be more on center and close to keyboard top edge.
            horizontalCenter: parent.horizontalCenter
        }
        textInput.inputMethodHints  : Qt.ImhNone
        textInput.echoMode          : TextInput.Password
    }

    Image { id                  : _showPassword
        visible                 : _password.visible
        anchors.left            : _password.right
        anchors.leftMargin      : Variables.minVGap
        anchors.verticalCenter  : _password.verticalCenter
        width                   : Variables.iconsDiameter
        height                  : Variables.iconsDiameter
        source                  : "qrc:/images/iEye"
    }

    MouseArea {
        anchors.fill: _showPassword
        onPressed   : _password.textInput.echoMode = TextInput.Normal
        onReleased  : _password.textInput.echoMode = TextInput.Password
    }

    Text { id                   : _message
        visible                 : ! _root.isPassword
        text                    : "Do you ... ?"
        color                   : Colors.textMain
        font.pixelSize          : Fonts.fontPixelTitle
        anchors.topMargin       : topMarginContent
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter  : parent.verticalCenter
        horizontalAlignment     : Text.AlignHCenter
        verticalAlignment       : Text.AlignVCenter
    }
}
