/*!
 *
 * 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 NotificationBarSmall.qml
 * \author (last) Behrouz NematiPour
 * \date (last) 13-Aug-2020
 * \author (original) Peter Lucia
 * \date (original) 25-Jun-2020
 *
 */

// Qt
import QtQuick 2.12

// Project
import Gui.Actions 0.1
//  Qml imports
import "qrc:/globals"

Rectangle { id: _root
    objectName: "NotificationBar" // SquishQt

    property alias  imageSource     : _image.source
    property bool   imageAutoSize   : false
    property bool   imageAnimated   : false

    property alias  text            : _text.text
    property alias  textColor       : _text.color
    property alias  textfontSize    : _text.font.pixelSize
    property alias  rowAnchors      : _row.anchors

    property int    level           : 0


    visible : _text.text

    height  : Variables.notificationHeight
    color   : Colors.textNotificationNoneBg
    //radius  : Variables.dialogRadius
    anchors {
        bottom  : parent.bottom
        left    : parent.left
        right   : parent.right
    }

    Row { id: _row
        anchors.centerIn: parent
        spacing: 10
        Image { id: _image
            width : source == "" ? 0 : imageAutoSize ? Math.min(_root.height, _root.width) : Variables.notificationIconSize
            height: source == "" ? 0 : imageAutoSize ? Math.min(_root.height, _root.width) : Variables.notificationIconSize
            anchors.verticalCenter   : imageAutoSize ? parent.verticalCenter : undefined
            anchors.top              : imageAutoSize ? undefined : parent.top
            anchors.topMargin        : height > _root.height ? -((height - _root.height) / 2) : 0
        }
        Text { id: _text
            color               : Colors.textNotificationNoneFg
            font.pixelSize      : Fonts.fontPixelNotification
            horizontalAlignment : Text.AlignHCenter
            verticalAlignment   : Text.AlignVCenter
        }
    }

    OpacityAnimator { target: _image
        from        : 0.3
        to          : 1
        duration    : 1500
        running     : imageAnimated && _root.visible
        onFinished  : {
            var tmp = from
            from = to
            to  = tmp
            restart()
        }
    }

    onLevelChanged: {
        switch (level) {
        case GuiActions.ALARM_PRIORITY_HIGH:
            _root.color = Colors.textNotificationHighBg;
            _text.color = Colors.textNotificationHighFg;
            break;
        case GuiActions.ALARM_PRIORITY_MEDIUM:
            _root.color = Colors.textNotificationMedBg;
            _text.color = Colors.textNotificationMedFg;
            break;
        case GuiActions.ALARM_PRIORITY_LOW:
            _root.color = Colors.textNotificationLowBg;
            _text.color = Colors.textNotificationLowFg;
            break;
        default : // GuiActions.ALARM_PRIORITY_NONE
            _root.color = Colors.textNotificationNoneBg;
            _text.color = Colors.textNotificationNoneFg;
            break;
        }
    }
}
