#!/usr/bin/env bash
#
# Copyright 2026 Jason Wolff
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0. You may use, modify and
# redistribute this file provided this notice is preserved. See LICENSE and
# NOTICE in the project root. Copyright remains with the author.
#
# Desktop-icon entry point. Opens the menu beside a live job monitor when
# tmux is available, and degrades to a plain single-pane menu when it is not.
TOOL=/usr/local/bin/drive-triage
CONF=/usr/local/share/drive-triage/tmux.conf

if command -v tmux >/dev/null 2>&1 && [ -f "$CONF" ] && [ -z "${TMUX:-}" ]; then
    tmux -f "$CONF" new-session -s "triage-$$" -n bench \
         "$TOOL; printf '\n[menu closed] '; read -rp 'Press Enter to close... ' _" \; \
         select-pane -T "DRIVE TRIAGE - menu" \; \
         split-window -h -l 38% "$TOOL --watch" \; \
         select-pane -t 1 -T "JOBS - live" \; \
         select-pane -t 0
    exit $?
fi

"$TOOL"
rc=$?
echo
[ "$rc" -ne 0 ] && echo "drive-triage exited with code $rc"
read -rp "Press Enter to close this window... " _
