# -*- coding: utf-8 -*-
"""
Example usage of the colab-print library.

This script demonstrates various features of the colab-print library for displaying
styled text, lists, dictionaries, tables, and pandas DataFrames in environments
that support IPython display (like Jupyter notebooks or Google Colab).
"""

import pandas as pd
import numpy as np  # Added for array examples
from colab_print import (
    Printer, header, title, subtitle, section_divider, subheader,
    code, card, quote, badge, data_highlight, footer,
    highlight, info, success, warning, error, muted, primary, secondary,
    dfd, table, list_, dict_, progress, mermaid, md
)
import time

P = Printer()


def demo_printer_class():
    """Demo using the Printer class directly."""

    print("=== DEMO: Using Printer Class Directly ===")
    printer = Printer()
    print(f"Available styles: {printer.get_available_styles()}")

    # --- Text Display --- 
    print("\n--- Text Display Examples ---")
    printer.display("This is default text.")
    printer.display("This is highlighted text.", style="highlight")
    printer.display("This is info text.", style="info")
    printer.display("This is success text.", style="success")
    printer.display("This is warning text.", style="warning")
    printer.display("This is error text.", style="error")
    printer.display("This is muted text.", style="muted")
    printer.display("Inline style example.", style="info", font_weight="bold", text_decoration="underline")

    # --- List Display --- 
    print("\n--- List Display Examples ---")
    simple_list = ['Apple', 'Banana', 'Cherry']
    nested_list = ['Fruit', ['Apple', 'Banana'], 'Vegetable', ['Carrot', 'Broccoli']]
    printer.display_list(simple_list, style="success", item_style="padding-left: 15px;")
    printer.display_list(nested_list, ordered=True, style="default")
    printer.display_list(('Tuple', 'Item 1', 'Item 2'), style="warning")  # Also works with tuples

    # --- Dictionary Display --- 
    print("\n--- Dictionary Display Examples ---")
    simple_dict = {'Name': 'Bob', 'Role': 'Developer', 'Experience (Years)': 5}
    nested_dict = {
        'Project': 'Colab Print',
        'Version': '0.1.0',
        'Author': {'Name': 'Alaa', 'Contact': 'test@example.com'},
        'Features': ['Text', 'List', 'Dict', 'Table', 'DataFrame']
    }
    printer.display_dict(simple_dict, style="info")
    printer.display_dict(nested_dict, style="default", key_style="color: blue;", value_style="color: green;")

    # --- Table Display --- 
    print("\n--- Table Display Examples ---")
    headers = ["ID", "Product", "Price", "In Stock"]
    rows = [
        [101, "Laptop", 1200.50, True],
        [102, "Keyboard", 75.00, False],
        [103, "Mouse", 25.99, True]
    ]
    printer.display_table(headers, rows, style="default", caption="Inventory")
    printer.display_table(headers, rows, style="highlight", width="80%")

    # --- DataFrame Display --- 
    print("\n--- DataFrame Display Examples ---")
    data = {
        'StudentID': ['S101', 'S102', 'S103', 'S104', 'S105'],
        'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
        'Score': [85.5, 92.0, 78.8, 88.1, 95.2],
        'Major': ['CompSci', 'Physics', 'Math', 'CompSci', 'Physics']
    }
    df = pd.DataFrame(data)

    printer.display_df(df, caption="Student Scores")
    printer.display_df(df, style="info", max_rows=3, precision=1, caption="Limited Rows & Precision")
    printer.display_df(df, style="success",
                       index=False,
                       highlight_cols=['Name', 'Score'],
                       highlight_rows={1: "background-color: #DFF0D8;"},  # Bob
                       highlight_cells={(4, 'Score'): "background-color: yellow; font-weight: bold;"},  # Eve's score
                       caption="Styled DataFrame without Index")

    # --- Custom Styles & Themes --- 
    print("\n--- Custom Style & Theme Examples ---")

    # Add a single custom style
    printer.add_style("custom_blue", "color: navy; border: 1px solid blue; padding: 5px;")
    printer.display("This uses a custom added style.", style="custom_blue")
    print(f"Updated styles: {printer.get_available_styles()}")

    # Initialize a new Printer with additional themes
    custom_themes = {
        'dark_mode': 'color: #E0E0E0; background-color: #282C34; font-family: Consolas, monospace;',
        'report': 'font-family: "Times New Roman", serif; font-size: 14px; color: #333;'
    }
    themed_printer = Printer(additional_styles=custom_themes)
    themed_printer.display("Dark mode style text.", style="dark_mode")
    themed_printer.display_dict({'report_section': 'Results'}, style="report")


