#!/bin/bash
# mox - Terminal Music CLI wrapper script
# This script provides a convenient way to run mox from the root directory

# Add Homebrew to PATH (needed for socat, jq, etc on macOS)
if [[ "$OSTYPE" == "darwin"* ]]; then
  # M1/M2 Macs
  [[ -x /opt/homebrew/bin/brew ]] && eval "$(/opt/homebrew/bin/brew shellenv)"
  # Intel Macs
  [[ -x /usr/local/bin/brew ]] && eval "$(/usr/local/bin/brew shellenv)"
fi

# Handle symlinks properly - resolve to actual script location
SOURCE="$0"
while [ -L "$SOURCE" ]; do
  DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"

# Set environment variable so mox.sh knows where the package is installed
export MOX_PACKAGE_DIR="$SCRIPT_DIR"

exec "$SCRIPT_DIR/src/mox.sh" "$@"