#!/bin/bash

# Selector Showcase Demo Script
# Demonstrates various selector capabilities with the wasot CLI

WASOT_FILE="examples/selector-showcase.wasot"
WASOT_CMD="cargo run --quiet --bin wasot -- select"

echo "======================================"
echo "     WASOT SELECTOR SHOWCASE"
echo "======================================"
echo

echo "📄 Using file: $WASOT_FILE"
echo

# Helper function to run a selector and show results
run_selector() {
    local selector="$1"
    local description="$2"
    
    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
    echo "🎯 Selector: '$selector'"
    echo "📝 Description: $description"
    echo "Results:"
    $WASOT_CMD "$WASOT_FILE" -s "$selector" | head -10
    echo
}

# Basic Type Selectors
echo "═══════════════════════════════════════"
echo "        BASIC TYPE SELECTORS"
echo "═══════════════════════════════════════"
echo

run_selector "paragraph" "Select all paragraph elements"
run_selector "section" "Select all section elements"
run_selector "quote" "Select all quote elements"
run_selector "*" "Universal selector - matches everything"

# ID Selectors
echo "═══════════════════════════════════════"
echo "           ID SELECTORS"
echo "═══════════════════════════════════════"
echo

run_selector "#intro" "Select element with ID 'intro'"
run_selector "#special-para" "Select element with ID 'special-para'"
run_selector "#featured-article" "Select element with ID 'featured-article'"

# Class Selectors
echo "═══════════════════════════════════════"
echo "          CLASS SELECTORS"
echo "═══════════════════════════════════════"
echo

run_selector ".highlight" "Select elements with class 'highlight'"
run_selector ".important" "Select elements with class 'important'"
run_selector ".primary" "Select elements with class 'primary'"

# Attribute Selectors
echo "═══════════════════════════════════════"
echo "        ATTRIBUTE SELECTORS"
echo "═══════════════════════════════════════"
echo

run_selector "[lang]" "Select elements with 'lang' attribute"
run_selector "[lang=en]" "Select elements where lang='en'"
run_selector "[priority]" "Select elements with 'priority' attribute"
run_selector "[priority=high]" "Select elements where priority='high'"
run_selector "[status]" "Select elements with 'status' attribute"
run_selector "[author]" "Select elements with 'author' attribute"

# Combinators
echo "═══════════════════════════════════════"
echo "           COMBINATORS"
echo "═══════════════════════════════════════"
echo

run_selector "section paragraph" "Descendant: paragraphs inside sections"
run_selector "article paragraph" "Descendant: paragraphs inside articles"
run_selector "section > subsection" "Child: direct subsection children of sections"
run_selector "container > card" "Child: direct card children of container"
run_selector "list item" "Descendant: items inside lists"
run_selector "item subitem" "Descendant: subitems inside items"

# Complex Selectors
echo "═══════════════════════════════════════"
echo "        COMPLEX SELECTORS"
echo "═══════════════════════════════════════"
echo

run_selector "section[lang=en]" "Sections with lang='en'"
run_selector "section[lang=en] paragraph" "Paragraphs inside English sections"
run_selector "#featured-article paragraph" "Paragraphs inside featured article"
run_selector "article > body > paragraph" "Paragraphs directly in article body"

# Multiple Selectors
echo "═══════════════════════════════════════"
echo "       MULTIPLE SELECTORS"
echo "═══════════════════════════════════════"
echo

echo "🎯 Multiple selectors: 'quote' OR 'blockquote'"
$WASOT_CMD "$WASOT_FILE" -s "quote" -s "blockquote" | head -10
echo

echo "🎯 Multiple selectors: '#intro' OR '#summary'"
$WASOT_CMD "$WASOT_FILE" -s "#intro" -s "#summary" | head -10
echo

echo "======================================"
echo "        END OF SHOWCASE"
echo "======================================"