/*!
 *
 * Copyright (c) 2020-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    NotificationBar.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      29-Jul-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  30-Mar-2020
 *
 */

// Qt
import QtQuick 2.12

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

Rectangle { id: _root
    objectName: "NotificationBar" // SquishQt
    property int   alarmID          : -1
    property alias text             : _text.text
    property alias textPixelSize    : _text.font.pixelSize
    property alias textColor        : _text.color
    property alias isSilenced       : _muteButton.isSilenced
    property alias timeout          : _muteButton.timeout
    property alias backgroundColor  : _root.color
    property bool  iconVisible      : true
    property bool  enableMute       : true

    clip    : true // the mute button expands so we need to clip the outside unwanted area.
    visible : _text.text
    height  : Variables.notificationHeight
    color   : Colors.textNotificationNoneBg
    radius  : Variables.dialogRadius
    anchors {
        bottom  : parent.bottom
        left    : parent.left
        right   : parent.right
    }

    signal clicked()
    signal muteClicked()
    signal listClicked()
    signal maximizeClicked()

    property bool  backgroundFading : false
    Fader {
        fadingProperyTarget : _root
        fadingProperyRunning:  backgroundFading
        fadingProperyName   : "backgroundColor"
        fadingProperyValue  :  backgroundColor
    }

    // Image { id: _muteImage
    //     source: "qrc:/images/iAlarm"
    //     anchors.right: _text.left
    //     anchors.rightMargin: Variables.notificationBarIconMargin;
    //     anchors.verticalCenter: parent.verticalCenter;
    //     sourceSize.height: Variables.notificationBarIconHeight;
    //     sourceSize.width: Variables.notificationBarIconWidth;
    // }

    Text { id: _text
        color               : Colors.textNotificationNoneFg
        anchors.centerIn    : parent
        font.pixelSize      : Fonts.fontPixelNotification
        horizontalAlignment : Text.AlignHCenter
        verticalAlignment   : Text.AlignVCenter
    }

    MouseArea {
        id: _TouchArea
        anchors.fill: parent;
        onClicked: _root.clicked()
    }

    MuteButton { id: _muteButton
        visible: _root.iconVisible
        backgroundColor: _root.color
        anchors {
            verticalCenter  : _root.verticalCenter
            left            : _root.left
            leftMargin      : Variables.silenceIconMargin
        }
        // might be another event
        // but call the same as the rest of the bar for now
        // when it has it's own event then the borderColor transparency can be removed as well
        // to indicate the touchable area.
        borderColor : _root.enableMute ? Colors.white       : Colors.transparent
        onClicked   : _root.enableMute ? _root.muteClicked(): _root.clicked()
    }

    UpDownButton { id: _updownButton
        visible: _root.iconVisible
        backgroundColor: _root.color
        isUp: true
        anchors {
            verticalCenter  : _root.verticalCenter
            right           : _root.right
            rightMargin     : Variables.silenceIconMargin
        }
        onClicked: _root.maximizeClicked()
    }

    TouchRect { id: _alarmsList
        visible: _root.iconVisible
        height: 45
        width : height

        backgroundColor: _root.color
        borderColor : Colors.white

        anchors {
            verticalCenter  : _root.verticalCenter
            right           : _updownButton.left
            rightMargin     : Variables.silenceIconMargin * 2
        }

        Image { id: _alarmListImage
            anchors.centerIn: parent
            height  : Variables.iconsDiameter
            width   : Variables.iconsDiameter
            source  : "qrc:/images/iList"
        }

        onClicked: _root.listClicked()
    }
    Text { id: _alarmID
        text            : qsTr("ID") + ":" + _root.alarmID
        anchors {
            right       : parent.right
            top         : parent.top
            rightMargin : 130
        }
        color           : Colors.textMain
        font.pixelSize  : Fonts.fontPixelDialogText
    }
}
