from typing import Iterable


def create_tooltip_formatter_code(groups: Iterable[str]) -> str:
    """Return tooltip formatter code.

    Parameters
    ----------
    groups : iterable of str
        Groups.

    Returns
    -------
    str
    """
    map_str = ', '.join(
        [f'[{index}, {group!r}]' for index, group in enumerate(groups)])
    return f"""
    function(params){{
        const convert = new Map([{map_str}]);
        if (isNaN(params.value)) {{
            return params.name;
        }}
        return params.name + ': ' + convert.get(params.value);
    }}
    """