# Copyright (C) 2019-2022 HERE Global B.V. and its affiliate(s).
# All rights reserved.
#
# This software and other materials contain proprietary information
# controlled by HERE and are protected by applicable copyright legislation.
# Any use and utilization of this software and other materials and
# disclosure to any third parties is conditional upon having a separate
# agreement with HERE for the access, use, utilization or disclosure of this
# software. In the absence of such agreement, the use of the software is not
# allowed.

"""
Utility functions for HERE Map Widget for Jupyter inspector backend.
"""
from typing import Dict

from here.inspector.ipyleaflet.basemaps import here_basemaps
from here.inspector.ipyleaflet.utils import theme_colors
from here.inspector.styles import Color, Theme

theme_here_basemap = {
    Theme.LIGHT_MAP: here_basemaps.reducedDay,
    Theme.DARK_MAP: here_basemaps.reducedNight,
}


def to_style(theme: Theme, color: Color) -> Dict:
    """Create a here-map-widget-for-jupyter style dictionary from given theme and color."""
    orig_color = theme_colors[theme][color]
    conv_color = orig_color.strip("#")
    rgba = f"rgba{tuple(int(conv_color[i:i+2], 16) for i in (0, 2, 4)) + (0.2,)}"
    return {"fillColor": rgba, "strokeColor": orig_color}
