import pywasot

print("=" * 60)
print("Demo 1: Parsing Wasot Content")
print("=" * 60)
print()


# Demo 1: Parsing from Wasot content
content = """
.document
..section :intro
...paragraph arg1 key=value .. Hello world
Some content here
..hr:
..section :main
./id 123
More content
"""

for event in pywasot.parse(content):
    print(event.to_json())
    match event:
        case pywasot.BlockStarted():
            print(f"BlockStarted: .{event.type_name}")
            print(f"   Level: {event.level}, ID: {event.id}")
            if event.text:
                print(f"   Text: {event.text!r}")
            print()

        case pywasot.Text():
            print(f"Text: {event.content!r}")
            print()

        case pywasot.BlockFinished():
            print("BlockFinished")
            print()

        case pywasot.VoidElement():
            print(f"VoidElement: .{event.type_name}:")
            print()

        case pywasot.ContextLine():
            event = event.clone(type_name="cloned_context")
            print(f"ContextLine: {event.type_name}")
            print()

# Demo 2: Direct construction (no Rust needed)
print("=" * 60)
print("Demo 2: Direct Construction")
print("=" * 60)
print()

events = [
    pywasot.BlockStarted.create("document"),
    pywasot.BlockStarted.create("section", level=2, id="intro"),
    pywasot.Text.create("Hello world"),
    pywasot.BlockFinished.create(),
    pywasot.VoidElement.create("hr"),
    pywasot.BlockFinished.create(),
    pywasot.ContextLine.create("This is a context line"),
]

for event in events:
    print(f"  {event!r}")

print()
print("=" * 60)
print("Demo 3: Cloning with modifications")
print("=" * 60)
print()

# Clone a BlockStarted with modifications
original = pywasot.BlockStarted.create("section", level=2, id="intro")
cloned = original.clone(type_name="paragraph", id="modified")
print(f"Original: {original!r}")
print(f"Cloned:   {cloned!r}")
