pragma ComponentBehavior: Bound

import QtQuick
import Quickshell
import qs.Modules.Bar as Bar

Region {
	id: root

	// required property Bar.BarLoader bar
	readonly property real borderThickness: win.borderThickness
	required property EdgeGeometry geometry
	readonly property alias menuPopoutRegion: menuPopoutRegion
	required property Panels panels
	required property var win

	height: win.height - geometry.insetTop(borderThickness, true) - geometry.insetBottom(borderThickness, true) - win.dragMaskPadding * 2
	intersection: Intersection.Xor
	width: win.width - geometry.insetLeft(borderThickness, true) * 2 - win.dragMaskPadding * 2
	x: geometry.insetLeft(borderThickness, true) + win.dragMaskPadding
	y: geometry.insetTop(borderThickness, true) + win.dragMaskPadding

	R {
		panel: root.panels.dashboardWrapper
	}

	R {
		panel: root.panels.launcher
	}

	R {
		id: sidebarRegion

		panel: root.panels.sidebar
		width: panel.width * (1 - root.panels.sidebar.offsetScale) + root.borderThickness
		x: root.win.width - width
	}

	R {
		panel: root.panels.osdWrapper
		width: panel.width * (1 - root.panels.osd.offsetScale) + root.borderThickness
	}

	R {
		height: panel.height + root.geometry.insetTop(root.borderThickness)
		panel: root.panels.notifications
		y: 0
	}

	R {
		height: panel.height * (1 - root.panels.utilities.offsetScale) + root.geometry.insetBottom(root.borderThickness)
		panel: root.panels.utilities
		y: root.win.height - height
	}

	R {
		height: root.geometry.horizontal ? panel.height * (1 - root.panels.popoutsWrapper.offsetScale) : panel.height
		panel: root.panels.popoutsWrapper
		width: root.geometry.horizontal ? panel.width : panel.width * (1 - root.panels.popoutsWrapper.offsetScale)
	}

	R {
		panel: root.panels.resourcesWrapper
	}

	R {
		panel: root.panels.settings
	}

	R {
		panel: root.panels.dock
	}

	R {
		panel: root.panels.clipboard
	}

	Region {
		id: menuPopoutRegion

		intersection: Intersection.Subtract
	}

	component R: Region {
		required property Item panel

		height: panel.height
		intersection: Intersection.Subtract
		width: panel.width
		x: panel.x + root.geometry.insetLeft(root.borderThickness)
		y: panel.y + root.geometry.insetTop(root.borderThickness)
	}
}
