"""Default block and style maps for the exporter.

The mappings connect Draft.js block types and inline styles to HTML
tags or component functions.
"""

from draftjs_exporter.constants import BLOCK_TYPES, INLINE_STYLES
from draftjs_exporter.dom import DOM
from draftjs_exporter.types import ConfigMap, Element, Props


def render_children(props: Props) -> Element:
    """Return the children of a component without wrapping markup."""
    return props["children"]


def code_block(props: Props) -> Element:
    """Render a code block inside a ``pre`` > ``code`` element tree."""
    return DOM.create_element(
        "pre", {}, DOM.create_element("code", {}, props["children"])
    )


# Default block map to extend.
BLOCK_MAP: ConfigMap = {
    BLOCK_TYPES.UNSTYLED: "p",
    BLOCK_TYPES.HEADER_ONE: "h1",
    BLOCK_TYPES.HEADER_TWO: "h2",
    BLOCK_TYPES.HEADER_THREE: "h3",
    BLOCK_TYPES.HEADER_FOUR: "h4",
    BLOCK_TYPES.HEADER_FIVE: "h5",
    BLOCK_TYPES.HEADER_SIX: "h6",
    BLOCK_TYPES.UNORDERED_LIST_ITEM: {"element": "li", "wrapper": "ul"},
    BLOCK_TYPES.ORDERED_LIST_ITEM: {"element": "li", "wrapper": "ol"},
    BLOCK_TYPES.BLOCKQUOTE: "blockquote",
    BLOCK_TYPES.PRE: "pre",
    BLOCK_TYPES.CODE: code_block,
    BLOCK_TYPES.ATOMIC: render_children,
}
"""Default mapping from block types to renderable tags or components."""


# Default style map to extend.
# Tags come from https://developer.mozilla.org/en-US/docs/Web/HTML/Element.
# and are loosely aligned with https://github.com/jpuri/draftjs-to-html.
# Only styles that map to HTML elements are allowed as defaults.
STYLE_MAP: ConfigMap = {
    INLINE_STYLES.BOLD: "strong",
    INLINE_STYLES.CODE: "code",
    INLINE_STYLES.ITALIC: "em",
    INLINE_STYLES.UNDERLINE: "u",
    INLINE_STYLES.STRIKETHROUGH: "s",
    INLINE_STYLES.SUPERSCRIPT: "sup",
    INLINE_STYLES.SUBSCRIPT: "sub",
    INLINE_STYLES.MARK: "mark",
    INLINE_STYLES.QUOTATION: "q",
    INLINE_STYLES.SMALL: "small",
    INLINE_STYLES.SAMPLE: "samp",
    INLINE_STYLES.INSERT: "ins",
    INLINE_STYLES.DELETE: "del",
    INLINE_STYLES.KEYBOARD: "kbd",
}
"""Default mapping from inline styles to HTML tags."""
