import QtQuick
import ZShell.Config
import qs.Services

CustomClippingRect {
	id: track

	required property var scrollBar
	required property var mouseArea

	anchors.left: parent.left
	anchors.right: parent.right
	anchors.bottom: parent.bottom
	implicitHeight: handle.implicitHeight
	radius: Tokens.rounding.full

	CustomRect {
		id: handle

		anchors.bottom: parent.bottom
		color: Colors.palette.m3secondary
		implicitWidth: track.scrollBar.width * track.scrollBar.effectiveSize
		implicitHeight: track.mouseArea.pressed || track.mouseArea.containsMouse ? Tokens.padding.extraSmall * 2 : Tokens.padding.extraSmall
		opacity: {
			if (!track.scrollBar.enabled)
				return 0;
			if (track.scrollBar.size === 1)
				return 0;
			if (track.mouseArea.pressed)
				return 1;
			if (track.mouseArea.containsMouse)
				return 0.8;
			if (track.scrollBar.policy === CustomScrollBar.AlwaysOn || track.scrollBar.shouldBeActive)
				return 0.6;
			return 0;
		}
		radius: Tokens.rounding.full
		x: track.scrollBar.reversed ? track.scrollBar.width * (1 + track.scrollBar.nonAnimY) * track.scrollBar.travelScale : track.scrollBar.width * track.scrollBar.nonAnimY * track.scrollBar.travelScale

		Behavior on implicitHeight {
			Anim {}
		}
		Behavior on opacity {
			Anim {
				type: Anim.DefaultEffects
			}
		}

		MouseArea {
			acceptedButtons: Qt.NoButton
			anchors.fill: parent
			cursorShape: Qt.PointingHandCursor
			hoverEnabled: true
		}
	}
}
