#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
CSVFILE="$SCRIPT_DIR/../examples/cql_examples.csv"

# Extract header and rows from CSV
tail -n +2 "$CSVFILE" | while IFS="|" read -r name description txt_path cql_path
do
    # Read the CQL content directly from the JSON file
    CQL_FILE="$SCRIPT_DIR/../$cql_path"
    if [ -f "$CQL_FILE" ]; then
        cql_content=$(cat "$CQL_FILE" | tr -d '\n' | sed 's/"/\&quot;/g')
        description=$(echo "$description" | sed 's/"/\&quot;/g')
        # Generate HTML option with description as a tooltip
        echo "<option value=\"$cql_content\" title=\"$description\">$name</option>"
    else
        echo "<!-- File not found: $CQL_FILE -->"
    fi
done