from django.contrib.auth import views as auth_views
from django.urls import include, path
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static

from .forms import EmailOrUsernameAuthenticationForm, CustomPasswordChangeForm
from .custom_views import CustomLoginView

from . import views

urlpatterns = [
    path('reset/<uidb64>/<token>/', views.CustomPasswordResetConfirmView.as_view(), name='password_reset_confirm'),
    path("", views.index, name="index"),
    path("tournaments/", views.tournaments, name="tournaments"),
    path("clubs/", views.clubs, name="clubs"),
    path("clubs/<str:club_id>/", views.club, name="club"),
    path("c/<str:broadcast_code>", views.club_broadcast, name="club-broadcast"),
    path("c/<str:broadcast_code>/go", views.club_broadcast_auto, name="club-broadcast-auto"),
    path("tournament/<str:tournament_id>/",
        include([
            path('', views.tournament, name='tournament'),
            path('teams/', views.tournament_teams, name='tournament-teams'),
            path('info/', views.tournament_info, name='tournament-info'),
            path('bracket/', views.tournament_bracket, name='tournament-bracket'),
            path('round/<str:round_id>/bracket/', views.round_bracket, name='round-bracket'),
            path('prog/', views.tournament_prog, name='tournament-prog'),
            path('summons/', views.tournament_summons, name='tournament-summons'),
            path('broadcast/summons/', views.tournament_broadcasted_summons, name='broadcasted-summons'),
            path('summons/json/', views.tournament_summons_json, name='tournament-summons-json'),
            path('broadcast/matches/', views.tournament_matches, name='broadcasted-matches'),
            path('broadcast/', views.tournament_broadcast_home, name='broadcast'),
            path('broadcast/auto/', views.automatic_broadcast, name='automatic-broadcast'),
            path('matches/json/', views.tournament_matches_json, name='tournament-matches-json'),
            path('prog/json/', views.tournament_prog_json, name='tournament-prog-json'),
            path('broadcast/json/', views.broadcast_json, name='broadcast-json'),
            path('broadcast/group-stages/', views.tournament_broadcasted_group_stages, name='broadcasted-group-stages'),
            path('broadcast/prog/', views.tournament_broadcasted_prog, name='broadcasted-prog'),
            path('broadcast/bracket/', views.tournament_broadcasted_bracket, name='broadcasted-bracket'),
            path('bracket/json/', views.tournament_bracket_json, name='tournament-bracket-json'),
            path('group-stages/', views.tournament_group_stages, name='group-stages'),
            path('group-stages/json/', views.tournament_live_group_stage_json, name='group-stages-json'),
            path('rankings/', views.tournament_rankings, name='tournament-rankings'),
            path('rankings/json/', views.tournament_rankings_json, name='tournament-rankings-json'),
            path('broadcast/rankings/', views.tournament_broadcast_rankings, name='broadcasted-rankings'),
            path('team/<str:team_id>/', views.team_details, name='team-details'),
        ])
    ),
    path("event/<str:event_id>/broadcast/auto/", views.automatic_broadcast_event, name='automatic-broadcast-event'),
    path('players/', views.players, name='players'),
    path('activate/<uidb64>/<token>/', views.activate, name='activate'),
    path('download/', views.download, name='download'),
    path('apns/', views.test_apns, name='test-apns'),
    path('terms-of-use/', views.terms_of_use, name='terms-of-use'),
    path('utils/xls-to-csv/', views.xls_to_csv, name='xls-to-csv'),
    path('mail-test/', views.simple_form_view, name='mail-test'),
    path('login/', CustomLoginView.as_view(), name='custom-login'),
    path('password_change/',
        auth_views.PasswordChangeView.as_view(
            success_url='/profile/',  # Redirect back to profile after success
            form_class=CustomPasswordChangeForm
        ),
        name='password_change'
    ),
    path('logout/', views.custom_logout, name='custom_logout'),
    path('signup/', views.signup, name='signup'),  # URL pattern for signup
#    path('profile/', views.profile, name='profile'),  # URL pattern for signup
    path('my-tournaments/', views.my_tournaments, name='my-tournaments'),  # URL pattern for signup
    path('tournaments/<str:tournament_id>/register/', views.register_tournament, name='register_tournament'),
    path('tournaments/<str:tournament_id>/unregister/', views.unregister_tournament, name='unregister_tournament'),
    path('password_reset/', auth_views.PasswordResetView.as_view(), name='password_reset'),
    path('password_reset_done/', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
    path('reset/done/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
    path('profile/', views.ProfileUpdateView.as_view(), name='profile'),
    path('admin/tournament-import/', views.tournament_import_view, name='tournament_import'),
    path('admin/status/', views.status_page, name='status_page'),
    path('admin/users-export/', views.UserListExportView.as_view(), name='users_export'),
    path('activation-success/', views.activation_success, name='activation_success'),
    path('activation-failed/', views.activation_failed, name='activation_failed'),
]
