from django.conf import settings
from django.conf.urls import url, include
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import re_path
from django.views.generic import RedirectView
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtailautocomplete.urls.admin import urlpatterns as autocomplete_admin_urls

from core import views


urlpatterns = [
    # django admin
    url(r'^guru/', admin.site.urls),
    url(r'^statistics/', include('statistics.urls', namespace='statistics')),

    # wagtail
    url(r'^admin/autocomplete/', include(autocomplete_admin_urls)),
    url(r'^cms/', include(wagtailadmin_urls)),

    # graphql backend
    url(r'^api/', include('api.urls', namespace="api")),

    #favicon
    url(r'^favicon\.ico$', RedirectView.as_view(url='/static/favicon@2x.png', permanent=True)),

]

if settings.DEBUG and not settings.USE_AWS:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

    if settings.ENABLE_SILKY:
        urlpatterns += [url(r'^silk/', include('silk.urls', namespace='silk'))]

# actually we use the cms in headless mode but need the url pattern to get the wagtail_serve function
urlpatterns += [url(r'pages/', include(wagtail_urls)), ]

urlpatterns += [re_path(r'^.*$', views.home, name='home')]

admin.site.site_header = 'Myskillbox Admin'
