import Quickshell
import Quickshell.Io
import QtQuick

import qs.modules.quicksettings

ShellRoot {
    id: root

    property int confirmedValue: 30
    property int commitCount: 0
    property int lastCommit: -1

    HomeBrightnessSlider {
        id: slider
        width: 200
        value: root.confirmedValue
        accessibleName: "Desk lamp brightness"
        onCommitted: value => {
            root.commitCount += 1;
            root.lastCommit = value;
        }
    }

    IpcHandler {
        target: "home-brightness-slider-test"

        function reset(value: int): void {
            root.confirmedValue = value;
            root.commitCount = 0;
            root.lastCommit = -1;
            slider.cancelPointerInteraction();
        }
        function external(value: int): void { root.confirmedValue = value; }
        function press(position: int): void { slider.beginPointerInteraction(position); }
        function move(position: int): void { slider.movePointerInteraction(position); }
        function release(): void { slider.releasePointerInteraction(); }
        function cancel(): void { slider.cancelPointerInteraction(); }
        function wheel(delta: int): void { slider.commitWheel(delta); }
        function status(): string {
            return JSON.stringify({
                confirmedValue: root.confirmedValue,
                previewValue: slider.previewValue,
                interactionActive: slider.interactionActive,
                commitCount: root.commitCount,
                lastCommit: root.lastCommit,
                accessibleRoleIsSlider: slider.Accessible.role === Accessible.Slider,
                accessibleName: slider.Accessible.name,
                accessibleDescription: slider.Accessible.description,
                accessibleFocusable: slider.Accessible.focusable
            });
        }
    }
}
