/*!
 *
 * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved.
 * \copyright                                                       \n
 *          THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM,  \n
 *          IN PART OR IN WHOLE,                                    \n
 *          WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. \n
 *
 * \file    ModalDialog.qml
 * \date    2019/10/21
 * \author  Behrouz NematiPour
 *
 */

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

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

/*!
 * \brief   The parent item for modal dialogs
 */
Dialog { id : _root
    contentItem.objectName: "ModalDialog"  //SquishQt testability

    property bool   autoHide            : false
    property int    autoHideDuration    : 1000

    property alias  notification: _notification

    width   : Variables.dialogWidth
    height  : Variables.dialogHeight

    visible : false
    anchors.centerIn: parent

    enter: Transition { NumberAnimation { property: "opacity"; from: 0.0; to: 1.0 } }
    exit : Transition { NumberAnimation { property: "opacity"; from: 1.0; to: 0.0 } }

    modal: true

    closePolicy: Dialog.NoAutoClose
    Overlay.modal : Rectangle { id : _borderRect
        anchors.fill: parent
        color: Colors.borderDialog
    }


    background: Rectangle { id: _backgroundRect
        color : Colors.backgroundDialog
        radius: Variables.dialogRadius
    }

    onVisibleChanged: {
        if (autoHide && visible) {
            _autoHideAnimation.start()
        }
    }

    NumberAnimation { id: _autoHideAnimation
        running: false
        target: _root
        property: "opacity"
        duration: autoHideDuration
        //easing.type: Easing.InOutQuad
        onFinished: {
            _root.visible = false
        }
    }

    NotificationBar { id: _notification
        text: "" //_root.notificationText
    }
}
