#!/bin/bash
#
# CodeVibe Setup Script
# Run this once after installing the plugin to configure PATH
#

set -e

# Determine plugin directory (where this script is located)
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BIN_PATH="$SCRIPT_DIR"

# Detect shell
if [ -n "$ZSH_VERSION" ] || [ "$SHELL" = "/bin/zsh" ]; then
    SHELL_RC="$HOME/.zshrc"
    SHELL_NAME="zsh"
elif [ -n "$BASH_VERSION" ] || [ "$SHELL" = "/bin/bash" ]; then
    SHELL_RC="$HOME/.bashrc"
    SHELL_NAME="bash"
else
    SHELL_RC="$HOME/.profile"
    SHELL_NAME="sh"
fi

# PATH export line
PATH_EXPORT="export PATH=\"\$PATH:$BIN_PATH\""

echo ""
echo "CodeVibe Setup"
echo "======================"
echo ""

# Check if already in rc file
if grep -q "codevibe-claude" "$SHELL_RC" 2>/dev/null; then
    echo "PATH already configured in $SHELL_RC"
else
    # Add to rc file
    echo "" >> "$SHELL_RC"
    echo "# CodeVibe plugin" >> "$SHELL_RC"
    echo "$PATH_EXPORT" >> "$SHELL_RC"
    echo "Added PATH to $SHELL_RC"
fi

echo ""
echo "================================================================"
echo "  Setup complete!"
echo "================================================================"
echo ""
echo "Next steps:"
echo ""
echo "  1. Reload your shell:"
echo "     source $SHELL_RC"
echo ""
echo "  2. Login to your account:"
echo "     codevibe-claude login"
echo ""
echo "  3. Start Claude Code with mobile support:"
echo "     codevibe-claude"
echo ""
echo "  4. Download the iOS app from the App Store"
echo "     Search \"CodeVibe\" and sign in with the same account"
echo ""
echo "----------------------------------------------------------------"
echo "  Documentation: https://github.com/hendryyeh/quantiya-codevibe-claude-plugin"
echo "----------------------------------------------------------------"
