#!/bin/bash

# Generate _index.rs from ICONS directory
# This script reads all .txt files from ICONS and generates the Leptos icons index file

ICONS_DIR="/Users/user/dev/1 - RUST/RUST-UI/crates/icons/ICONS"
OUTPUT_FILE="/Users/user/dev/1 - RUST/RUST-UI/crates/icons/src/leptos/_index.rs"

# Function to convert snake_case to PascalCase
snake_to_pascal() {
    echo "$1" | awk -F'_' '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1' OFS=''
}

# Start writing the output file
cat > "$OUTPUT_FILE" << 'EOF'
use leptos::prelude::*;

use crate::create_leptos_icons;

// * This file is auto-generated. Please DO NOT EDIT MANUALLY.

EOF

# Process all .txt files in ICONS directory, sort them first
find "$ICONS_DIR" -name "*.txt" -type f | sort | while read -r file; do
    # Extract filename without extension
    basename_file=$(basename "$file" .txt)
    
    # Convert to PascalCase
    pascal_case=$(snake_to_pascal "$basename_file")
    
    # Add the macro call to the file
    echo "create_leptos_icons!($pascal_case, $basename_file);" >> "$OUTPUT_FILE"
    
done

echo "Generated $OUTPUT_FILE successfully!"