def demo_global_shortcuts():
    """Demo using the global shortcut functions."""

    print("\n=== DEMO: Using Global Shortcut Functions ===")

    # --- Heading & Structure Display ---
    print("\n--- Heading & Structure Display ---")
    title("Colab Print Demo")
    subtitle("A showcase of styling capabilities")
    header("Main Section Header")
    subheader("Important Subsection")
    section_divider("Section Break")

    # --- Content formatting ---
    print("\n--- Content Formatting ---")
    card("This is a card with important content that stands out from the rest of the text")
    quote("The best way to predict the future is to invent it. - Alan Kay")
    code("import pandas as pd\ndf = pd.read_csv('data.csv')\nprint(df.head())")

    # Code with syntax highlighting (basic)
    code("""def example_function(param):
    \"\"\"An example function with a docstring.\"\"\"
    if param > 10:
        return param * 2
    else:
        return param""", highlighting_mode="block")

    # --- Status indicators ---
    print("\n--- Status Indicators ---")
    info("This is an informational message")
    success("Operation completed successfully!")
    warning("Please be cautious with this action")
    error("An error occurred during processing")
    muted("This is less important information")

    # --- Special elements ---
    print("\n--- Special Elements ---")
    data_highlight("99.8%")
    badge("NEW")
    badge("PRO", background_color="#9C27B0")  # Style override example
    primary("Primary action button")
    secondary("Secondary option")
    highlight("This text needs attention", font_size="20px")  # Style override example
    footer("© 2023 Colab Print Project")

    # --- Data Container Display ---
    print("\n--- Data Container Display ---")

    # Sample data
    sample_dict = {
        "key1": "value1",
        "key2": "value2",
        "nested": {"a": 1, "b": 2}
    }

    sample_list = ["Item 1", "Item 2", ["Nested 1", "Nested 2"]]

    headers = ["Name", "Value", "Description"]
    rows = [
        ["Alpha", 100, "First item in list"],
        ["Beta", 200, "Second item in list"],
        ["Gamma", 300, "Third item in list"]
    ]

    data = {
        'Category': ['A', 'B', 'C', 'D'],
        'Value1': [10, 20, 30, 40],
        'Value2': [100, 90, 80, 70]
    }
    df = pd.DataFrame(data)

    # Display with the shortcuts
    dict_(sample_dict, key_style="color: #1565C0; font-weight: bold;")
    list_(sample_list, ordered=True)
    table(headers, rows, caption="Sample Table Data")
    dfd(df, max_rows=3, caption="Sample DataFrame")

    # --- Style Override Examples ---
    print("\n--- Style Override Examples ---")
    header("Default Header")
    header("Custom Color Header", color="#E53935")
    header("Larger Header", font_size="32px")

    info("Default Info Message")
    info("Custom Info", background_color="rgba(3, 169, 244, 0.1)", border_radius="10px")

    card("Default Card")
    card("Custom Card", box_shadow="0 4px 8px rgba(0,0,0,0.2)", border_left="5px solid #673AB7")


