// The banner stack: newest at the top, tucked under the bar on the right.
//
// The window is exactly as wide and tall as the stack, so everything outside
// it stays clickable; the mask trims it further to the cards themselves.

import QtQuick
import Quickshell
import Quickshell.Wayland
import qs.config
import qs.services

PanelWindow {
    id: root

    visible: !Notifs.doNotDisturb && Notifs.popups.length > 0
    color: "transparent"

    anchors.top: true
    anchors.right: true
    margins.top: Theme.barHeight + Theme.barGap * 2
    margins.right: Theme.barSideMargin
    exclusiveZone: 0

    implicitWidth: 400
    implicitHeight: Math.max(1, stack.implicitHeight)

    WlrLayershell.namespace: "qs-notifications"
    WlrLayershell.layer: WlrLayer.Overlay

    // Normally inert so banners never steal a keystroke. An open inline reply
    // is the one case where the surface has to be typeable.
    WlrLayershell.keyboardFocus: root.replyFocused ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.None

    property bool replyFocused: false

    mask: Region {
        item: stack
    }

    Column {
        id: stack
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        spacing: Theme.itemSpacing

        Repeater {
            model: Notifs.popups.slice(0, Settings.maxVisibleToasts)

            Toast {
                required property var modelData

                width: stack.width
                notification: modelData
                onReplyFocusChanged: focused => root.replyFocused = focused
            }
        }
    }
}
