#!/usr/bin/env bash

set -euo pipefail

repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
body="$repo_dir/config/dot/quickshell/modules/overview/OverviewBody.qml"
thumbnail="$repo_dir/config/dot/quickshell/modules/overview/WindowThumbnail.qml"

fail() {
    printf 'overview-keyboard contract: %s\n' "$1" >&2
    exit 1
}

rg -q 'Keys\.onLeftPressed' "$body" || fail 'Left does not navigate workspaces'
rg -q 'Keys\.onRightPressed' "$body" || fail 'Right does not navigate workspaces'
rg -q 'Keys\.onUpPressed' "$body" || fail 'Up does not navigate search results'
rg -q 'Keys\.onDownPressed' "$body" || fail 'Down does not navigate search results'
rg -q 'Keys\.onDeletePressed' "$body" || fail 'Delete cannot close the selected search result'
rg -q 'selectedResultIndex' "$body" || fail 'search results have no keyboard selection model'
rg -q 'property bool selected' "$thumbnail" || fail 'thumbnail cannot render keyboard selection'

printf 'overview-keyboard contract: PASS\n'