def demo_progress_bars():
    """Demo using the progress bar feature."""

    print("\n--- Progress Bar Examples ---")

    # Determined progress bar example (manual style)
    print("\n--- Determined Progress Bar (Manual) ---")
    progress_id = progress(total=100, desc="Loading Data", color="#4a6fa5", height="25px")
    for i in range(101):
        P.update_progress(progress_id=progress_id, value=i)
        time.sleep(0.01)  # Simulate work being done

    # TQDM-like functionality (Automatic progress with iterables)
    print("\n--- TQDM-like Progress (Automatic) ---")

    # Example 1: With a list - automatically calculates total
    items = list(range(50))
    for item in progress(items, desc="Processing List"):
        time.sleep(0.02)  # Simulate work being done

    # Example 2: With a custom total
    items = range(100)
    for item in progress(items, total=100, desc="Processing Range", color="#2ecc71"):
        if item % 3 == 0:  # Only process every third item
            time.sleep(0.02)

    # Example 3: With a generator that doesn't have len() - undetermined progress
    def my_generator():
        for i in range(30):
            yield i

    for item in progress(my_generator(), desc="Processing Generator", color="#e74c3c"):
        time.sleep(0.05)

    # Traditional undetermined progress example
    print("\n--- Undetermined Progress Bar ---")
    progress_id2 = progress(desc="Processing Data", style="progress", color="#8E44AD", height="20px", animated=True)

    # Simulate some processing work
    time.sleep(2)

    # Important: Replace the undetermined progress with a completed one
    # This prevents the animation from running forever
    P.update_progress(progress_id2, 100, 100)

    # Alternative ways to show completion
    print("\n--- Completing Progress Examples ---")

    # Style 1: Show partial completion
    progress_id3 = progress(total=100, desc="Downloading Files", color="#16a085", height="20px")
    for i in range(0, 65, 5):
        P.update_progress(progress_id3, i)
        time.sleep(0.05)
    success("Download partially completed (65%)")

    # Style 2: Show error state
    progress_id4 = progress(total=100, desc="Installing Packages", color="#c0392b", height="20px")
    for i in range(0, 85, 5):
        P.update_progress(progress_id4, i)
        time.sleep(0.05)
    error("Installation failed at 85%")


def demo_enhanced_lists():
    """Demo showcasing the enhanced list display features."""

    title("Enhanced List Display Features")
    subtitle("Showcasing new styling and formatting capabilities")

    # Create a Printer instance for custom configurations
    printer = Printer()

    # --- Simple color-coded nested lists ---
    header("Color-coded Nested Lists")

    nested_list = [
        "Top Level",
        ["Level 1 - Item 1", "Level 1 - Item 2"],
        "Another Top Level",
        ["Level 1 - Item 3",
         ["Level 2 - Nested A", "Level 2 - Nested B",
          ["Level 3 - Deep Nested", "Level 3 - Another Deep"]
          ]
         ],
        "Final Top Level"
    ]

    info("Default color-coded nesting scheme:")
    list_(nested_list)

    # --- Custom nesting colors ---
    subheader("Custom Nesting Colors")

    # Use warm color scheme (reds to yellows)
    warm_colors = [
        "#E53935",  # Red
        "#F57C00",  # Orange
        "#FDD835",  # Yellow
        "#7CB342",  # Light Green
        "#039BE5",  # Light Blue
    ]

    info("Warm color scheme for nesting:")
    list_(nested_list, nesting_colors=warm_colors)

    # --- Matrix display ---
    header("Matrix Display")

    # Simple matrix (2D array)
    matrix_data = [
        [1, 2, 3, 4],
        [5, 6, 7, 8],
        [9, 10, 11, 12]
    ]

    info("Simple 2D matrix (automatically detected):")
    list_(matrix_data)

    # Create a NumPy matrix
    np_matrix = np.array([
        [1.2, 3.4, 5.6],
        [7.8, 9.0, 1.2],
        [3.4, 5.6, 7.8],
        [9.0, 1.2, 3.4]
    ])

    info("NumPy matrix with auto-detection:")
    list_(np_matrix)

    # Force list display for 2D data
    info("Forcing list display for matrix data:")
    list_(matrix_data, matrix_mode=False)

    # --- Array-like objects ---
    header("Array-like Objects Support")

    # NumPy array (1D)
    np_array = np.array([10, 20, 30, 40, 50])
    info("NumPy 1D array:")
    list_(np_array)

    # Pandas Series
    pd_series = pd.Series([1, 2, 3, 4, 5], index=['a', 'b', 'c', 'd', 'e'])
    info("Pandas Series:")
    list_(pd_series)

    # Creating a pandas DataFrame
    df = pd.DataFrame({
        'A': [1, 2, 3],
        'B': [4, 5, 6]
    })
    info("Pandas DataFrame (displayed as matrix):")
    list_(df)

    # --- Complex nested structures ---
    header("Complex Nested Structures")

    # Combined nested structure with different types
    complex_structure = [
        "Mixed Types Example",
        {"dict_in_list": "value", "nested_dict": {"a": 1, "b": 2}},
        ["List in list", ["Deeper", np.array([1, 2, 3])]],
        pd.Series([10, 20, 30], index=['x', 'y', 'z']),
        [
            [1, 2, 3],
            [4, 5, 6]
        ]
    ]

    info("Complex nested structure with different data types:")
    list_(complex_structure)

    # --- Generator and iterator examples ---
    header("Generators and Iterators")

    # Generator example
    def sample_generator(n):
        for i in range(n):
            yield f"Generated item {i}"

    info("Generator output:")
    list_(sample_generator(5))

    # Iterator example (map object)
    map_iterator = map(lambda x: x * 10, range(5))
    info("Map iterator output:")
    list_(map_iterator)


