// The leading "show applications" button. GNOME's dash had
// show-apps-at-top: true, which on a bottom dock means the leading edge.
//
// The glyph is drawn rather than pulled from the icon theme: GNOME's app-grid
// icon is literally a 3x3 dot grid, and drawing it removes any dependency on
// which icon theme happens to be installed.

import Quickshell
import QtQuick
import qs.config

Item {
    id: root

    signal entered
    signal exited

    readonly property bool hovered: mouse.containsMouse
    readonly property string label: qsTr("Show Applications")

    implicitWidth: Theme.dockIconSize
    implicitHeight: Theme.dockIconSize

    Rectangle {
        id: bg
        anchors.centerIn: parent
        width: Theme.dockIconSize
        height: Theme.dockIconSize
        radius: width / 2
        border.width: 0 // QTBUG-137166
        color: root.hovered ? Theme.alpha(Theme.fg, Theme.hoverAlpha) : "transparent"

        Behavior on color {
            ColorAnimation {
                duration: Theme.durFast
            }
        }

        transformOrigin: Item.Center
        scale: root.hovered ? 1.15 : 1.0

        Behavior on scale {
            NumberAnimation {
                duration: Theme.durFast
                easing.type: Easing.OutBack
                easing.overshoot: 1.6
            }
        }

        Grid {
            anchors.centerIn: parent
            columns: 3
            spacing: Math.round(Theme.dockIconSize * 0.11)

            Repeater {
                model: 9

                Rectangle {
                    readonly property int dot: Math.round(Theme.dockIconSize * 0.135)
                    width: dot
                    height: dot
                    radius: dot / 2
                    border.width: 0
                    color: Theme.fg
                }
            }
        }
    }

    MouseArea {
        id: mouse
        anchors.fill: parent
        hoverEnabled: true
        onEntered: root.entered()
        onExited: root.exited()
        // vicinae is the launcher this shell uses in place of GNOME's app grid.
        onClicked: Quickshell.execDetached(["vicinae", "toggle"])
    }
}
