/*!
 *
 * Copyright (c) 2023-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    ConfirmDialog.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      29-Aug-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  29-Aug-2023
 *
 */

// Qt
import QtQuick 2.12

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

/*!
 * \brief   Contains the PowerOff Dialog Implementation
 */
ModalDialog { id : _root
    contentItem.objectName          : "PowerOffDialog"  //SquishQt testability
    property string idText          : ""
    property alias  titleText       : _titleText.text
    property alias  messageText     : _messageText.text
    property alias  confirmText     : _confirmTouch.textString
    property alias  confirmVisible  : _confirmTouch.visible
    property alias  cancelText      : _cancelTouch.textString
    property alias  cancelVisible   : _cancelTouch.visible
    property bool   autoClose       : true

    height          : Variables.smallDialogHeight
    width           : Variables.smallDialogWidth

    function footerUpdate() {
        _footer.update()
    }

    TitleText { id: _titleText
        width   : _root.width
        height  : Variables.mainMenuHeight
        anchors.top         : parent.top
        anchors.topMargin   : Variables.minVGap2    // Since it doesnt have border, it looks too close to top border.
        clip                : true
        font.weight         : Font.DemiBold
    }

    TitleText { id: _messageText
        anchors.centerIn            : parent
        anchors.verticalCenterOffset: Variables.defaultMargin * -3 // adjust text up to add more space from bottom buttons
        width   : parent.width
        height  : Variables.mainMenuHeight * 4 // title + reason + 2*Gap
        clip    : true
        text    : qsTr("Are you sure?")
    }

    Footer { id: _footer
        anchors.horizontalCenter    : parent.horizontalCenter

        childrenWidth: Variables.defaultButtonWidth
        children: [
            TouchRect { id  : _cancelTouch
                textString  : qsTr("Cancel")
                height      :  Variables.defaultButtonHeight
                onPressed   : {
                    rejected()
                    if ( autoClose ) close()
                }
            },
            ConfirmButton { id : _confirmTouch
                height          :  Variables.defaultButtonHeight
                anchors.margins : 0
                anchors.top     : undefined
                anchors.right   : undefined
                onClicked: {
                    accepted()
                    if ( autoClose ) close()
                }
            }
        ]
    }

    Text { id: _idText
        text            : qsTr("ID") + ":" + _root.idText
        visible         : _root.idText
        anchors {
            left        : parent.left
            bottom      : parent.bottom
            leftMargin  : 5
            bottomMargin: 5
        }
        color           : notification.visible ? Colors.backgroundDialog : Colors.textMain
        font.pixelSize  : Fonts.fontPixelDialogText
    }
}
