use microformats::parse::Parser;
use url::Url;
use microformats_types::{Item, PropertyValue};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let html = r#"
    <article class="h-entry">
        <h1 class="p-name">Blog Post Title</h1>
        <picture class="p-name">
            <source srcset="/images/hero-800w.jpg 800w, /images/hero-400w.jpg 400w"
                    media="(min-width: 800px)" type="image/jpeg">
            <img src="/images/fallback.jpg" alt="Hero image">
        </picture>
    </article>
    "#;

    let base_url = Url::parse("https://example.com/").unwrap();
    let mut parser = Parser::from_html(html.to_string())?;
    let document = parser.into_document(Some(base_url))?;

    println!("Number of items found: {}", document.items.len());
    for (i, item) in document.items.iter().enumerate() {
        println!("Item {}: types={:?}", i, item.r#type);
        println!("  Properties: {:?}", item.properties.keys().collect::<Vec<_>>());

        // Check for name property specifically
        if let Some(name_prop) = item.properties.get("name") {
            println!("  Name property ({} values): {:?}", name_prop.len(), name_prop);
            for (j, val) in name_prop.iter().enumerate() {
                println!("    Value {}: {:?}", j, val);
            }
        }
    }

    Ok(())
}
