#!/bin/bash

# Test script to debug the management script issue

echo "Starting test..."

# Set basic variables
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_DIR="$(dirname "$SCRIPT_DIR")"
PROJECT_ROOT="$(dirname "$CONFIG_DIR")"
BACKUP_DIR="$CONFIG_DIR/backups"
ENVIRONMENTS=("dev" "prod" "example")

echo "SCRIPT_DIR: $SCRIPT_DIR"
echo "CONFIG_DIR: $CONFIG_DIR"
echo "PROJECT_ROOT: $PROJECT_ROOT"
echo "BACKUP_DIR: $BACKUP_DIR"

# Test list-features function
echo "Testing list-features..."

echo "Available features:"

if [ -d "$CONFIG_DIR/features" ]; then
    echo "Features directory found: $CONFIG_DIR/features"
    for feature_dir in "$CONFIG_DIR/features"/*; do
        if [ -d "$feature_dir" ]; then
            feature_name=$(basename "$feature_dir")
            echo "  - $feature_name"

            # Show available environments for this feature
            envs=()
            for env in "${ENVIRONMENTS[@]}"; do
                if [ -f "$feature_dir/$env.toml" ]; then
                    envs+=("$env")
                fi
            done

            if [ ${#envs[@]} -gt 0 ]; then
                echo "    Environments: ${envs[*]}"
            fi
        fi
    done
else
    echo "Features directory not found: $CONFIG_DIR/features"
fi

echo "Test completed."
