"""Blog editor panel rendering."""
from __future__ import annotations


def render_editor_panel(save_error: str | None = None, is_page: bool = False) -> str:
    """Build the WYSIWYG editor panel for new post/page creation."""
    from shared.browser.app.csrf import generate_csrf_token
    from shared.sx.helpers import sx_call
    from .helpers import _editor_urls, _editor_init_js

    urls = _editor_urls()
    csrf = generate_csrf_token()
    title_placeholder = "Page title..." if is_page else "Post title..."
    create_label = "Create Page" if is_page else "Create Post"
    init_js = _editor_init_js(urls, form_id="post-new-form", has_initial_json=False)

    return sx_call("blog-editor-content",
        csrf=csrf,
        title_placeholder=title_placeholder,
        create_label=create_label,
        css_href=urls["css_href"],
        js_src=urls["js_src"],
        sx_editor_js_src=urls["sx_editor_js_src"],
        init_js=init_js,
        save_error=save_error or None)