def demo_mermaid_diagrams():
    """Demo showcasing the Mermaid diagram rendering feature."""

    title("Mermaid Diagram Examples")
    subtitle("Rendering diagrams with the new mermaid feature")

    # --- Flowchart Example ---
    header("Flowchart Diagram")

    flow_diagram = """
    graph TD
        A[Start] --> B{Is it working?}
        B -->|Yes| C[Great!]
        B -->|No| D[Debug]
        D --> B
        C --> E[Continue]
        E --> F[End]
    """

    info("Basic flowchart diagram with default theme:")
    mermaid(flow_diagram)

    # --- Sequence Diagram Example ---
    header("Sequence Diagram")

    sequence_diagram = """
    sequenceDiagram
        participant User
        participant Client
        participant Server
        participant Database
        
        User->>Client: Submit Form
        Client->>Server: POST /api/data
        Server->>Database: Insert Data
        Database-->>Server: Confirm Insert
        Server-->>Client: 201 Created
        Client-->>User: Show Success
    """

    info("Sequence diagram with forest theme:")
    mermaid(sequence_diagram, theme="forest")

    # --- Class Diagram Example ---
    header("Class Diagram")

    class_diagram = """
    classDiagram
        class Animal {
            +String name
            +int age
            +makeSound()
        }
        class Dog {
            +fetch()
        }
        class Cat {
            +scratch()
        }
        Animal <|-- Dog
        Animal <|-- Cat
    """

    info("Class diagram with dark theme and custom container style:")
    mermaid(class_diagram, theme="dark", background_color="#282c34", padding="20px", border_radius="8px")

    # --- Gantt Chart Example ---
    header("Gantt Chart")

    gantt_chart = """
    gantt
        title Project Timeline
        dateFormat  YYYY-MM-DD
        section Planning
        Requirements     :done,    des1, 2023-01-01, 2023-01-05
        Design           :active,  des2, 2023-01-06, 2023-01-10
        section Development
        Implementation   :         des3, after des2, 2023-01-20
        Testing          :         des4, after des3, 7d
        Deployment       :         des5, after des4, 3d
    """

    info("Gantt chart with neutral theme:")
    mermaid(gantt_chart, theme="neutral")

    # --- State Diagram Example ---
    header("State Diagram")

    state_diagram = """
    stateDiagram-v2
        [*] --> Still
        Still --> [*]
        Still --> Moving
        Moving --> Still
        Moving --> Crash
        Crash --> [*]
    """

    info("State diagram with custom styling:")
    mermaid(state_diagram, border_left="4px solid #3498db")

    # --- Entity Relationship Diagram ---
    header("Entity Relationship Diagram")

    er_diagram = """
    erDiagram
        CUSTOMER ||--o{ ORDER : places
        ORDER ||--|{ LINE-ITEM : contains
        CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
    """

    info("Entity relationship diagram:")
    mermaid(er_diagram)

    # --- Using Printer class directly ---
    header("Using Printer Class")

    pie_chart = """
    pie title Product Distribution
        "Electronics" : 35
        "Clothing" : 25
        "Food" : 20
        "Books" : 15
        "Other" : 5
    """

    info("Using the Printer class to display a pie chart:")
    printer = Printer()
    printer.display_mermaid(pie_chart, theme="default", style="card")


