#!/bin/bash

echo "==================================="
echo "   SAMATORTRACK CONFIG SWITCHER"
echo "==================================="
echo

echo "Available configurations:"
echo "1. Development (localhost:8000)"
echo "2. Staging (staging-api.samatortrack.id)"
echo "3. Production (api.samatortrack.id)"
echo "4. Custom (manual edit)"
echo

read -p "Select configuration (1-4): " choice

case $choice in
    1)
        echo "Switching to Development configuration..."
        cp "config-templates/config.development.js" "public/config.js"
        echo "✓ Development config applied"
        echo "API URL: http://localhost:8000"
        echo "Debug: Enabled"
        echo "Dev Indicator: Enabled"
        ;;
    2)
        echo "Switching to Staging configuration..."
        cp "config-templates/config.staging.js" "public/config.js"
        echo "✓ Staging config applied"
        echo "API URL: https://staging-api.samatortrack.id"
        echo "Debug: Enabled"
        echo "Dev Indicator: Enabled"
        ;;
    3)
        echo "Switching to Production configuration..."
        cp "config-templates/config.production.js" "public/config.js"
        echo "✓ Production config applied"
        echo "API URL: https://api.samatortrack.id"
        echo "Debug: Disabled"
        echo "Dev Indicator: Disabled"
        ;;
    4)
        echo "Opening config file for manual editing..."
        ${EDITOR:-nano} "public/config.js"
        echo "✓ Config file opened for editing"
        ;;
    *)
        echo "Invalid choice. Please run the script again."
        exit 1
        ;;
esac

echo
echo "==================================="
echo "   CONFIGURATION UPDATED"
echo "==================================="
echo
echo "The application will use the new configuration"
echo "on next page refresh or restart."
echo
echo "Current config file: public/config.js"
echo

read -p "Press Enter to continue..."