from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from beesgospel.models import Agenda, Document, Membre, User


@admin.register(Agenda)
class AgendaAdmin(admin.ModelAdmin):
    list_display = ["titre", "lieu", "date_heure", "prive"]
    ordering = ["-date_heure"]
    search_fields = ["titre", "lieu"]
    date_hierarchy = "date_heure"


@admin.register(Document)
class DocumentAdmin(admin.ModelAdmin):
    list_display = ["titre", "quand", "prive"]
    ordering = ["-quand"]


@admin.register(Membre)
class MembreAdmin(admin.ModelAdmin):
    list_display = ["nom", "prenom", "localite", "user__email"]
    ordering = ["nom"]


@admin.register(User)
class UserAdmin(UserAdmin):
    list_display = ["email", "is_active", "is_staff", "last_login"]
    search_fields = ["email"]
    ordering = ["email"]
    fieldsets = (
        (None, {"fields": ("email", "password",)}),
        (
            "Permissions",
            {
                "fields": (
                    "is_active",
                    "is_staff",
                    "is_superuser",
                    "groups",
                    "user_permissions",
                ),
            },
        ),
        ("Important dates", {"fields": ("last_login", "date_joined")}),
    )
    add_fieldsets = (
        (
            None,
            {
                "classes": ("wide",),
                "fields": ("email", "usable_password", "password1", "password2"),
            },
        ),
    )
