# Path: mapwidgets/constants.py
# STATIC_MAP_PLACEHOLDER_IMAGE = "mapwidgets/images/no-map-image.png"
# 
# Path: mapwidgets/settings.py
# DEFAULTS = {
#     "GooglePointFieldWidget": (
#         ("mapCenterLocationName", None),
#         ("mapCenterLocation", TIMEZONE_COORDINATES.get(getattr(django_settings, "TIME_ZONE", "UTC"))),
#         ("zoom", 6),
#         ("GooglePlaceAutocompleteOptions", {}),
#         ("markerFitZoom", 15),
#         ("streetViewControl", True),
#     ),
# 
#     "MapboxPointFieldWidget": (
#         ("mapCenterLocationName", None),
#         ("mapCenterLocation", TIMEZONE_COORDINATES.get(getattr(django_settings, "TIME_ZONE", "UTC"))),
#         ("zoom", 6),
#         ("markerFitZoom", 15),
#         ("access_token", ""),
#     ),
# 
#     "GoogleStaticMapWidget": (
#         ("zoom", 15),
#         ("size", "480x480"),
#         ("scale", ""),
#         ("format", ""),
#         ("maptype", ""),
#         ("path", ""),
#         ("visible", ""),
#         ("style", ""),
#         ("language", ""),
#         ("region", "")
#     ),
# 
#     "GoogleStaticMapMarkerSettings": (
#         ("size", "normal"),
#         ("color", ""),
#         ("icon", ""),
#     ),
# 
#     "GoogleStaticOverlayMapWidget": (
#         ("zoom", 15),
#         ("size", "480x480"),
#         ("thumbnail_size", "160x160"),
#         ("scale", ""),
#         ("format", ""),
#         ("maptype", ""),
#         ("path", ""),
#         ("visible", ""),
#         ("style", ""),
#         ("language", ""),
#         ("region", "")
#     ),
#     "LANGUAGE": "en",
#     "LIBRARIES": "places",
#     "MINIFED": not django_settings.DEBUG,
#     "GOOGLE_MAP_API_SIGNATURE": "",
#     "GOOGLE_MAP_API_KEY": "",
#     "MAPBOX_API_KEY": "",
# }
# class MapWidgetSettings(object):
#     def __init__(self, app_settings=None, defaults=None):
#     def app_settings(self):
#     def __getattr__(self, attr):
# def reload_widget_settings(*args, **kwargs):


import json
from django import forms
from django.contrib.gis.forms import BaseGeometryWidget
from django.contrib.gis.geos import Point
from django.core.exceptions import ImproperlyConfigured
from django.template.loader import render_to_string
from django.templatetags.static import static
from django.utils.http import urlencode
from mapwidgets.constants import STATIC_MAP_PLACEHOLDER_IMAGE
from mapwidgets.settings import MapWidgetSettings, mw_settings

class BasePointFieldMapWidget(BaseGeometryWidget):
    settings_namespace = None
    settings = None

    def __init__(self, *args, **kwargs):
        attrs = kwargs.get('attrs')
        self.attrs = {}
        for key in ('geom_type', 'map_srid', 'map_width', 'map_height', 'display_raw'):
            if key in kwargs:
                self.attrs[key] = kwargs.get(key)
            else:
                self.attrs[key] = getattr(self, key)

        if isinstance(attrs, dict):
            self.attrs.update(attrs)

        self.custom_settings = False
        if kwargs.get('settings'):
            self.settings = kwargs.pop('settings')
            self.custom_settings = True

    def map_options(self):
        if not self.settings:  # pragma: no cover
            raise ImproperlyConfigured('%s requires either a definition of "settings"' % self.__class__.__name__)

        if not self.settings_namespace:  # pragma: no cover
            raise ImproperlyConfigured('%s requires either a definition of "settings_namespace"' % self.__class__.__name__)

        if self.custom_settings:

# Path: mapwidgets/constants.py
# STATIC_MAP_PLACEHOLDER_IMAGE = "mapwidgets/images/no-map-image.png"
# 
# Path: mapwidgets/settings.py
# DEFAULTS = {
#     "GooglePointFieldWidget": (
#         ("mapCenterLocationName", None),
#         ("mapCenterLocation", TIMEZONE_COORDINATES.get(getattr(django_settings, "TIME_ZONE", "UTC"))),
#         ("zoom", 6),
#         ("GooglePlaceAutocompleteOptions", {}),
#         ("markerFitZoom", 15),
#         ("streetViewControl", True),
#     ),
# 
#     "MapboxPointFieldWidget": (
#         ("mapCenterLocationName", None),
#         ("mapCenterLocation", TIMEZONE_COORDINATES.get(getattr(django_settings, "TIME_ZONE", "UTC"))),
#         ("zoom", 6),
#         ("markerFitZoom", 15),
#         ("access_token", ""),
#     ),
# 
#     "GoogleStaticMapWidget": (
#         ("zoom", 15),
#         ("size", "480x480"),
#         ("scale", ""),
#         ("format", ""),
#         ("maptype", ""),
#         ("path", ""),
#         ("visible", ""),
#         ("style", ""),
#         ("language", ""),
#         ("region", "")
#     ),
# 
#     "GoogleStaticMapMarkerSettings": (
#         ("size", "normal"),
#         ("color", ""),
#         ("icon", ""),
#     ),
# 
#     "GoogleStaticOverlayMapWidget": (
#         ("zoom", 15),
#         ("size", "480x480"),
#         ("thumbnail_size", "160x160"),
#         ("scale", ""),
#         ("format", ""),
#         ("maptype", ""),
#         ("path", ""),
#         ("visible", ""),
#         ("style", ""),
#         ("language", ""),
#         ("region", "")
#     ),
#     "LANGUAGE": "en",
#     "LIBRARIES": "places",
#     "MINIFED": not django_settings.DEBUG,
#     "GOOGLE_MAP_API_SIGNATURE": "",
#     "GOOGLE_MAP_API_KEY": "",
#     "MAPBOX_API_KEY": "",
# }
# class MapWidgetSettings(object):
#     def __init__(self, app_settings=None, defaults=None):
#     def app_settings(self):
#     def __getattr__(self, attr):
# def reload_widget_settings(*args, **kwargs):


# Path: mapwidgets/widgets.py
import json
from django import forms
from django.contrib.gis.forms import BaseGeometryWidget
from django.contrib.gis.geos import Point
from django.core.exceptions import ImproperlyConfigured
from django.template.loader import render_to_string
from django.templatetags.static import static
from django.utils.http import urlencode
from mapwidgets.constants import STATIC_MAP_PLACEHOLDER_IMAGE
from mapwidgets.settings import MapWidgetSettings, mw_settings


class BasePointFieldMapWidget(BaseGeometryWidget):
    settings_namespace = None
    settings = None

    def __init__(self, *args, **kwargs):
        attrs = kwargs.get('attrs')
        self.attrs = {}
        for key in ('geom_type', 'map_srid', 'map_width', 'map_height', 'display_raw'):
            if key in kwargs:
                self.attrs[key] = kwargs.get(key)
            else:
                self.attrs[key] = getattr(self, key)

        if isinstance(attrs, dict):
            self.attrs.update(attrs)

        self.custom_settings = False
        if kwargs.get('settings'):
            self.settings = kwargs.pop('settings')
            self.custom_settings = True

    def map_options(self):
        if not self.settings:  # pragma: no cover
            raise ImproperlyConfigured('%s requires either a definition of "settings"' % self.__class__.__name__)

        if not self.settings_namespace:  # pragma: no cover
            raise ImproperlyConfigured('%s requires either a definition of "settings_namespace"' % self.__class__.__name__)

        if self.custom_settings:

            custom_settings = MapWidgetSettings(app_settings=self.settings)