import streamlit as st

out = st.components.v2.component(
    "st-tui-editor.st_tui_editor",
    js="index-*.js",
    css="index-*.css",
    html='<div class="react-root"></div>',
)

def on_markdown_change():
    pass

def st_tui_editor(
    initial_value="",
    height="500px",
    initial_edit_type="markdown",
    preview_style="vertical",
    theme="light",
    usage_statistics=True,
    key=None,
):
    """Create a new instance of "st_tui_editor".

    Parameters
    ----------
    initial_value: str
        The initial markdown content to display in the editor.
    height: str
        The height of the editor (e.g., "500px", "auto").
    initial_edit_type: str
        The initial edit type ("markdown" or "wysiwyg").
    preview_style: str
        The preview style ("tab" or "vertical").
    theme: str
        The theme ("light" or "dark").
    usage_statistics: bool
        Whether to enable usage statistics for TUI Editor.
    key: str or None
        An optional key that uniquely identifies this component.

    Returns
    -------
    dict
        A dictionary containing the edited markdown, e.g., {"markdown": "..."}.
    """
    component_value = out(
        initialValue=initial_value,
        height=height,
        initialEditType=initial_edit_type,
        previewStyle=preview_style,
        theme=theme,
        usageStatistics=usage_statistics,
        key=key,
        default={"markdown": initial_value},
        on_markdown_change=on_markdown_change,
        data={
            "initialValue": initial_value,
            "height": height,
            "initialEditType": initial_edit_type,
            "previewStyle": preview_style,
            "theme": theme,
            "usageStatistics": usage_statistics,
        },
    )

    return component_value