def display_mermaid_2():
    # Create a simple diagram file for demonstration
    import os
    os.makedirs('examples/diagrams', exist_ok=True)

    with open('examples/diagrams/flow.mmd', 'w') as f:
        f.write('''
    graph TD
        A[Start] --> B{Is it working?}
        B -->|Yes| C[Great!]
        B -->|No| D[Debug]
        D --> B
    ''')

    # Example 1: Basic diagram display
    print("Example 1: Basic diagram display")
    mermaid('''
    graph TD
        A --> B
        A --> C
        B --> D
        C --> D
    ''')

    # Example 2: Reading from a file
    print("\nExample 2: Reading diagram from a file")
    mermaid('examples/diagrams/flow.mmd', theme='forest')

    # Example 3: Using custom CSS
    print("\nExample 3: Applying custom CSS")
    custom_styles = {
        '.node rect': 'fill: #f0f8ff; stroke: #4682b4; stroke-width: 2px;',
        '.node circle': 'fill: #f0f8ff; stroke: #4682b4; stroke-width: 2px;',
        '.node polygon': 'fill: #f0f8ff; stroke: #4682b4; stroke-width: 2px;',
        '.node.default > rect': 'fill: #e6f7ff;',
        '.edgeLabel': 'background-color: #ffffff; padding: 4px; border-radius: 4px;',
        '.edgePath .path': 'stroke: #4682b4; stroke-width: 2px;'
    }

    mermaid('''
    graph TD
        A[Start] --> B{Decision}
        B -->|Option 1| C[Result 1]
        B -->|Option 2| D[Result 2]
        C --> E[End]
        D --> E
    ''', theme='default', custom_css=custom_styles)

    # Example 4: Using printer instance with custom CSS
    print("\nExample 4: Using Printer instance with custom CSS")
    printer = Printer()

    # Custom styles focused on dark theme
    dark_styles = {
        '.node rect': 'fill: #2d2d2d; stroke: #6a9ec0; stroke-width: 2px;',
        '.node circle': 'fill: #2d2d2d; stroke: #6a9ec0; stroke-width: 2px;',
        '.node polygon': 'fill: #2d2d2d; stroke: #6a9ec0; stroke-width: 2px;',
        '.edgeLabel': 'color: #ffffff; background-color: #2d2d2d; padding: 4px;',
        '.edgePath .path': 'stroke: #6a9ec0; stroke-width: 2px;',
        '.label': 'color: #ffffff;',
        '.nodeLabel': 'color: #ffffff;'
    }

    printer.display_mermaid('''
    sequenceDiagram
        participant User
        participant System
        User->>System: Action
        System-->>User: Response
        User->>System: Another Action
        System-->>User: Another Response
    ''', theme='dark', custom_css=dark_styles)

    print("\nAll examples completed.")


