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

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


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


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


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


@admin.register(Chant)
class ChantAdmin(admin.ModelAdmin):
    list_display = ["titre", "particularite", "statut"]
    list_filter = ["statut"]
    search_fields = ["titre"]
    ordering = ["titre"]


@admin.register(ChantDoc)
class ChantDocAdmin(admin.ModelAdmin):
    list_display = ["titre", "chant", "fichier", "lien"]


@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"),
            },
        ),
    )
