#!/bin/bash

# Script to extract SVG elements (path, circle, rect, line, polyline, ellipse, polygon) from Leptos icon .rs files to .txt files
# Usage: ./extract_svg.sh

RS_DIR="LEPTOS_LUCIDE_RS"
TXT_DIR="LEPTOS_LUCIDE_TXT"

# Create TXT directory if it doesn't exist
mkdir -p "$TXT_DIR"

# Process all .rs files in the RS directory
for rs_file in "$RS_DIR"/*.rs; do
    if [[ -f "$rs_file" ]]; then
        # Get filename without extension
        basename=$(basename "$rs_file" .rs)
        txt_file="$TXT_DIR/${basename}.txt"
        
        echo "Processing: $rs_file -> $txt_file"
        
        # Extract all SVG elements (path, circle, rect, line, polyline, ellipse, polygon) and remove leading whitespace
        grep -E '<(path|circle|rect|line|polyline|ellipse|polygon)[^>]*/?>' "$rs_file" | sed 's/^[[:space:]]*//' > "$txt_file"
        
        # Count extracted elements
        element_count=$(wc -l < "$txt_file")
        echo "  Extracted $element_count element(s)"
    fi
done

echo "Extraction complete!"