pragma ComponentBehavior: Bound

import QtQuick
import QtQuick.Layouts
import Quickshell.Services.SystemTray
import ZShell.Config
import qs.Components
import qs.Modules.Bar.Components.Common
import qs.Modules.Bar.Components.Tray
import qs.Modules.Bar.Popouts
import qs.Services

WidgetBase {
	id: root

	readonly property alias items: repeater
	readonly property alias layout: sysGrid
	required property GridLayout loader
	readonly property int padding: Tokens.padding.extraSmall
	required property Wrapper popouts
	readonly property real size: horizontal ? sysGrid.implicitWidth + sysGrid.anchors.leftMargin + sysGrid.anchors.rightMargin : sysGrid.implicitHeight + sysGrid.anchors.topMargin + sysGrid.anchors.bottomMargin

	bottomLeftRadius: horizontal ? Tokens.rounding.full : Tokens.rounding.small / 2
	bottomRightRadius: Tokens.rounding.small / 2
	color: Colors.tPalette.m3surfaceContainer
	implicitHeight: horizontal ? baseSize : size
	implicitWidth: horizontal ? size : baseSize
	radius: Tokens.rounding.full
	topRightRadius: horizontal ? Tokens.rounding.small / 2 : Tokens.rounding.full

	GridLayout {
		id: sysGrid

		anchors.bottomMargin: root.horizontal ? 0 : Tokens.padding.extraSmall
		anchors.centerIn: parent
		anchors.leftMargin: root.horizontal ? Tokens.padding.extraSmall : 0
		anchors.rightMargin: root.horizontal ? Tokens.padding.extraSmall : 0
		anchors.topMargin: root.horizontal ? 0 : Tokens.padding.extraSmall
		columns: root.horizontal ? -1 : 1
		rowSpacing: -2

		Repeater {
			id: repeater

			model: SystemTray.items

			TrayItem {
				id: trayItem

				required property int index
				required property SystemTrayItem modelData

				Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
				implicitHeight: 34
				implicitWidth: 34
				ind: index
				item: modelData
				loader: root.loader
				popouts: root.popouts
			}
		}
	}
}
