#!/bin/bash

# --- CHOOSE YOUR LAUGH TRACK ---
# Change the filename in the line below to your sound file.
# It must be located in the .githooks/sounds/ folder.
THE_ONE_LAUGH="laugh-1.mp3"

# --- No need to edit below this line ---

# Get the directory where this script is located
SCRIPT_DIR="$(dirname -- "$0")"

# Build the full path to the one sound file
SOUND_FILE="$SCRIPT_DIR/sounds/$THE_ONE_LAUGH"

# Silently exit if the chosen sound file doesn't exist for any reason
if [ ! -f "$SOUND_FILE" ]; then
    exit 0
fi

# --- Play the sound based on the Operating System ---
if [[ "$(uname)" == "Darwin" ]]; then
    afplay "$SOUND_FILE" &

elif [[ "$(uname)" == "Linux" ]]; then
    if command -v paplay >/dev/null; then paplay "$SOUND_FILE" &
    elif command -v aplay >/dev/null; then aplay "$SOUND_FILE" &
    fi

elif [[ "$(uname)" =~ MINGW|CYGWIN|MSYS ]]; then
    WIN_PATH=$(cygpath -w "$SOUND_FILE")
    powershell.exe -c "(New-Object Media.SoundPlayer '$WIN_PATH').PlaySync()" &
fi

exit 0