// Rich persistent mode of Signal Glass. Dismiss hides controls only; the
// compact bar timer remains until the session ends.

import QtQuick
import qs.config
import qs.modules.focus
import qs.services
import qs.widgets

Rectangle {
    id: root

    radius: Theme.popoverRadius
    color: Theme.alpha(Theme.bgPopover, 0.88)
    border.width: 1
    border.color: Theme.alpha(Theme.fg, 0.1)

    PrismEdge {
        anchors.top: parent.top
        anchors.topMargin: 1
        anchors.left: parent.left
        anchors.right: parent.right
        inset: parent.radius
    }

    Item {
        id: primary
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.top: parent.top
        anchors.margins: 12
        height: 54

        Rectangle {
            id: focusMark
            anchors.left: parent.left
            anchors.verticalCenter: parent.verticalCenter
            width: 38
            height: 38
            radius: 19
            border.width: 0
            color: Theme.alpha(Theme.accent, 0.16)

            Text {
                anchors.centerIn: parent
                text: "\u{F051F}"
                color: Theme.accent
                font.family: Theme.fontMono
                font.pixelSize: 20
            }
        }

        Column {
            anchors.left: focusMark.right
            anchors.leftMargin: 11
            anchors.right: remaining.left
            anchors.rightMargin: 12
            anchors.verticalCenter: parent.verticalCenter
            spacing: 2

            Text {
                width: parent.width
                text: FocusSession.workspaceLabel || "Focus session"
                color: Theme.fg
                elide: Text.ElideRight
                font.family: Theme.fontFamily
                font.pixelSize: Theme.fontSizeLarge
                font.weight: Font.DemiBold
            }

            Text {
                width: parent.width
                text: FocusSession.statusText
                color: FocusSession.paused ? Theme.warn : Theme.fgDim
                elide: Text.ElideRight
                font.family: Theme.fontFamily
                font.pixelSize: Theme.fontSizeSmall
            }
        }

        Text {
            id: remaining
            anchors.right: closeButton.left
            anchors.rightMargin: 8
            anchors.verticalCenter: parent.verticalCenter
            text: FocusSession.remainingText
            color: FocusSession.paused ? Theme.warn : Theme.fg
            font.family: Theme.fontFamily
            font.features: Theme.tabularFigures
            font.pixelSize: Theme.fontSizeLarge
            font.weight: Font.DemiBold
        }

        Rectangle {
            id: closeButton
            anchors.right: parent.right
            anchors.verticalCenter: parent.verticalCenter
            width: 28
            height: 28
            radius: 14
            border.width: 0
            color: closeMouse.containsMouse ? Theme.alpha(Theme.fg, Theme.hoverAlpha) : "transparent"

            ThemedIcon {
                anchors.centerIn: parent
                size: 14
                icon: "window-close-symbolic"
                tint: Theme.fgDim
            }

            MouseArea {
                id: closeMouse
                anchors.fill: parent
                hoverEnabled: true
                cursorShape: Qt.PointingHandCursor
                onClicked: FocusSession.dismiss()
            }
        }

        MouseArea {
            anchors.left: parent.left
            anchors.right: closeButton.left
            anchors.top: parent.top
            anchors.bottom: parent.bottom
            cursorShape: Qt.PointingHandCursor
            z: -1
            onClicked: {
                FocusSession.activateWorkspace();
                FocusSession.dismiss();
            }
        }
    }

    Row {
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.leftMargin: 12
        anchors.rightMargin: 12
        anchors.bottomMargin: 12
        spacing: Theme.itemSpacing

        FocusAction {
            width: (parent.width - parent.spacing * 2) / 3
            icon: FocusSession.paused ? "media-playback-start-symbolic" : "media-playback-pause-symbolic"
            label: FocusSession.paused ? "Resume" : "Pause"
            onActivated: FocusSession.pauseOrResume()
        }

        FocusAction {
            width: (parent.width - parent.spacing * 2) / 3
            icon: "view-grid-symbolic"
            iconFallback: "view-app-grid-symbolic"
            label: "Workspace"
            onActivated: {
                ShellState.openOverview(FocusSession.workspaceId);
                FocusSession.dismiss();
            }
        }

        FocusAction {
            width: (parent.width - parent.spacing * 2) / 3
            icon: "process-stop-symbolic"
            label: "End"
            destructive: true
            onActivated: FocusSession.end(false)
        }
    }
}
