from .slideshow import slideshow


def convert_html(obj):
    value = obj["value"]
    if "text" in value and "html" not in value:
        value["html"] = value.pop("text")
    return obj


def convert_carousel(obj):
    return slideshow(
        obj,
        lambda slide: (
            '<p><a href="%(url)s">%(caption)s</a></p>' % slide if slide["url"] else ""
        ),
        "carousel",
    )


def convert_iconslider(obj):
    return slideshow(
        obj,
        lambda slide: (
            '<p><a href="%(url)s">%(name)s</a></p>' % slide
            if slide["url"]
            else "<p>%(name)s</p>" % slide
        ),
        "iconslider",
        items=6,
    )


def convert_product(obj):
    obj["type"] = "Product"
    return obj


def convert_googlemaps(obj):
    obj["value"].pop("coordinates", None)
    obj["type"] = "Maps"
    return obj


def convert_vat(obj):
    obj["type"] = "VAT_entry"
    return obj


def convert_embed(obj):
    obj["type"] = "video"
    return obj
