""" the main URL config that imports many URL configs from the applications. """
from django.conf import settings
from django.urls import include, path
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.sitemaps.views import sitemap
from django.views.generic.base import TemplateView

from content import views, feeds
from content.sitemaps import ArticleSitemap, PageSitemap
from events.sitemaps import EventSitemap
from events.views import EventListIcal
from mahjong_ranking.sitemaps import *
from maistar_ranking.sitemaps import *
from membership.views import MembershipDetail

admin.autodiscover()
# register_converter('path')

sitemaps = {
    'event_rankings': EventRankingSitemap,
    'event_hanchans': EventHanchanSitemap,
    'mahjong_seasons': MajongSeasonSitemap,
    'maistar_games': MaistarGamesSitemap,
    'articles': ArticleSitemap,
    'events': EventSitemap,
    'pages': PageSitemap,
}

urlpatterns = [  # Ignore PyLintBear (C0103)
    path("", views.StartPage.as_view(), name="index"),
    path('index.html', views.StartPage.as_view()),
    path('404/', TemplateView.as_view(template_name='404.html'), name="404"),
    path('admin/doc/', include('django.contrib.admindocs.urls'), name="django-docs"),
    path('admin/', admin.site.urls, name="django-admin"),
    path('ckeditor/', include('ckeditor_uploader.urls')),
    path('comments/', include('django_comments.urls')),
    path('events/', include('events.urls')),
    path('events.ics', EventListIcal.as_view(), name='events-ical'),
    path('feeds/latest/', feeds.LatestNews(), name='feed-latest-news'),
    path('feeds/comments/', feeds.LatestComments(), name='feed-latest-comments'),
    path('gallery/', include('events.gallery_urls')),
    path('google25dabc1a49a9ef03.html', TemplateView.as_view(template_name='google25dabc1a49a9ef03.html')),
    path('i18n/', include('django.conf.urls.i18n'), name='start-page'),
    path('manifest.json', TemplateView.as_view(template_name='manifest.json')),
    path('membership/', include('membership.urls')),
    path('news/', include('content.news_urls')),
    path('ranking/', include('mahjong_ranking.urls')),
    path('ranking/', include('maistar_ranking.urls')),
    path('sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'),
    path('robots.txt', TemplateView.as_view(template_name='robots.txt')),
    path('users/', MembershipDetail.as_view(), name='membership-details'),
    path('users/<slug:username>/', MembershipDetail.as_view(), name='membership-details'),
    path('add_page/<path:path>', views.PageAddForm.as_view(), name='add-page'),
    path('edit_page/<path:path>', views.PageEditForm.as_view(), name='edit-page'),
    path('<path:path>.html', views.PageHtml.as_view(), name='view-page'),
    path('<path:path>.pdf', views.PagePdf.as_view()),
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL,
                          document_root=settings.MEDIA_ROOT)
    urlpatterns += static(settings.STATIC_URL,
                          document_root=settings.STATIC_ROOT)
    if 'rosetta' in settings.INSTALLED_APPS:
        urlpatterns += [path("rosetta/", include('rosetta.urls'))]
    if 'debug_toolbar' in settings.INSTALLED_APPS:
        import debug_toolbar

        urlpatterns += [path('__debug__/', include(debug_toolbar.urls)), ]
