#!/bin/bash

# Extract all pub mod lines, convert to PascalCase, and generate the tmp_all_icons.rs file with tuples for tooltips

echo "use icons::leptos::*;" > tmp_all_icons.rs
echo "use leptos::prelude::*;" >> tmp_all_icons.rs
echo "" >> tmp_all_icons.rs
echo "pub const ALL_ICONS: &[(fn() -> AnyView, &'static str)] = &[" >> tmp_all_icons.rs

# Extract pub mod lines, sort them, convert snake_case to PascalCase
grep "^pub mod " "/Users/user/dev/1 - RUST/RUST-UI/crates/icons/src/leptos/mod.rs" | \
sed 's/pub mod //g' | \
sed 's/;//g' | \
sort | \
while read module_name; do
    # Skip raw identifiers and problematic modules
    if [[ "$module_name" == r#* ]] || [[ "$module_name" == "_svg_icon" ]]; then
        continue
    fi
    
    # Convert snake_case to PascalCase using awk
    pascal_name=$(echo "$module_name" | awk -F_ '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1' OFS="")
    echo "    (|| view! { <$pascal_name /> }.into_any(), \"$pascal_name\")," >> tmp_all_icons.rs
done

echo "];" >> tmp_all_icons.rs

echo "Generated tmp_all_icons.rs with all icons (tuple format)!"