"""mysite URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from django.views.generic import TemplateView

from django_psutil_dash.urls import psutil_urlpatterns


from . import views


from rapids import views as rapid_views
from anatomy import views as anatomy_views
from longs import views as long_views

from generic import views as generic_views

from django.conf.urls import handler400, handler403, handler404, handler500

from .api import api
from autocomplete import urls as autocomplete_urls



urlpatterns = [
    path("admin/", admin.site.urls, name="admin"),
    path("api/", api.urls),
    path("anatomy/", include("anatomy.urls"), name="anatomy"),
    path("physics/", include("physics.urls"), name="physics"),
    # path("sbas/", include("sbas.urls"), name="sbas"),
    path("rapids/", include("rapids.urls"), name="rapids"),
    path("shorts/", include("shorts.urls"), name="shorts"),
    path("longs/", include("longs.urls"), name="longs"),
    path("sbas/", include("sbas.urls"), name="sbas"),
    path("generic/", include("generic.urls"), name="generic"),
    path("atlas/", include("atlas.urls"), name="atlas"),
    path("survey/", include("survey.urls")),
    path("research/", include("research.urls"), name="research"),
    path("rcr/", include("rcr.urls"), name="rcr"),
    path("rota/", include("rota.urls"), name="rota"),
    path("oef/", include("oef.urls"), name="oef"),
    path(
        "accounts/check_users", views.accounts_check_users, name="accounts_check_users"
    ),
    path(
        "accounts/bulk_create/", views.accounts_bulk_create, name="accounts_bulk_create"
    ),
    path(
        "accounts/bulk_create/check", views.accounts_bulk_create_check, name="accounts_bulk_create_check"
    ),
    path(
        "accounts/create/", generic_views.create_user, name="create_user"
    ),
    path(
        "accounts/trainees/create/", generic_views.create_trainee, name="create_trainee"
    ),
    path(
        "accounts/trainees/", generic_views.trainees, name="trainees"
    ),
    path(
        "accounts/trainees/<str:grade>/", generic_views.trainees, name="trainees_grade"
    ),
    path(
        "accounts/trainees/bulk_update/spreadsheet", generic_views.trainees_bulk_update_from_spreadsheet, name="trainees_bulk_update_from_spreadsheet"
    ),
    path(
        "accounts/update/<str:slug>/",
        views.UpdateUserView.as_view(),
        name="account_update",
    ),
    path(
        "accounts/delete/<int:pk>/",
        views.DeleteUserView.as_view(),
        name="account_delete",
    ),
    path(
        "accounts/update_profile/<str:slug>/",
        views.UpdateUserProfileView.as_view(),
        name="account_profile_update",
    ),
    path("server", views.server, name="server"),
    path("logs/", views.logs_view, name="logs_view"),
    path("management/media-cleanup/", views.media_cleanup, name="media_cleanup"),
    path("people", views.people, name="people"),
    path("accounts/", views.UserListTableView.as_view(), name="accounts_list"),
    #path("accounts/", views.UserListView.as_view(), name="accounts_list"),
    path("accounts/", include("django.contrib.auth.urls")),
    path("accounts/profile", views.profile, name="profile"),
    path("accounts/profile/<str:slug>/", views.account_profile, name="account_profile"),
    path(
        "accounts/profile/<str:slug>/set-supervisor/",
        views.account_set_supervisor,
        name="account_set_supervisor",
    ),
    path(
        "accounts/profile/<str:slug>/send-password-reset/",
        views.account_send_password_reset,
        name="account_send_password_reset",
    ),
    #path("", TemplateView.as_view(template_name="index.html"), name="home"),
    path("", views.index, name="home"),
    path("cid/results/<int:cid>/", views.cid_results, name="cid_results"),
    path("cid/<int:cid>/<str:passcode>", views.cid_user_overview, name="cid_scores"),
    path("cid/<int:cid>/", views.cid_scores_admin, name="cid_scores_admin"),
    path("user/scores", views.user_scores, name="user_scores"),
    path("user/scores/<int:user_id>", views.user_scores_admin, name="user_scores_admin"),
    path("user/marking", views.user_marking, name="user_marking"),
    path("user/marking/<str:exam_type>", views.user_marking_partial, name="user_marking_partial"),
    path("cid/", views.cid_selector, name="cid_selector"),
    path("cid/request_cid_details/", views.request_cid_details, name="request_cid_details"),
    # Global url that registers RTS compatible exams
    path("exam/json/", views.active_exams, name="active_exams"),
    path(
        "exam/json/<int:cid>/<str:passcode>",
        views.active_exams,
        name="active_exams_cid",
    ),
    path(
        "exam/json/unbased/<int:cid>/<str:passcode>",
        views.active_exams_unbased,
        name="active_exams_cid_unbased",
    ),
    path("exam/json/unbased", views.active_exams_unbased, name="active_exams_unbased"),
    path("exam/json/<str:exam_type>/", views.active_exams_by_type, name="active_exams_by_type"),
    path(
        "exam/json/<str:exam_type>/<int:cid>/<str:passcode>",
        views.active_exams_by_type,
        name="active_exams_by_type_cid",
    ),
    path(
        "exam/json/<str:exam_type>/unbased/<int:cid>/<str:passcode>",
        views.active_exams_by_type_unbased,
        name="active_exams_by_type_cid_unbased",
    ),
    path("exam/json/<str:exam_type>/unbased", views.active_exams_by_type_unbased, name="active_exams_by_type_unbased"),
    path("exam/submit", views.exam_submit, name="global_exam_answers_submit"),
    # path('', include('generic.urls')),
    path(
        "feedback/<str:question_type>/<int:pk>",
        views.AddQuestionNote.as_view(),
        name="feedback_create",
    ),
    path(
        "feedback/note/<int:pk>/complete",
        views.feedback_mark_complete,
        name="feedback_mark_complete",
    ),
    path(
        "feedback/note/<int:pk>/delete",
        views.feedback_note_delete,
        name="feedback_note_delete",
    ),
    # path("feedback/", views.AddQuestionNote.as_view(), name="feedback"),
    path(
        "feedback/answer",
        views.answer_suggestion_submit,
        name="answer_suggestion_submit",
    ),
    path("feedback/answer_submit", views.answer_submit, name="answer_submit"),
    path(
        "feedback/answer/confirm",
        views.answer_suggestion_confirm,
        name="answer_suggestion_confirm",
    ),
    path("feedback/view", views.view_feedback, name="view_feedback"),
    #path("api-auth/", include("rest_framework.urls")),
    path("tinymce/", include("tinymce.urls")),
    path("cookies/", include("cookie_consent.urls")),
    #path("cookies/", include("cookie_consent.urls")),
    path("privacy/", views.privacy_view, name="privacy"),
    path("about/", views.about_view, name="about"),
    path("stats/", views.stats, name="stats"),
    # path('select2/', include('select2.urls')),

    path("ac/", autocomplete_urls),
    path('psutil/', psutil_urlpatterns(), name='psutil'),
    path("cimar/", views.cimar, name="cimar"),
    path(
        "cimar/study/<str:uuid>/dicom_json",
        views.cimar_study_dicom_json,
        name="cimar_study_dicom_json",
    ),
    path(
        "cimar/study/<str:uuid>/viewer",
        views.cimar_study_viewer,
        name="cimar_study_viewer",
    ),
    path(
        "cimar/study/<str:uuid>/viewer/embed",
        views.cimar_study_viewer_embed,
        name="cimar_study_viewer_embed",
    ),
    path(
        "cimar/study/<str:uuid>/series_block",
        views.cimar_study_series_block,
        name="cimar_study_series_block",
    ),

    path("cimar/login/", views.cimar_login, name="cimar_login"),
    path("cimar/logout/", views.cimar_logout, name="cimar_logout"),
    path("cimar/login/status", views.cimar_status, name="cimar_status"),

]

# handler400 = 'my_app.views.bad_request'
handler403 = "rad.views.page_forbidden"
handler404 = "rad.views.page_not_found"
handler500 = "rad.views.server_error"
# handler500 = 'my_app.views.server_error'

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

if settings.DEBUG:
    #urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static("/rts/", document_root="rts")
    urlpatterns += static("/viewer/", document_root="viewer")
    import debug_toolbar

    urlpatterns = [
        path("__debug__/", include(debug_toolbar.urls)),
        # For django versions before 2.0:
        # url(r'^__debug__/', include(debug_toolbar.urls)),
    ] + urlpatterns