def demo_enhanced_code_display():
    """Demo showcasing the enhanced code display features."""

    title("Enhanced Code Display Features")
    subtitle("Showcasing Python prompt detection and syntax highlighting")

    # --- Basic code display ---
    header("Basic Code Display")

    simple_code = """def greet(name):
    \"\"\"Simple greeting function\"\"\"
    return f"Hello, {name}!"

print(greet("World"))"""

    info("Basic code display with block-level highlighting:")
    code(simple_code, highlighting_mode="block")

    info("Basic code display with gradient highlighting:")
    code(simple_code, highlighting_mode="gradient")

    # --- Python REPL prompt recognition ---
    header("Python REPL Prompt Recognition")

    repl_code = """>>> x = 5
>>> y = 10
>>> x + y
15
>>> for i in range(3):
...     print(i)
...     i += 1
0
1
2
>>> def factorial(n):
...     if n <= 1:
...         return 1
...     else:
...         return n * factorial(n-1)
... 
>>> factorial(5)
120"""

    info("Code with Python REPL prompts (block highlighting):")
    code(repl_code, highlighting_mode="block")

    info("Code with Python REPL prompts (gradient highlighting):")
    code(repl_code, highlighting_mode="gradient",
         background_color="#f8f9fa")

    # --- Shell prompt recognition ---
    header("Shell Prompt Recognition")

    shell_code = """> ls -la
> cd /home/user
> mkdir new_folder
> python script.py
Processing...
Done!
> echo "Hello World"
Hello World"""

    info("Code with shell prompts:")
    code(shell_code, highlighting_mode="block")

    # --- Mixed prompts and customization ---
    header("Mixed Prompts and Customization")

    mixed_code = """# Python example
>>> import random
>>> random.randint(1, 100)
42

# Shell commands
> pip install pandas
Successfully installed pandas
> python
>>> import pandas as pd
>>> df = pd.DataFrame({"A": [1, 2, 3]})
>>> df
   A
0  1
1  2
2  3"""

    info("Mixed Python and shell prompts with custom styling:")
    code(mixed_code,
         highlighting_mode="block",
         background_color="#2d2d2d",
         color="#f8f8f2",
         font_family="'Fira Code', monospace",
         border_radius="8px",
         line_height="1.5")

    # --- Complex code example ---
    header("Complex Code Example")

    complex_code = """# A more complex example with nested indentation
def process_data(data):
    \"\"\"Process a data structure with nested elements.\"\"\"
    if not data:
        return None
    
    results = []
    for item in data:
        if isinstance(item, dict):
            # Process dictionaries
            processed = {}
            for key, value in item.items():
                if isinstance(value, list):
                    processed[key] = [x * 2 for x in value]
                else:
                    processed[key] = str(value).upper()
            results.append(processed)
        elif isinstance(item, list):
            # Process lists
            results.append([
                x + 1 if isinstance(x, int) else x
                for x in item
            ])
        else:
            # Process primitives
            results.append(item)
    
    return results
"""

    info("Complex code with block-level highlighting to show indentation:")
    code(complex_code, highlighting_mode="block")

    # --- Error handling example ---
    header("Error Cases (Try in a notebook)")

    info("Examples of error handling (these would raise exceptions in a notebook):")

    code("""# These would normally raise errors:
# code(123)  # Not a string
# code("print('hello')", highlighting_mode="invalid")  # Invalid mode
# code("print('hello')", background_color="invalid")  # Invalid color""")


def demo_animation():
    """Demo animation effects."""

    print("\n=== DEMO: Animation Effects ===")
    
    # --- Basic Animations ---
    title("Animation Effects Demo", animate="fadeIn")
    subtitle("Showcasing Animate.css integration", animate="slideInRight")
    
    section_divider("Attention Seekers", animate="pulse")
    
    time.sleep(0.5)
    info("Pulse Effect", animate="pulse")
    time.sleep(0.5)
    warning("Shake Effect", animate="shakeX")
    time.sleep(0.5)
    error("Bounce Effect", animate="bounce")
    time.sleep(0.5)
    success("Flash Effect", animate="flash")
    
    section_divider("Entrances", animate="flipInX")
    
    time.sleep(0.5)
    card("Fade In", animate="fadeIn")
    time.sleep(0.5)
    card("Slide In Left", animate="slideInLeft")
    time.sleep(0.5)
    card("Slide In Right", animate="slideInRight")
    time.sleep(0.5)
    card("Bounce In", animate="bounceIn")
    
    section_divider("Exits", animate="flipInY")
    
    time.sleep(0.5)
    code("# This code block will fade out\nprint('Hello, world!')", animate="fadeOut", delay="3s")
    time.sleep(0.5)
    badge("Slide Out Up", animate="slideOutUp", delay="3s")
    time.sleep(0.5)
    highlight("Slide Out Down", animate="slideOutDown", delay="3s")
    time.sleep(0.5)
    quote("This quote will disappear to the right", animate="slideOutRight", delay="3s")
    
    section_divider("Complex Combinations", animate="fadeInUp")
    
    time.sleep(0.5)
    headers = ["Animation", "Duration", "Delay"]
    rows = [
        ["bounce", "1s", "0s"],
        ["flash", "2s", "1s"],
        ["pulse", "3s", "2s"]
    ]
    table(headers, rows, caption="Animation Properties", animate="zoomIn")
    
    time.sleep(0.5)
    sample_dict = {
        "name": "Animate.css",
        "version": "4.1.1",
        "animations": ["Attention seekers", "Entrances", "Exits", "Others"]
    }
    dict_(sample_dict, animate="rotateIn")
    
    # Animation with custom styling
    time.sleep(0.5)
    header("Custom Animation Styling", animate="fadeInLeft", animation_duration="2s", animation_delay="0.5s")


