/*!
 *
 * Copyright (c) 2019-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    ModalDialog.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      28-Sep-2022
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  21-Oct-2019
 *
 */

// 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  backgroundColor     : _backgroundRect.color
    property alias  textColor           : _notification.textColor
    property alias  border              : _backgroundRect.border
    property alias  radius              : _backgroundRect.radius
    property alias  notificationText    : _notification.text
    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; duration: 200 } }
    exit : Transition { NumberAnimation { property: "opacity"; from: 1.0; to: 0.0; duration: 200 } }

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

    NotificationBarSmall { id: _notification }
}
