#!/bin/bash

# Script to copy tree-sitter-zx query files to editor directories

# Use current working directory (run from project root)
PROJECT_ROOT="$(pwd)"

# Source and destination directories
SOURCE_DIR="$PROJECT_ROOT/pkg/tree-sitter-zx/queries"
ZED_DIR="$PROJECT_ROOT/ide/zed/languages/zx"
NEOVIM_DIR="$PROJECT_ROOT/ide/neovim/queries/zx"
SITE_PAGES_DIR="$PROJECT_ROOT/site/pages/docs"

# Ensure destination directories exist
mkdir -p "$ZED_DIR"
mkdir -p "$NEOVIM_DIR"
mkdir -p "$SITE_PAGES_DIR"

# Function to copy files
copy_files() {
    local dest_dir="$1"
    local editor_name="$2"
    
    echo "Copying .scm files to $editor_name..."
    echo "  Destination: $dest_dir"
    
    for file in "$SOURCE_DIR"/*.scm; do
        if [ -f "$file" ]; then
            filename=$(basename "$file")
            dest_file="$dest_dir/$filename"
            # Remove existing file or symlink first
            rm -f "$dest_file"
            cp "$file" "$dest_file"
            echo "  Copied: $filename"
        fi
    done
    
    echo ""
}

# Copy files to both editors
copy_files "$ZED_DIR" "Zed"
copy_files "$NEOVIM_DIR" "Neovim"

# Copy highlights.scm to site/pages
echo "Copying highlights.scm to site/pages..."
rm -f "$SITE_PAGES_DIR/highlights.scm"
cp "$SOURCE_DIR/highlights.scm" "$SITE_PAGES_DIR/highlights.scm"
echo "  Copied: highlights.scm"
echo ""

echo "Done! All .scm files have been copied."
echo ""
echo "Source: $SOURCE_DIR"
echo "Destinations:"
echo "  - $ZED_DIR"
echo "  - $NEOVIM_DIR"
echo "  - $SITE_PAGES_DIR (highlights.scm only)"
