pragma ComponentBehavior: Bound

import Quickshell
import QtQuick
import qs.Components
import ZShell.Config

Item {
	id: root

	readonly property PersistentProperties dashState: PersistentProperties {
		property date currentDate: new Date()
		property int currentTab

		reloadableId: "dashboardState"
	}
	readonly property real nonAnimHeight: state === "visible" ? (content.item?.nonAnimHeight ?? 0) : 0
	required property real offsetScale
	required property string position
	readonly property bool shouldBeActive: root.visibilities.dashboard && Config.dashboard.enabled
	required property PersistentProperties visibilities

	anchors.bottom: position === "bottom" ? parent.bottom : undefined
	anchors.bottomMargin: position === "bottom" ? (-implicitHeight - 5) * offsetScale : 0
	anchors.left: position === "left" ? parent.left : undefined
	anchors.leftMargin: position === "left" ? (-implicitWidth - 5) * offsetScale : 0
	anchors.top: position === "top" ? parent.top : undefined
	anchors.topMargin: position === "top" ? (-implicitHeight - 5) * offsetScale : 0
	implicitHeight: content.implicitHeight
	implicitWidth: content.implicitWidth || 854
	opacity: 1 - offsetScale
	visible: offsetScale < 1

	Loader {
		id: content

		active: root.shouldBeActive || root.visible
		anchors.bottom: root.position === "top" ? parent.bottom : undefined
		anchors.horizontalCenter: root.position !== "left" ? parent.horizontalCenter : undefined
		anchors.right: root.position !== "left" ? undefined : parent.right
		anchors.top: root.position === "bottom" ? parent.top : undefined
		anchors.verticalCenter: root.position === "left" ? undefined : parent.verticalCenter

		sourceComponent: Content {
			dashState: root.dashState
			visibilities: root.visibilities
		}
	}
}
