/// Macro to create Leptos icon components with cached SVG parsing
///
/// This macro generates both a per-icon cache and the component function.
/// SVG parsing is performed only once per icon type using OnceLock.
///
/// Usage:
/// ```rust
/// create_leptos_icons_animated!(AArrowDown, a_arrow_down);
/// create_leptos_icons_animated!(Activity, activity);
/// ```
#[macro_export]
macro_rules! create_leptos_icons_animated {
    ($component_name:ident, $snake_name:ident) => {
        // Generate a unique cache for this icon using paste for hygiene
        paste::paste! {
            static [<$component_name:upper _CACHE>]: std::sync::OnceLock<Vec<$crate::leptos_animated::parser::SvgElement>> = std::sync::OnceLock::new();
        }

        #[component]
        pub fn $component_name(#[prop(into, optional)] class: Signal<String>) -> impl IntoView {
            use leptos::prelude::*;

            use super::parser::parse_svg_elements;
            use super::svg_icon::SvgIcon;

            // Get cached parsed elements (parse only once per icon type)
            paste::paste! {
                let elements = [<$component_name:upper _CACHE>].get_or_init(|| {
                    // Read SVG content at compile time
                    const SVG_CONTENT: &str = include_str!(concat!("../../ICONS/", stringify!($snake_name), ".txt"));
                    parse_svg_elements(SVG_CONTENT)
                });
            }

            const SVG_ANIMATION: &str = include_str!(concat!("../../ICONS/", stringify!($snake_name), ".css"));

            view! {
                <style>{SVG_ANIMATION}</style>

                <SvgIcon class=class data_name=stringify!($component_name)>
                    <title>{format!("Rust UI Icons - {}", stringify!($component_name))}</title>

                    {elements.iter().map(|element| {
                        element.to_leptos_view()
                    }).collect::<Vec<_>>()}
                </SvgIcon>
            }
        }
    };
}