def demo_md():
    """Demo showcasing the Markdown display feature."""

    title("Markdown Display Examples")
    subtitle("Rendering Markdown content with read more/less functionality")

    # Creating example markdown files for demonstration
    import os
    os.makedirs('examples/markdown', exist_ok=True)

    # Basic markdown example
    basic_markdown = """# Markdown Example

This is a basic markdown example demonstrating the `MDDisplayer` class functionality.

## Features

- **Syntax highlighting** for code blocks
- *Formatted text* with Markdown
- Tables and lists
- Read more/less functionality

## Code Example

```python
def hello_world():
    print("Hello, World!")
    return True
```

## Table Example

| Name | Age | Occupation |
|------|-----|------------|
| John | 28  | Developer  |
| Jane | 32  | Designer   |
| Bob  | 45  | Manager    |

"""

    with open('examples/markdown/basic.md', 'w', encoding='utf-8') as f:
        f.write(basic_markdown)

    # Longer markdown example with more content
    longer_markdown = basic_markdown + """
## Additional Content

This section demonstrates the 'read more' functionality by adding more content.

### Lists

1. First item
2. Second item
   - Nested item 1
   - Nested item 2
3. Third item

### Blockquotes

> This is a blockquote.
> It can span multiple lines.

### Horizontal Rule

---

### Links and Images

[Link to Google](https://www.google.com)

![Image placeholder](https://via.placeholder.com/150)

## Final Section

This is the end of our markdown example document.
"""

    with open('examples/markdown/longer.md', 'w', encoding='utf-8') as f:
        f.write(longer_markdown)

    # --- Basic Examples ---
    header("Basic Markdown Example")
    info("Display markdown from a file:")
    
    # Using the Printer class directly
    printer = Printer()
    printer.display_md('examples/markdown/basic.md')

    # --- Styled Examples ---
    header("Styled Markdown Example")
    info("Displaying markdown with custom styling:")
    md('examples/markdown/longer.md', style="card", border_left="5px solid #4CAF50")

    # --- Animated Example ---
    header("Animated Markdown")
    info("Markdown content with animation effects:")
    md('examples/markdown/basic.md', animate="fadeIn")

    # --- Inline Styles Example ---
    header("Custom Styled Markdown")
    info("Applying custom inline styles:")
    md('examples/markdown/longer.md', background_color="#f8f8f8", padding="20px", border_radius="10px")

    # --- URL Example ---
    # We'll use a public markdown file URL for this example
    header("Loading Markdown from URL")
    info("Loading markdown content from a URL:")
    md('https://raw.githubusercontent.com/adam-p/markdown-here/master/README.md', is_url=True)


def main():
    """Main function to run the examples."""

    print("===== COLAB PRINT LIBRARY DEMO =====")

    # Uncomment to run the original Printer class demo
    # demo_printer_class()

    # Demo the new global shortcut functions
    demo_global_shortcuts()

    # Demo the enhanced code display features
    demo_enhanced_code_display()

    # Demo the enhanced list display features
    demo_enhanced_lists()

    # Demo the animation features
    demo_animation()

    # Demo the progress bar feature
    demo_progress_bars()

    # Demo the mermaid diagram feature
    demo_mermaid_diagrams()
    display_mermaid_2()

    # Demo the markdown display feature
    demo_md()

    print("\n===== END OF DEMO =====")


if __name__ == "__main__":
    main()
